You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(2) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
|
Feb
|
Mar
(16) |
Apr
(83) |
May
(27) |
Jun
(14) |
Jul
(11) |
Aug
(22) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <mic...@us...> - 2007-04-11 13:39:18
|
Revision: 24 http://svn.sourceforge.net/pearcolator/?rev=24&view=rev Author: michael_baer Date: 2007-04-11 06:39:17 -0700 (Wed, 11 Apr 2007) Log Message: ----------- Centrally parsing command line options in DBT_Options. Stopped passing argument arrays into the classes, but instead retrieving it from DBT_Options. Modified Paths: -------------- src/org/binarytranslator/DBT_Options.java src/org/binarytranslator/Main.java src/org/binarytranslator/arch/arm/os/process/image/ARM_ImageProcessSpace.java src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java src/org/binarytranslator/generic/fault/BadInstructionException.java src/org/binarytranslator/generic/os/abi/linux/LinuxStackInitializer.java src/org/binarytranslator/generic/os/loader/Loader.java src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java src/org/binarytranslator/generic/os/loader/image/ImageLoader.java src/org/binarytranslator/generic/os/process/ProcessSpace.java Modified: src/org/binarytranslator/DBT_Options.java =================================================================== --- src/org/binarytranslator/DBT_Options.java 2007-04-06 11:51:35 UTC (rev 23) +++ src/org/binarytranslator/DBT_Options.java 2007-04-11 13:39:17 UTC (rev 24) @@ -8,6 +8,9 @@ */ package org.binarytranslator; +import java.util.HashMap; +import java.util.Map.Entry; + /** * Options for controlling the emulator */ @@ -25,6 +28,12 @@ public final static boolean unimplementedSystemCallsFatal = true; // -oO Translation settings Oo- + + /** The file that is currently being executed. */ + public static String executableFile; + + /** Arguments given to the executable.*/ + public static String[] executableArguments = null; /** * The initial optimisation level @@ -154,47 +163,132 @@ * The group ID for the user running the command */ public final static int GID = 100; - + + /** Stores the arguments given to the DBT by the user. These are NOT the arguments given to the executable. */ + private final static HashMap<String, String> dbtArguments = new HashMap<String, String>(); + /** - * Process a command line option - * - * @arg the command line argument starting "-X:dbt:" + * Read and parse the command line arguments. */ - public static void processArgument(String arg) { - if (arg.startsWith("-X:dbt:debugInstr=true")) { - debugInstr = true; - } else if (arg.startsWith("-X:dbt:debugRuntime=true")) { - debugRuntime = true; - } else if (arg.startsWith("-X:dbt:debugSyscall=true")) { - debugSyscall = true; - } else if (arg.startsWith("-X:dbt:debugSyscallMore=true")) { - debugSyscallMore = true; - } else if (arg.startsWith("-X:dbt:globalBranchLevel=")) { - globalBranchLevel = Integer.parseInt(arg.substring(25)); - } else if (arg.startsWith("-X:dbt:initialOptLevel=")) { - initialOptLevel = Integer.parseInt(arg.substring(23)); - } else if (arg.startsWith("-X:dbt:instrOpt0=")) { - instrOpt0 = Integer.parseInt(arg.substring(17)); - } else if (arg.startsWith("-X:dbt:instrOpt1=")) { - instrOpt1 = Integer.parseInt(arg.substring(17)); - } else if (arg.startsWith("-X:dbt:instrOpt2=")) { - instrOpt2 = Integer.parseInt(arg.substring(17)); - } else if (arg.startsWith("-X:dbt:singleInstrTranslation=true")) { - singleInstrTranslation = true; - } else if (arg.startsWith("-X:dbt:resolveBranchesAtOnce=true")) { - resolveBranchesAtOnce = true; - } else if (arg.startsWith("-X:dbt:resolveBranchesAtOnce=false")) { - resolveBranchesAtOnce = false; - } else if (arg.startsWith("-X:dbt:resolveProceduresBeforeBranches=true")) { - resolveProceduresBeforeBranches = true; - } else if (arg.startsWith("-X:dbt:resolveProceduresBeforeBranches=false")) { - resolveProceduresBeforeBranches = false; - } else if (arg.startsWith("-X:dbt:gdbStub=true")) { - gdbStub = true; - } else if (arg.startsWith("-X:dbt:gdbStubPort=")) { - gdbStubPort = Integer.parseInt(arg.substring(19)); + public static void parseArguments(String[] args) { + parseArgumentsToHashmap(args); + + for (Entry<String, String> argument : dbtArguments.entrySet()) { + String arg = argument.getKey(); + String value = argument.getValue(); + + try { + parseSingleArgument(arg, value); + } + catch (NumberFormatException e) { + throw new Error("Argument " + arg + " is not a valid integer."); + } + } + } + + /** + * Parses a single argument into the options class. + */ + private static void parseSingleArgument(String arg, String value) { + + if (arg.equalsIgnoreCase("-X:dbt:debugInstr")) { + debugInstr = Boolean.parseBoolean(value); + } else if (arg.equalsIgnoreCase("-X:dbt:debugRuntime")) { + debugRuntime = Boolean.parseBoolean(value); + } else if (arg.equalsIgnoreCase("-X:dbt:debugSyscall")) { + debugSyscall = Boolean.parseBoolean(value); + } else if (arg.equalsIgnoreCase("-X:dbt:debugSyscallMore")) { + debugSyscallMore = Boolean.parseBoolean(value); + } else if (arg.equalsIgnoreCase("-X:dbt:globalBranchLevel")) { + globalBranchLevel = Integer.parseInt(value); + } else if (arg.equalsIgnoreCase("-X:dbt:initialOptLevel")) { + initialOptLevel = Integer.parseInt(value); + } else if (arg.equalsIgnoreCase("-X:dbt:instrOpt0")) { + instrOpt0 = Integer.parseInt(value); + } else if (arg.equalsIgnoreCase("-X:dbt:instrOpt1")) { + instrOpt1 = Integer.parseInt(value); + } else if (arg.equalsIgnoreCase("-X:dbt:instrOpt2")) { + instrOpt2 = Integer.parseInt(value); + } else if (arg.equalsIgnoreCase("-X:dbt:singleInstrTranslation")) { + singleInstrTranslation = Boolean.parseBoolean(value); + } else if (arg.equalsIgnoreCase("-X:dbt:resolveBranchesAtOnce")) { + resolveBranchesAtOnce = Boolean.parseBoolean(value); + } else if (arg.equalsIgnoreCase("-X:dbt:resolveBranchesAtOnce")) { + resolveBranchesAtOnce = Boolean.parseBoolean(value); + } else if (arg.equalsIgnoreCase("-X:dbt:resolveProceduresBeforeBranches")) { + resolveProceduresBeforeBranches = Boolean.parseBoolean(value); + } else if (arg.equalsIgnoreCase("-X:dbt:resolveProceduresBeforeBranches")) { + resolveProceduresBeforeBranches = Boolean.parseBoolean(value); + } else if (arg.equalsIgnoreCase("-X:dbt:gdbStub")) { + gdbStub = Boolean.parseBoolean(value); + } else if (arg.equalsIgnoreCase("-X:dbt:gdbStubPort")) { + gdbStubPort = Integer.parseInt(value); } else { - throw new Error("DBT Options: Unrecongised emulator option " + arg); + throw new Error("DBT Options: Unknown emulator option " + arg); } } + + /** + * Takes an array of arguments and parses them as key=value pairs into the hashmap arguments. + */ + private static void parseArgumentsToHashmap(String[] args) { + + String key = null; + String value; + int next = 0; + + try { + //are there further arguments? + if (next == args.length) { + return; + } + + key = args[next++].trim(); + + if (!key.startsWith("-")) { + //this is not an argument to the DBT, so it must the file we're trying to execute. + executableFile = key; + + //the remaining arguments may be passed to the executable + executableArguments = new String[args.length - next]; + for (int i = next; i < args.length; i++) + executableArguments[i] = args[next + i]; + + return; + } + + //did the user give an argument without spaces in it? + int pos = key.indexOf('='); + if (pos != -1) { + value = key.substring(pos + 1); + key = key.substring(0, pos); + } + else { + + //extract the argument's value + do { + value = args[next++].trim(); + + if (value.startsWith("=")) + { + if (value.length() > 1) + value = value.substring(1); + else + value = ""; + } + } + while ( value.length() == 0 ); + } + + //store the argument's key and value + if (dbtArguments.containsKey(key)) { + throw new Error(String.format("Parameter %s already defined", key)); + } + + dbtArguments.put(key, value); + } + catch (Exception e) { + throw new Error("Invalid argument format for argument " + key); + } + } } Modified: src/org/binarytranslator/Main.java =================================================================== --- src/org/binarytranslator/Main.java 2007-04-06 11:51:35 UTC (rev 23) +++ src/org/binarytranslator/Main.java 2007-04-11 13:39:17 UTC (rev 24) @@ -18,20 +18,7 @@ * */ public class Main { - /* - * Variables required for an instance of the emulator - */ - /** - * A process space encapsulating the execution of a process - */ - ProcessSpace ps; - - /* - * Utility functions - */ - - /** * Debug information * * @param s @@ -47,62 +34,44 @@ /** * Usage */ - public static void usage() { + public static void showUsage() { System.out .println("org.binarytranslator.Main [-X:dbt:...] <program> <args...>"); } /** - * Constructor - should only be run from main - * - * @param args - * command line arguments. args[0] is the program to load. - */ - private Main(String[] args) { - // Check we have a file to load - if (args.length < 1) { - usage(); - throw new Error("Error program ran without arguments"); - } else { - // Set up and load the process space - try { - report("Loading " + args[0]); - Loader loader = Loader.getLoader(args[0]); - ps = loader.readBinary(args); - } catch (java.io.IOException e) { - usage(); - throw new Error("Error accessing file: " + args[0], e); - } - report("Sucessfully created process"); - } - } - - /** * Main method * * @param args * command line arguments (see usage()) */ public static void main(String[] args) { + + if (args.length < 1) { + showUsage(); + return; + } + // Process any arguments for the emulator - for (int i = 0; i < args.length; i++) { - if (args[i].startsWith("-X:dbt:")) { - DBT_Options.processArgument(args[i]); - } else { - if (i != 0) { - String new_args[] = new String[args.length - i]; - for (int j = 0; j < (args.length - i); j++) { - new_args[j] = args[i + j]; - } - args = new_args; - } - break; - } + try { + DBT_Options.parseArguments(args); + } catch (Exception e) { + System.err.println("Error while parsing command line arguments."); + System.err.println(e.getMessage()); } - Main runtime = new Main(args); - for (int i = 0; i < args.length; i++) { - report("Argument " + i + ": " + args[i]); + + ProcessSpace ps; + + try { + report("Loading " + DBT_Options.executableFile); + Loader loader = Loader.getLoader(DBT_Options.executableFile); + ps = loader.readBinary(DBT_Options.executableFile); + } + catch (java.io.IOException e) { + throw new Error("Error accessing file: " + args[0], e); } - runtime.ps.run(); + + report("Sucessfully created process."); + ps.run(); } } Modified: src/org/binarytranslator/arch/arm/os/process/image/ARM_ImageProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/arm/os/process/image/ARM_ImageProcessSpace.java 2007-04-06 11:51:35 UTC (rev 23) +++ src/org/binarytranslator/arch/arm/os/process/image/ARM_ImageProcessSpace.java 2007-04-11 13:39:17 UTC (rev 24) @@ -28,7 +28,7 @@ } @Override - public void initialise(Loader loader, int pc, int brk, String[] args) { + public void initialise(Loader loader, int pc, int brk) { registers.write(ARM_Registers.PC, pc); } Modified: src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java 2007-04-06 11:51:35 UTC (rev 23) +++ src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java 2007-04-11 13:39:17 UTC (rev 24) @@ -45,7 +45,7 @@ } @Override - public void initialise(Loader loader, int pc, int brk, String[] args) { + public void initialise(Loader loader, int pc, int brk) { registers.write(ARM_Registers.PC, pc); this.brk = brk; @@ -69,8 +69,7 @@ LinuxStackInitializer.AuxiliaryVectorType.AT_SECURE, 0, LinuxStackInitializer.AuxiliaryVectorType.AT_NULL, 0x0 }; - LinuxStackInitializer.stackInit(memory, STACK_TOP, args, - getEnvironmentVariables(), auxVector); + LinuxStackInitializer.stackInit(memory, STACK_TOP, getEnvironmentVariables(), auxVector); } public int getBrk() { Modified: src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java 2007-04-06 11:51:35 UTC (rev 23) +++ src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java 2007-04-11 13:39:17 UTC (rev 24) @@ -65,16 +65,16 @@ * @param args * command line arguments */ - public void initialise(Loader loader, int pc, int brk, String args[]) { + public void initialise(Loader loader, int pc, int brk) { this.pc = pc; this.brk = brk; - this.r1 = initialiseStack(loader, pc, args); + this.r1 = initialiseStack(loader, pc); } /** * Initialise the stack */ - private int initialiseStack(Loader loader, int pc, String args[]) { + private int initialiseStack(Loader loader, int pc) { int[] auxVector = { LinuxStackInitializer.AuxiliaryVectorType.AT_IGNOREPPC, LinuxStackInitializer.AuxiliaryVectorType.AT_IGNOREPPC, @@ -118,7 +118,7 @@ * binaries. */ - return LinuxStackInitializer.stackInit(memory, STACK_TOP, args, + return LinuxStackInitializer.stackInit(memory, STACK_TOP, getEnvironmentVariables(), auxVector); } Modified: src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java 2007-04-06 11:51:35 UTC (rev 23) +++ src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java 2007-04-11 13:39:17 UTC (rev 24) @@ -56,16 +56,16 @@ * @param brk the initial value for the top of BSS * @param args command line arguments */ - public void initialise(Loader loader, int pc, int brk, String args[]) { + public void initialise(Loader loader, int pc, int brk) { registers.eip = pc; this.brk = brk; - registers.writeGP32(X86_Registers.ESP, initialiseStack(loader, pc, args)); + registers.writeGP32(X86_Registers.ESP, initialiseStack(loader, pc)); } /** * Initialise the stack */ - private int initialiseStack(Loader loader, int pc, String args[]) { + private int initialiseStack(Loader loader, int pc) { int[] auxVector = {LinuxStackInitializer.AuxiliaryVectorType.AT_SYSINFO, 0xffffe400, LinuxStackInitializer.AuxiliaryVectorType.AT_SYSINFO_EHDR, 0xffffe000, LinuxStackInitializer.AuxiliaryVectorType.AT_HWCAP, 0x78bfbff, @@ -86,7 +86,7 @@ //LinuxStackInitializer.AuxiliaryVectorType.AT_PLATFORM, LinuxStackInitializer.AuxiliaryVectorType.STACK_TOP - getPlatformString().length, LinuxStackInitializer.AuxiliaryVectorType.AT_NULL, 0x0}; - return LinuxStackInitializer.stackInit(memory, STACK_TOP, args, getEnvironmentVariables(), auxVector); + return LinuxStackInitializer.stackInit(memory, STACK_TOP, getEnvironmentVariables(), auxVector); } /** Modified: src/org/binarytranslator/generic/fault/BadInstructionException.java =================================================================== --- src/org/binarytranslator/generic/fault/BadInstructionException.java 2007-04-06 11:51:35 UTC (rev 23) +++ src/org/binarytranslator/generic/fault/BadInstructionException.java 2007-04-11 13:39:17 UTC (rev 24) @@ -11,7 +11,21 @@ import org.binarytranslator.generic.os.process.ProcessSpace; public class BadInstructionException extends Exception { + + private final int pc; + private final ProcessSpace ps; + public BadInstructionException(int pc, ProcessSpace ps) { super("Bad instruction encountered at 0x" + Integer.toHexString(pc)); + this.pc = pc; + this.ps = ps; } + + public int getInstructionAddress() { + return pc; + } + + public ProcessSpace getProcessSpace() { + return ps; + } } Modified: src/org/binarytranslator/generic/os/abi/linux/LinuxStackInitializer.java =================================================================== --- src/org/binarytranslator/generic/os/abi/linux/LinuxStackInitializer.java 2007-04-06 11:51:35 UTC (rev 23) +++ src/org/binarytranslator/generic/os/abi/linux/LinuxStackInitializer.java 2007-04-11 13:39:17 UTC (rev 24) @@ -10,6 +10,7 @@ import java.io.UnsupportedEncodingException; +import org.binarytranslator.DBT_Options; import org.binarytranslator.generic.memory.Memory; import org.binarytranslator.generic.memory.MemoryMapException; @@ -274,7 +275,11 @@ * @param the auxiliary vector, including the terminating AT_NULL (two zeroes). * @return the bottom of the stack in memory */ - public static int stackInit(Memory memory, int stackTop, String[] argv, String[] env, int[] auxVector) { + public static int stackInit(Memory memory, int stackTop, String[] env, int[] auxVector) { + + //grab the vector of command line options that are to be delivered to the linux program + String[] argv = DBT_Options.executableArguments; + // --- // First create the information block by concatenating all strings // together, then compute pointers to values in the information Modified: src/org/binarytranslator/generic/os/loader/Loader.java =================================================================== --- src/org/binarytranslator/generic/os/loader/Loader.java 2007-04-06 11:51:35 UTC (rev 23) +++ src/org/binarytranslator/generic/os/loader/Loader.java 2007-04-11 13:39:17 UTC (rev 24) @@ -20,9 +20,6 @@ * appropriate sub-class loader is chosen to actually load the binary. */ public abstract class Loader { - /* - * Utility functions - */ /** * Debug information @@ -45,11 +42,11 @@ * Create a process space, load the binary into it and initialise the stack, * etc. * - * @param args - * command line arguments + * @param filename + * The file, which is to be loaded and executed. * @return the process space to start executing */ - abstract public ProcessSpace readBinary(String[] args) throws IOException; + abstract public ProcessSpace readBinary(String filename) throws IOException; /** * Return the application binary interface (ABI) supported by this file Modified: src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java =================================================================== --- src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java 2007-04-06 11:51:35 UTC (rev 23) +++ src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java 2007-04-11 13:39:17 UTC (rev 24) @@ -116,13 +116,13 @@ /** * Main entry point that loads the binary - * @param args command line arguments including the program file name + * @param filename the program file name * @return process space containing loaded binary */ - public ProcessSpace readBinary(String[] args) throws IOException + public ProcessSpace readBinary(String filename) throws IOException { - report("Opening File: " + args[0]); - RandomAccessFile rFile = new RandomAccessFile(args[0], "r"); + report("Opening File: " + filename); + RandomAccessFile rFile = new RandomAccessFile(filename, "r"); elfHeader = new ELF_Header(rFile); //NB also sets up reader report("ELF header read successfully"); @@ -149,7 +149,7 @@ "entry = 0x" + Integer.toHexString(elfHeader.getEntryPoint()) + " brk = 0x" + Integer.toHexString(brk) ); - ps.initialise(this, elfHeader.getEntryPoint(), brk, args); + ps.initialise(this, elfHeader.getEntryPoint(), brk); return ps; } Modified: src/org/binarytranslator/generic/os/loader/image/ImageLoader.java =================================================================== --- src/org/binarytranslator/generic/os/loader/image/ImageLoader.java 2007-04-06 11:51:35 UTC (rev 23) +++ src/org/binarytranslator/generic/os/loader/image/ImageLoader.java 2007-04-11 13:39:17 UTC (rev 24) @@ -82,10 +82,12 @@ } } - public ProcessSpace readBinary(String[] args) throws IOException { + /** + */ + public ProcessSpace readBinary(String filename) throws IOException { - report("Reading: " + args[0]); - RandomAccessFile file = new RandomAccessFile(args[0], "r"); + report("Reading: " + filename); + RandomAccessFile file = new RandomAccessFile(filename, "r"); if (!readAndCheckID(file)) throw new IOException("File does not contain the expected EXT_IMG ID string."); @@ -118,7 +120,7 @@ return null; } - ps.initialise(this, 0, -1, args); + ps.initialise(this, 0, -1); return ps; } Modified: src/org/binarytranslator/generic/os/process/ProcessSpace.java =================================================================== --- src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-04-06 11:51:35 UTC (rev 23) +++ src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-04-11 13:39:17 UTC (rev 24) @@ -293,10 +293,8 @@ * the entry point * @param brk * the initial value for the top of BSS - * @param args - * command line arguments */ - public abstract void initialise(Loader loader, int pc, int brk, String args[]); + public abstract void initialise(Loader loader, int pc, int brk); /** * Constructor This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cap...@us...> - 2007-04-06 11:51:36
|
Revision: 23 http://svn.sourceforge.net/pearcolator/?rev=23&view=rev Author: captain5050 Date: 2007-04-06 04:51:35 -0700 (Fri, 06 Apr 2007) Log Message: ----------- Fix a few build and runtime issues Modified Paths: -------------- src/org/binarytranslator/Main.java src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java src/org/binarytranslator/generic/os/process/ProcessSpace.java src/org/binarytranslator/vmInterface/DBT_Trace.java src/org/binarytranslator/vmInterface/DynamicCodeRunner.java Modified: src/org/binarytranslator/Main.java =================================================================== --- src/org/binarytranslator/Main.java 2007-04-03 14:11:34 UTC (rev 22) +++ src/org/binarytranslator/Main.java 2007-04-06 11:51:35 UTC (rev 23) @@ -62,6 +62,7 @@ // Check we have a file to load if (args.length < 1) { usage(); + throw new Error("Error program ran without arguments"); } else { // Set up and load the process space try { Modified: src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java 2007-04-03 14:11:34 UTC (rev 22) +++ src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java 2007-04-06 11:51:35 UTC (rev 23) @@ -1,7 +1,6 @@ package org.binarytranslator.arch.arm.os.process; import java.io.IOException; - import org.binarytranslator.DBT_Options; import org.binarytranslator.arch.arm.os.process.image.ARM_ImageProcessSpace; import org.binarytranslator.arch.arm.os.process.linux.ARM_LinuxProcessSpace; @@ -11,6 +10,7 @@ import org.binarytranslator.generic.os.process.ProcessSpace; import org.jikesrvm.compilers.opt.ir.OPT_GenerationContext; import org.jikesrvm.compilers.opt.ir.OPT_HIRGenerator; +import org.vmmagic.pragma.Uninterruptible; public abstract class ARM_ProcessSpace extends ProcessSpace { @@ -94,6 +94,7 @@ /** * Return as an integer the current instruction's address */ + @Uninterruptible public int getCurrentInstructionAddress() { return registers.read(ARM_Registers.PC); } Modified: src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java 2007-04-03 14:11:34 UTC (rev 22) +++ src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java 2007-04-06 11:51:35 UTC (rev 23) @@ -22,6 +22,7 @@ import org.binarytranslator.vmInterface.DBT_OptimizingCompilerException; import org.jikesrvm.compilers.opt.ir.OPT_GenerationContext; import org.jikesrvm.compilers.opt.ir.OPT_HIRGenerator; +import org.vmmagic.pragma.Uninterruptible; /** * Capture the running of a PowerPC process @@ -162,6 +163,7 @@ /** * Return as an integer the current instruction's address */ + @Uninterruptible public int getCurrentInstructionAddress() { return pc; } Modified: src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java 2007-04-03 14:11:34 UTC (rev 22) +++ src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java 2007-04-06 11:51:35 UTC (rev 23) @@ -21,6 +21,7 @@ import org.binarytranslator.arch.x86.os.process.linux.X86_LinuxProcessSpace; import org.binarytranslator.arch.x86.decoder.X862IR; import org.binarytranslator.generic.os.loader.Loader; +import org.vmmagic.pragma.Uninterruptible; /** * Encapsulate the parts of an X86 process that are common across operating systems @@ -172,6 +173,7 @@ /** * Return as an integer the current instruction's address */ + @Uninterruptible public int getCurrentInstructionAddress() { return registers.eip; } Modified: src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java 2007-04-03 14:11:34 UTC (rev 22) +++ src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java 2007-04-06 11:51:35 UTC (rev 23) @@ -24,7 +24,7 @@ /** * System calls object for handling system calls generated by this process */ - LinuxSystemCalls syscalls; + final LinuxSystemCalls syscalls; /** * Allows uniform access to the arguments of a system call. We cache this object for reuse. @@ -45,8 +45,8 @@ * Constructor */ public X86_LinuxProcessSpace(Loader loader) { + syscallArgs = new X86_LinuxSyscallArgumentIterator(this); syscalls = new X86_LinuxSystemCalls(this); - syscallArgs = new X86_LinuxSyscallArgumentIterator(this); } /** Modified: src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java =================================================================== --- src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java 2007-04-03 14:11:34 UTC (rev 22) +++ src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java 2007-04-06 11:51:35 UTC (rev 23) @@ -61,7 +61,7 @@ /** * List of (RandomAccessFile(s)) files currently open */ - private ArrayList files; + private ArrayList<Object> files; /** * Convert integer file descriptor into Java RandomAccessFile */ @@ -109,7 +109,7 @@ for(int i=0; i < MAX_SYSCALLS; i++) { systemCallTable[i] = USC; } - files = new ArrayList(); + files = new ArrayList<Object>(); files.add(System.in); files.add(System.out); files.add(System.err); @@ -447,7 +447,7 @@ } abstract class ParameterizedSystemCall extends SystemCall { - protected LinuxSystemCallGenerator.CallArgumentIterator arguments; + protected final LinuxSystemCallGenerator.CallArgumentIterator arguments; public ParameterizedSystemCall() { arguments = src.getSysCallArguments(); Modified: src/org/binarytranslator/generic/os/process/ProcessSpace.java =================================================================== --- src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-04-03 14:11:34 UTC (rev 22) +++ src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-04-06 11:51:35 UTC (rev 23) @@ -29,7 +29,9 @@ import org.binarytranslator.arch.x86.os.process.X86_ProcessSpace; import org.binarytranslator.arch.arm.os.process.ARM_ProcessSpace; import org.binarytranslator.arch.ppc.os.process.PPC_ProcessSpace; +import org.vmmagic.pragma.Uninterruptible; + /** * A process space encapsulates a running process. This superclass contains non * operating and architecture specific details of the process. @@ -348,6 +350,7 @@ /** * Return as an integer the current instruction's address */ + @Uninterruptible public abstract int getCurrentInstructionAddress(); /** Modified: src/org/binarytranslator/vmInterface/DBT_Trace.java =================================================================== --- src/org/binarytranslator/vmInterface/DBT_Trace.java 2007-04-03 14:11:34 UTC (rev 22) +++ src/org/binarytranslator/vmInterface/DBT_Trace.java 2007-04-06 11:51:35 UTC (rev 23) @@ -205,6 +205,7 @@ /** * Map bytecode index to java source line number */ + @Uninterruptible public int getLineNumberForBCIndex(int bci) { return bci; } Modified: src/org/binarytranslator/vmInterface/DynamicCodeRunner.java =================================================================== --- src/org/binarytranslator/vmInterface/DynamicCodeRunner.java 2007-04-03 14:11:34 UTC (rev 22) +++ src/org/binarytranslator/vmInterface/DynamicCodeRunner.java 2007-04-06 11:51:35 UTC (rev 23) @@ -23,7 +23,7 @@ * compiled using the PPC emulator. Uninterruptible is used to prevent garbage * collection errors with the dynamic bridge code. */ -@Uninterruptible +//@Uninterruptible @DynamicBridge public class DynamicCodeRunner { /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cap...@us...> - 2007-04-03 14:11:33
|
Revision: 22 http://svn.sourceforge.net/pearcolator/?rev=22&view=rev Author: captain5050 Date: 2007-04-03 07:11:34 -0700 (Tue, 03 Apr 2007) Log Message: ----------- Moved the typo fix into the RVM Modified Paths: -------------- rvmroot.patch Modified: rvmroot.patch =================================================================== --- rvmroot.patch 2007-04-02 12:43:16 UTC (rev 21) +++ rvmroot.patch 2007-04-03 14:11:34 UTC (rev 22) @@ -1,17 +1,8 @@ Index: build.xml =================================================================== ---- build.xml (revision 11903) +--- build.xml (revision 11998) +++ build.xml (working copy) -@@ -792,7 +792,7 @@ - </condition> - - <!-- -- FIXME: When we can capture the primordials based on reacability we will not need to delete class dir -+ FIXME: When we can capture the primordials based on reachability we will not need to delete class dir - here. We will also be able to compile ALL classes in one sweep. - --> - <delete dir="${build.classes}"/> -@@ -802,8 +802,8 @@ +@@ -803,8 +803,8 @@ debugLevel="lines,source" source="1.5" target="1.5" @@ -22,7 +13,7 @@ <bootclasspath> <pathelement location="${classpath.lib.dir}/classpath.jar"/> </bootclasspath> -@@ -862,7 +862,7 @@ +@@ -863,7 +863,7 @@ </javac> </target> @@ -31,7 +22,7 @@ <!-- create a rt.jar for the RVM --> <copy file="${classpath.lib.dir}/classpath.jar" tofile="${build.rt.jar}"/> <zip destfile="${build.rt.jar}" update="true" basedir="${build.classes}"> -@@ -881,7 +881,20 @@ +@@ -883,7 +883,20 @@ </jar> </target> @@ -54,7 +45,7 @@ <!-- * Section for building the boot image * --> Index: rvm/src-generated/opt-ir/InstructionFormatList.dat =================================================================== ---- rvm/src-generated/opt-ir/InstructionFormatList.dat (revision 11903) +--- rvm/src-generated/opt-ir/InstructionFormatList.dat (revision 11995) +++ rvm/src-generated/opt-ir/InstructionFormatList.dat (working copy) @@ -149,6 +149,14 @@ "U Cond OPT_ConditionOperand" "U BranchProfile OPT_BranchProfileOperand" @@ -73,7 +64,7 @@ "D Result OPT_RegisterOperand" "U Val1 OPT_Operand" "U Val2 OPT_Operand" \ Index: rvm/src-generated/opt-ir/OperatorList.dat =================================================================== ---- rvm/src-generated/opt-ir/OperatorList.dat (revision 11903) +--- rvm/src-generated/opt-ir/OperatorList.dat (revision 11995) +++ rvm/src-generated/opt-ir/OperatorList.dat (working copy) @@ -1255,6 +1255,20 @@ @@ -96,11 +87,9 @@ # Load a singed byte # NOTE: Because of our strategy of using explict guard instructions, there is no # way in the HIR/LIR that the actual load instruction can except. - - Index: rvm/src/OptDummy.java =================================================================== ---- rvm/src/OptDummy.java (revision 11903) +--- rvm/src/OptDummy.java (revision 11995) +++ rvm/src/OptDummy.java (working copy) @@ -20,4 +20,5 @@ static org.jikesrvm.compilers.opt.OPT_Compiler a; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mic...@us...> - 2007-04-02 12:43:18
|
Revision: 21 http://svn.sourceforge.net/pearcolator/?rev=21&view=rev Author: michael_baer Date: 2007-04-02 05:43:16 -0700 (Mon, 02 Apr 2007) Log Message: ----------- Addition to previous commit. Sorry, forgot to save that file... :) Modified Paths: -------------- src/org/binarytranslator/DBT.java Modified: src/org/binarytranslator/DBT.java =================================================================== --- src/org/binarytranslator/DBT.java 2007-04-02 12:41:02 UTC (rev 20) +++ src/org/binarytranslator/DBT.java 2007-04-02 12:43:16 UTC (rev 21) @@ -15,7 +15,7 @@ else { if (!cond) { - //assertion failed, see if we can get some info on where the assertion occured + //assertion failed, see if we can get some info on where the assertion occurred StackTraceElement[] trace = Thread.currentThread().getStackTrace(); if (trace.length > 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mic...@us...> - 2007-04-02 12:41:04
|
Revision: 20 http://svn.sourceforge.net/pearcolator/?rev=20&view=rev Author: michael_baer Date: 2007-04-02 05:41:02 -0700 (Mon, 02 Apr 2007) Log Message: ----------- Replaced VM._assert with DBT._assert Modified Paths: -------------- src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxSyscallArgumentIterator.java src/org/binarytranslator/generic/decoder/DecoderUtils.java Added Paths: ----------- src/org/binarytranslator/DBT.java src/org/binarytranslator/arch/arm/decoder/ src/org/binarytranslator/arch/arm/decoder/ARM2IR.java src/org/binarytranslator/arch/arm/decoder/ARM_InstructionDecoder.java src/org/binarytranslator/arch/arm/decoder/ARM_Laziness.java Removed Paths: ------------- ext/org/jikesrvm/VM_RuntimeCompiler.java Deleted: ext/org/jikesrvm/VM_RuntimeCompiler.java =================================================================== --- ext/org/jikesrvm/VM_RuntimeCompiler.java 2007-04-02 12:11:23 UTC (rev 19) +++ ext/org/jikesrvm/VM_RuntimeCompiler.java 2007-04-02 12:41:02 UTC (rev 20) @@ -1,775 +0,0 @@ -/* - * This file is part of Jikes RVM (http://jikesrvm.sourceforge.net). - * The Jikes RVM 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 IBM Corp. 2001, 2005 - */ -package org.jikesrvm; - -import org.jikesrvm.classloader.*; -import org.jikesrvm.opt.*; -import org.jikesrvm.adaptive.*; -import org.jikesrvm.ArchitectureSpecific.VM_JNICompiler; -import org.jikesrvm.runtime.VM_Time; -import org.jikesrvm.scheduler.VM_Thread; - -/** - * Harness to select which compiler to dynamically - * compile a method in first invocation. - * - * A place to put code common to all runtime compilers. - * This includes instrumentation code to get equivalent data for - * each of the runtime compilers. - * <p> - * We collect the following data for each compiler - * <ol> - * <li> - * total number of methods complied by the compiler - * <li> - * total compilation time in milliseconds. - * <li> - * total number of bytes of bytecodes compiled by the compiler - * (under the assumption that there is no padding in the bytecode - * array and thus VM_Method.getBytecodes().length is the number bytes - * of bytecode for a method) - * <li> - * total number of machine code insructions generated by the compiler - * (under the assumption that there is no (excessive) padding in the - * machine code array and thus VM_CompiledMethod.numberOfInsturctions() - * is a close enough approximation of the number of machinecodes generated) - * </ol> - * Note that even if 3. & 4. are inflated due to padding, the numbers will - * still be an accurate measure of the space costs of the compile-only - * approach. - * - * @author Matthew Arnold - * @author Dave Grove - * @author Michael Hind - */ -public class VM_RuntimeCompiler implements VM_Constants, - VM_Callbacks.ExitMonitor { - - // Use these to encode the compiler for record() - public static final byte JNI_COMPILER = 0; - public static final byte BASELINE_COMPILER = 1; - public static final byte OPT_COMPILER = 2; - - // Data accumulators - private static final String[] name = {"JNI\t","Base\t","Opt\t"}; // Output names - private static int[] totalMethods = {0,0,0}; - private static double[] totalCompTime = {0,0,0}; - private static int[] totalBCLength = {0,0,0}; - private static int[] totalMCLength = {0,0,0}; - - // running sum of the natural logs of the rates, - // used for geometric mean, the product of rates is too big for doubles - // so we use the principle of logs to help us - // We compute e ** ((log a + log b + ... + log n) / n ) - private static double[] totalLogOfRates = {0,0,0}; - - // We can't record values until Math.log is loaded, so we miss the first few - private static int[] totalLogValueMethods = {0,0,0}; - - private static String[] earlyOptArgs = new String[0]; - - // is the opt compiler usable? - protected static boolean compilerEnabled; - - // is opt compiler currently in use? - // This flag is used to detect/avoid recursive opt compilation. - // (ie when opt compilation causes a method to be compiled). - // We also make all public entrypoints static synchronized methods - // because the opt compiler is not reentrant. - // When we actually fix defect 2912, we'll have to implement a different - // scheme that can distinguish between recursive opt compilation by the same - // thread (always bad) and parallel opt compilation (currently bad, future ok). - // NOTE: This code can be quite subtle, so please be absolutely sure - // you know what you're doing before modifying it!!! - protected static boolean compilationInProgress; - - // One time check to optionally preload and compile a specified class - protected static boolean preloadChecked = false; - - // Cache objects needed to cons up compilation plans - // TODO: cutting link to opt compiler by declaring type as object. - public static Object /* OPT_Options */ options; - public static Object /* OPT_OptimizationPlanElement[] */ optimizationPlan; - - /** - * To be called when the VM is about to exit. - * @param value the exit value - */ - public void notifyExit(int value) { - report(false); - } - - /** - * This method records the time and sizes (bytecode and machine code) for - * a compilation. - * @param compiler the compiler used - * @param method the resulting VM_Method - * @param compiledMethod the resulting compiled method - */ - public static void record(byte compiler, - VM_NormalMethod method, - VM_CompiledMethod compiledMethod) { - - recordCompilation(compiler, method.getBytecodeLength(), - compiledMethod.numberOfInstructions(), - compiledMethod.getCompilationTime()); - - if (VM.BuildForAdaptiveSystem) { - if (VM_AOSLogging.booted()) { - VM_AOSLogging.recordUpdatedCompilationRates(compiler, - method, - method.getBytecodeLength(), - totalBCLength[compiler], - compiledMethod.numberOfInstructions(), - totalMCLength[compiler], - compiledMethod.getCompilationTime(), - totalCompTime[compiler], - totalLogOfRates[compiler], - totalLogValueMethods[compiler], - totalMethods[compiler]); - } - } - } - - /** - * This method records the time and sizes (bytecode and machine code) for - * a compilation - * @param compiler the compiler used - * @param method the resulting VM_Method - * @param compiledMethod the resulting compiled method - */ - public static void record(byte compiler, - VM_NativeMethod method, - VM_CompiledMethod compiledMethod) { - - - recordCompilation(compiler, - 0, // don't have any bytecode info, its native - compiledMethod.numberOfInstructions(), - compiledMethod.getCompilationTime()); - } - - /** - * This method does the actual recording - * @param compiler the compiler used - * @param BCLength the number of bytecodes in method source - * @param MCLength the length of the generated machine code - * @param compTime the compilation time in ms - */ - private static void recordCompilation(byte compiler, - int BCLength, - int MCLength, - double compTime) { - - totalMethods[compiler]++; - totalMCLength[compiler] += MCLength; - totalCompTime[compiler] += compTime; - - // Comp rate not useful for JNI compiler because there is no bytecode! - if (compiler != JNI_COMPILER) { - totalBCLength[compiler] += BCLength; - double rate = BCLength / compTime; - - // need to be fully booted before calling log - if (VM.fullyBooted) { - // we want the geometric mean, but the product of rates is too big - // for doubles, so we use the principle of logs to help us - // We compute e ** ((log a + log b + ... + log n) / n ) - totalLogOfRates[compiler] += Math.log(rate); - totalLogValueMethods[compiler]++; - } - } - } - - /** - * This method produces a summary report of compilation activities - * @param explain Explains the metrics used in the report - */ - public static void report (boolean explain) { - VM.sysWrite("\n\t\tCompilation Subsystem Report\n"); - VM.sysWrite("Comp\t#Meths\tTime\tbcb/ms\tmcb/bcb\tMCKB\tBCKB\n"); - for (int i=0; i<=name.length-1; i++) { - if (totalMethods[i]>0) { - VM.sysWrite(name[i]); - // Number of methods - VM.sysWrite(totalMethods[i]); - VM.sysWrite("\t"); - // Compilation time - VM.sysWrite(totalCompTime[i]); - VM.sysWrite("\t"); - - if (i == JNI_COMPILER) { - VM.sysWrite("NA"); - } else { - // Bytecode bytes per millisecond, - // use unweighted geomean - VM.sysWrite(Math.exp(totalLogOfRates[i] / totalLogValueMethods[i]), 2); - } - VM.sysWrite("\t"); - // Ratio of machine code bytes to bytecode bytes - if (i != JNI_COMPILER) { - VM.sysWrite((double)(totalMCLength[i] << ArchitectureSpecific.VM_RegisterConstants.LG_INSTRUCTION_WIDTH)/(double)totalBCLength[i], 2); - } else { - VM.sysWrite("NA"); - } - VM.sysWrite("\t"); - // Generated machine code Kbytes - VM.sysWrite((double)(totalMCLength[i] << ArchitectureSpecific.VM_RegisterConstants.LG_INSTRUCTION_WIDTH)/1024, 1); - VM.sysWrite("\t"); - // Compiled bytecode Kbytes - if (i != JNI_COMPILER) { - VM.sysWrite((double)totalBCLength[i]/1024, 1); - } else { - VM.sysWrite("NA"); - } - VM.sysWrite("\n"); - } - } - if (explain) { - // Generate an explanation of the metrics reported - VM.sysWrite("\t\t\tExplanation of Metrics\n"); - VM.sysWrite("#Meths:\t\tTotal number of methods compiled by the compiler\n"); - VM.sysWrite("Time:\t\tTotal compilation time in milliseconds\n"); - VM.sysWrite("bcb/ms:\t\tNumber of bytecode bytes complied per millisecond\n"); - VM.sysWrite("mcb/bcb:\tRatio of machine code bytes to bytecode bytes\n"); - VM.sysWrite("MCKB:\t\tTotal number of machine code bytes generated in kilobytes\n"); - VM.sysWrite("BCKB:\t\tTotal number of bytecode bytes compiled in kilobytes\n"); - } - - VM_BaselineCompiler.generateBaselineCompilerSubsystemReport(explain); - - if (VM.BuildForAdaptiveSystem) { - // Get the opt's report - VM_TypeReference theTypeRef = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/jikesrvm/opt/OPT_OptimizationPlanner;")); - VM_Type theType = theTypeRef.peekResolvedType(); - if (theType != null && theType.asClass().isInitialized()) { - OPT_OptimizationPlanner.generateOptimizingCompilerSubsystemReport(explain); - } else { - VM.sysWrite("\n\tNot generating Optimizing Compiler SubSystem Report because \n"); - VM.sysWrite("\tthe opt compiler was never invoked.\n\n"); - } - } - } - - /** - * Return the current estimate of basline-compiler rate, in bcb/msec - */ - public static double getBaselineRate() { - return Math.exp(totalLogOfRates[BASELINE_COMPILER] / totalLogValueMethods[BASELINE_COMPILER]); - } - - /** - * This method will compile the passed method using the baseline compiler. - * @param method the method to compile - */ - public static VM_CompiledMethod baselineCompile(VM_NormalMethod method) { - VM_Callbacks.notifyMethodCompile(method, VM_CompiledMethod.BASELINE); - long start = 0; - if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { - start = VM_Thread.getCurrentThread().accumulateCycles(); - } - - VM_CompiledMethod cm = VM_BaselineCompiler.compile(method); - - if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { - long end = VM_Thread.getCurrentThread().accumulateCycles(); - double compileTime = VM_Time.cyclesToMillis(end - start); - cm.setCompilationTime(compileTime); - record(BASELINE_COMPILER, method, cm); - } - - return cm; - } - - /** - * Process command line argument destined for the opt compiler - */ - public static void processOptCommandLineArg(String prefix, String arg) { - if (VM.BuildForAdaptiveSystem) { - if (compilerEnabled) { - if (((OPT_Options)options).processAsOption(prefix, arg)) { - // update the optimization plan to reflect the new command line argument - optimizationPlan = OPT_OptimizationPlanner.createOptimizationPlan((OPT_Options)options); - } else { - VM.sysWrite("Unrecognized opt compiler argument \""+arg+"\""); - VM.sysExit(VM.EXIT_STATUS_BOGUS_COMMAND_LINE_ARG); - } - } else { - String[] tmp = new String[earlyOptArgs.length+2]; - for (int i=0; i<earlyOptArgs.length; i++) { - tmp[i] = earlyOptArgs[i]; - } - earlyOptArgs = tmp; - earlyOptArgs[earlyOptArgs.length-2] = prefix; - earlyOptArgs[earlyOptArgs.length-1] = arg; - } - } else { - if (VM.VerifyAssertions) VM._assert(NOT_REACHED); - } - } - - /** - * attempt to compile the passed method with the OPT_Compiler. - * Don't handle OPT_OptimizingCompilerExceptions - * (leave it up to caller to decide what to do) - * Precondition: compilationInProgress "lock" has been acquired - * @param method the method to compile - * @param plan the plan to use for compiling the method - */ - private static VM_CompiledMethod optCompile(VM_NormalMethod method, - OPT_CompilationPlan plan) - throws OPT_OptimizingCompilerException { - if (VM.BuildForOptCompiler) { - if (VM.VerifyAssertions) { - VM._assert(compilationInProgress, "Failed to acquire compilationInProgress \"lock\""); - } - - VM_Callbacks.notifyMethodCompile(method, VM_CompiledMethod.JNI); - long start = 0; - if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { - start = VM_Thread.getCurrentThread().accumulateCycles(); - } - - VM_CompiledMethod cm = OPT_Compiler.compile(plan); - - if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { - long end = VM_Thread.getCurrentThread().accumulateCycles(); - double compileTime = VM_Time.cyclesToMillis(end - start); - cm.setCompilationTime(compileTime); - record(OPT_COMPILER, method, cm); - } - - return cm; - } else { - if (VM.VerifyAssertions) VM._assert(false); - return null; - } - } - - - // These methods are safe to invoke from VM_RuntimeCompiler.compile - - /** - * This method tries to compile the passed method with the OPT_Compiler, - * using the default compilation plan. If - * this fails we will use the quicker compiler (baseline for now) - * The following is carefully crafted to avoid (infinte) recursive opt - * compilation for all combinations of bootimages & lazy/eager compilation. - * Be absolutely sure you know what you're doing before changing it !!! - * @param method the method to compile - */ - public static synchronized VM_CompiledMethod optCompileWithFallBack(VM_NormalMethod method) { - if (VM.BuildForOptCompiler) { - if (compilationInProgress) { - return fallback(method); - } else { - try { - compilationInProgress = true; - OPT_CompilationPlan plan = new OPT_CompilationPlan(method, (OPT_OptimizationPlanElement[])optimizationPlan, null, (OPT_Options)options); - return optCompileWithFallBackInternal(method, plan); - } finally { - compilationInProgress = false; - } - } - } else { - if (VM.VerifyAssertions) VM._assert(false); - return null; - } - } - - /** - * This method tries to compile the passed method with the OPT_Compiler - * with the passed compilation plan. If - * this fails we will use the quicker compiler (baseline for now) - * The following is carefully crafted to avoid (infinte) recursive opt - * compilation for all combinations of bootimages & lazy/eager compilation. - * Be absolutely sure you know what you're doing before changing it !!! - * @param method the method to compile - * @param plan the compilation plan to use for the compile - */ - public static synchronized VM_CompiledMethod optCompileWithFallBack(VM_NormalMethod method, - OPT_CompilationPlan plan) { - if (VM.BuildForOptCompiler) { - if (compilationInProgress) { - return fallback(method); - } else { - try { - compilationInProgress = true; - return optCompileWithFallBackInternal(method, plan); - } finally { - compilationInProgress = false; - } - } - } else { - if (VM.VerifyAssertions) VM._assert(false); - return null; - } - } - - /** - * This real method that performs the opt compilation. - * @param method the method to compile - * @param plan the compilation plan to use - */ - private static VM_CompiledMethod optCompileWithFallBackInternal(VM_NormalMethod method, - OPT_CompilationPlan plan) { - if (VM.BuildForOptCompiler) { - if (method.hasNoOptCompileAnnotation()) return fallback(method); - try { - return optCompile(method, plan); - } catch (OPT_OptimizingCompilerException e) { - String msg = "VM_RuntimeCompiler: can't optimize \"" + method + "\" (error was: " + e + "): reverting to baseline compiler\n"; - if (e.isFatal && VM.ErrorsFatal) { - e.printStackTrace(); - VM.sysFail(msg); - } else { - boolean printMsg = true; - if (e instanceof OPT_MagicNotImplementedException) { - printMsg = !((OPT_MagicNotImplementedException)e).isExpected; - } - if (printMsg) VM.sysWrite(msg); - } - return fallback(method); - } - } else { - if (VM.VerifyAssertions) VM._assert(false); - return null; - } - } - - - /* recompile the specialized method with OPT_Compiler. */ - public static VM_CompiledMethod recompileWithOptOnStackSpecialization(OPT_CompilationPlan plan) { - if (VM.BuildForOptCompiler) { - if (VM.VerifyAssertions) { VM._assert(plan.method.isForOsrSpecialization());} - if (compilationInProgress) { - return null; - } - - try { - compilationInProgress = true; - - // the compiler will check if isForOsrSpecialization of the method - VM_CompiledMethod cm = optCompile(plan.method, plan); - - // we donot replace the compiledMethod of original method, - // because it is temporary method - return cm; - } catch (OPT_OptimizingCompilerException e) { - e.printStackTrace(); - String msg = "Optimizing compiler " - +"(via recompileWithOptOnStackSpecialization): " - +"can't optimize \"" + plan.method + "\" (error was: " + e + ")\n"; - - if (e.isFatal && VM.ErrorsFatal) { - VM.sysFail(msg); - } else { - VM.sysWrite(msg); - } - return null; - } finally { - compilationInProgress = false; - } - } else { - if (VM.VerifyAssertions) VM._assert(false); - return null; - } - } - - /** - * This method tries to compile the passed method with the OPT_Compiler. - * It will install the new compiled method in the VM, if sucessful. - * NOTE: the recompile method should never be invoked via - * VM_RuntimeCompiler.compile; - * it does not have sufficient guards against recursive recompilation. - * @param plan the compilation plan to use - * @return the CMID of the new method if successful, -1 if the - * recompilation failed. - * - **/ - public static synchronized int recompileWithOpt(OPT_CompilationPlan plan) { - if (VM.BuildForOptCompiler) { - if (compilationInProgress) { - return -1; - } else { - try { - compilationInProgress = true; - VM_CompiledMethod cm = optCompile(plan.method, plan); - try { - plan.method.replaceCompiledMethod(cm); - } catch (Throwable e) { - String msg = "Failure in VM_Method.replaceCompiledMethod (via recompileWithOpt): while replacing \"" + plan.method + "\" (error was: " + e + ")\n"; - if (VM.ErrorsFatal) { - e.printStackTrace(); - VM.sysFail(msg); - } else { - VM.sysWrite(msg); - } - return -1; - } - return cm.getId(); - } catch (OPT_OptimizingCompilerException e) { - String msg = "Optimizing compiler (via recompileWithOpt): can't optimize \"" + plan.method + "\" (error was: " + e + ")\n"; - if (e.isFatal && VM.ErrorsFatal) { - e.printStackTrace(); - VM.sysFail(msg); - } else { - // VM.sysWrite(msg); - } - return -1; - } finally { - compilationInProgress = false; - } - } - } else { - if (VM.VerifyAssertions) VM._assert(false); - return -1; - } - } - - /** - * A wrapper method for those callers who don't want to make - * optimization plans - * @param method the method to recompile - */ - public static int recompileWithOpt(VM_NormalMethod method) { - if (VM.BuildForOptCompiler) { - OPT_CompilationPlan plan = new OPT_CompilationPlan(method, - (OPT_OptimizationPlanElement[])optimizationPlan, - null, - (OPT_Options)options); - return recompileWithOpt(plan); - } else { - if (VM.VerifyAssertions) VM._assert(false); - return -1; - } - } - - /** - * This method uses the default compiler (baseline) to compile a method - * It is typically called when a more aggressive compilation fails. - * This method is safe to invoke from VM_RuntimeCompiler.compile - */ - protected static VM_CompiledMethod fallback(VM_NormalMethod method) { - // call the inherited method "baselineCompile" - return baselineCompile(method); - } - - public static void boot() { - if (VM.MeasureCompilation) { - VM_Callbacks.addExitMonitor(new VM_RuntimeCompiler()); - } - if (VM.BuildForAdaptiveSystem) { - options = new OPT_Options(); - optimizationPlan = OPT_OptimizationPlanner.createOptimizationPlan((OPT_Options)options); - if (VM.MeasureCompilation) { - OPT_OptimizationPlanner.initializeMeasureCompilation(); - } - - OPT_Compiler.init((OPT_Options)options); - - VM_PreCompile.init(); - // when we reach here the OPT compiler is enabled. - compilerEnabled = true; - - for (int i=0; i<earlyOptArgs.length; i+=2) { - processOptCommandLineArg(earlyOptArgs[i], earlyOptArgs[i+1]); - } - } - } - - public static void processCommandLineArg(String prefix, String arg) { - if (VM.BuildForAdaptiveSystem) { - if (VM_Controller.options !=null && VM_Controller.options.optIRC()) { - processOptCommandLineArg(prefix, arg); - } else { - VM_BaselineCompiler.processCommandLineArg(prefix, arg); - } - } else { - VM_BaselineCompiler.processCommandLineArg(prefix, arg); - } - } - - /** - * Compile a Java method when it is first invoked. - * @param method the method to compile - * @return its compiled method. - */ - public static VM_CompiledMethod compile(VM_NormalMethod method) { - if (VM.BuildForAdaptiveSystem) { - VM_CompiledMethod cm; - if (!VM_Controller.enabled) { - // System still early in boot process; compile with baseline compiler - cm = baselineCompile(method); - VM_ControllerMemory.incrementNumBase(); - } else { - if (!preloadChecked) { - preloadChecked = true; // prevent subsequent calls - // N.B. This will use irc options - if (VM_BaselineCompiler.options.PRELOAD_CLASS != null) { - compilationInProgress = true; // use baseline during preload - // Other than when boot options are requested (processed during preloadSpecialClass - // It is hard to communicate options for these special compilations. Use the - // default options and at least pick up the verbose if requested for base/irc - OPT_Options tmpoptions = (OPT_Options)((OPT_Options)options).clone(); - tmpoptions.PRELOAD_CLASS = VM_BaselineCompiler.options.PRELOAD_CLASS; - tmpoptions.PRELOAD_AS_BOOT = VM_BaselineCompiler.options.PRELOAD_AS_BOOT; - if (VM_BaselineCompiler.options.PRINT_METHOD) { - tmpoptions.PRINT_METHOD = true; - } else { - tmpoptions = (OPT_Options)options; - } - OPT_Compiler.preloadSpecialClass(tmpoptions); - compilationInProgress = false; - } - } - if (VM_Controller.options.optIRC() || method.optCompileOnly()) { - if (// will only run once: don't bother optimizing - method.isClassInitializer() || - // exception in progress. can't use opt compiler: - // it uses exceptions and runtime doesn't support - // multiple pending (undelivered) exceptions [--DL] - VM_Thread.getCurrentThread().hardwareExceptionRegisters.inuse) { - // compile with baseline compiler - cm = baselineCompile(method); - VM_ControllerMemory.incrementNumBase(); - } else { // compile with opt compiler - VM_AOSInstrumentationPlan instrumentationPlan = - new VM_AOSInstrumentationPlan(VM_Controller.options, method); - OPT_CompilationPlan compPlan = - new OPT_CompilationPlan(method, (OPT_OptimizationPlanElement[])optimizationPlan, - instrumentationPlan, (OPT_Options)options); - if(!method.optCompileOnly()) { - cm = optCompileWithFallBack(method, compPlan); - } - else { - compilationInProgress = true; - try { - cm = optCompile(method, compPlan); - } catch (OPT_OptimizingCompilerException e) { - String msg = "Optimizing compiler " - +"(on method that can only be optimizing compiler compiled): " - +"can't optimize \"" + method + "\""; - throw new Error(msg, e); - } finally { - compilationInProgress = false; - } - } - } - } else { - if ((VM_Controller.options.BACKGROUND_RECOMPILATION - && (!VM_Controller.options.ENABLE_REPLAY_COMPILE) - && (!VM_Controller.options.ENABLE_PRECOMPILE)) - ) { - // must be an inital compilation: compile with baseline compiler - // or if recompilation with OSR. - cm = baselineCompile(method); - VM_ControllerMemory.incrementNumBase(); - } else { - if (VM_CompilerAdviceAttribute.hasAdvice()) { - VM_CompilerAdviceAttribute attr = - VM_CompilerAdviceAttribute.getCompilerAdviceInfo(method); - if (attr.getCompiler() != VM_CompiledMethod.OPT) { - cm=fallback(method); - VM_AOSLogging.recordCompileTime(cm, 0.0); - return cm; - } - int newCMID = -2; - OPT_CompilationPlan compPlan; - if (VM_Controller.options.counters()) { - // for invocation counter, we only use one optimization level - compPlan = VM_InvocationCounts.createCompilationPlan(method); - } else { - // for now there is not two options for sampling, so - // we don't have to use: if (VM_Controller.options.sampling()) - compPlan = VM_Controller.recompilationStrategy.createCompilationPlan(method, attr.getOptLevel(), null); - } - VM_AOSLogging.recompilationStarted(compPlan); - newCMID = recompileWithOpt(compPlan); - cm = newCMID == -1 ? null : VM_CompiledMethods.getCompiledMethod(newCMID); - if (newCMID == -1) { - VM_AOSLogging.recompilationAborted(compPlan); - } else if (newCMID > 0) { - VM_AOSLogging.recompilationCompleted(compPlan); - } - if (cm == null) { // if recompilation is aborted - cm = baselineCompile(method); - VM_ControllerMemory.incrementNumBase(); - } - } else { - // check to see if there is a compilation plan for this method. - VM_ControllerPlan plan = VM_ControllerMemory.findLatestPlan(method); - if (plan == null || plan.getStatus() != VM_ControllerPlan.IN_PROGRESS) { - // initial compilation or some other funny state: compile with baseline compiler - cm = baselineCompile(method); - VM_ControllerMemory.incrementNumBase(); - } else { - cm = plan.doRecompile(); - if (cm == null) { - // opt compilation aborted for some reason. - cm = baselineCompile(method); - } - } - } - } - } - } - if ((VM_Controller.options.ENABLE_ADVICE_GENERATION) - && (cm.getCompilerType() == VM_CompiledMethod.BASELINE) - && VM_Controller.enabled) { - VM_AOSGenerator.baseCompilationCompleted(cm); - } - VM_AOSLogging.recordCompileTime(cm, 0.0); - return cm; - } else { - return baselineCompile(method); - } - } - - /** - * Compile the stub for a native method when it is first invoked. - * @param method the method to compile - * @return its compiled method. - */ - public static VM_CompiledMethod compile(VM_NativeMethod method) { - VM_Callbacks.notifyMethodCompile(method, VM_CompiledMethod.JNI); - long start = 0; - if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { - start = VM_Thread.getCurrentThread().accumulateCycles(); - } - - VM_CompiledMethod cm = VM_JNICompiler.compile(method); - if (VM.verboseJNI) { - VM.sysWriteln("[Dynamic-linking native method " + - method.getDeclaringClass() + "." + method.getName() + - " "+method.getDescriptor()); - } - - if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { - long end = VM_Thread.getCurrentThread().accumulateCycles(); - double compileTime = VM_Time.cyclesToMillis(end - start); - cm.setCompilationTime(compileTime); - record(JNI_COMPILER, method, cm); - } - - return cm; - } - - /** - * returns the string version of compiler number, using the naming scheme - * in this file - * @param compiler the compiler of interest - * @return the string version of compiler number - */ - public static String getCompilerName(byte compiler) { - return name[compiler]; - } - -} Added: src/org/binarytranslator/DBT.java =================================================================== --- src/org/binarytranslator/DBT.java (rev 0) +++ src/org/binarytranslator/DBT.java 2007-04-02 12:41:02 UTC (rev 20) @@ -0,0 +1,33 @@ +package org.binarytranslator; + +import org.jikesrvm.VM; + +public final class DBT { + public static final boolean VerifyAssertions = true; + + public static void _assert(boolean cond) { + + if (!VerifyAssertions) + return; + + if (VM.VerifyAssertions) + VM._assert(cond); + else + { + if (!cond) { + //assertion failed, see if we can get some info on where the assertion occured + StackTraceElement[] trace = Thread.currentThread().getStackTrace(); + + if (trace.length > 0) { + StackTraceElement source = trace[trace.length-1]; + System.err.println("Assertion failed in: " + source.getFileName() + "(" + source.getLineNumber() + ")"); + } + else { + System.err.println("Assertion failed. No stack trace on assertion source available."); + } + + System.exit(-1); + } + } + } +} Added: src/org/binarytranslator/arch/arm/decoder/ARM2IR.java =================================================================== --- src/org/binarytranslator/arch/arm/decoder/ARM2IR.java (rev 0) +++ src/org/binarytranslator/arch/arm/decoder/ARM2IR.java 2007-04-02 12:41:02 UTC (rev 20) @@ -0,0 +1,185 @@ +package org.binarytranslator.arch.arm.decoder; + +import java.util.ArrayList; + +import org.binarytranslator.DBT; +import org.binarytranslator.DBT_Options; +import org.binarytranslator.arch.arm.os.process.ARM_ProcessSpace; +import org.binarytranslator.generic.decoder.DecoderUtils; +import org.binarytranslator.generic.decoder.Laziness; +import org.jikesrvm.classloader.VM_Atom; +import org.jikesrvm.classloader.VM_FieldReference; +import org.jikesrvm.classloader.VM_MemberReference; +import org.jikesrvm.classloader.VM_TypeReference; +import org.jikesrvm.compilers.opt.ir.*; + +public class ARM2IR extends DecoderUtils implements OPT_HIRGenerator { + + /** Mapping of ARM registers to HIR registers */ + protected OPT_Register regMap[] = new OPT_Register[16]; + + /** Set to true for each register that is in use during the current trace */ + protected boolean regUsed[] = new boolean[16]; + + /** Type reference to the ARM process space */ + private static final VM_TypeReference psTref; + + /** A field reference to the ARM registers class within the PS */ + private static final VM_FieldReference registersFref; + + /** A type reference to the ARM registers class */ + private static final VM_TypeReference registersTref; + + /** A field reference to the ARM registers array within the ARM_Registers class */ + private static final VM_FieldReference registers_regs_Fref; + + /** A type reference to the ARM registers array within the ARM_Registers class */ + private static final VM_TypeReference registers_regs_Tref; + + /** A register holding a reference to ps.registers */ + private OPT_Register ps_registers; + + /** A register holding a reference to ps.registers.regs */ + private OPT_Register ps_registers_regs; + + + static { + psTref = VM_TypeReference.findOrCreate(ARM_ProcessSpace.class); + + registersFref = VM_MemberReference + .findOrCreate( + psTref, + VM_Atom.findOrCreateAsciiAtom("registers"), + VM_Atom + .findOrCreateAsciiAtom("Lorg/binarytranslator/arch/arm/os/process/ARM_Registers;")) + .asFieldReference(); + + if (DBT.VerifyAssertions) DBT._assert(registersFref != null); + + registersTref = registersFref.getFieldContentsType(); + + if (DBT.VerifyAssertions) DBT._assert(registersTref != null); + + registers_regs_Fref = VM_MemberReference.findOrCreate( + registersTref, VM_Atom.findOrCreateAsciiAtom("regs"), + VM_Atom.findOrCreateAsciiAtom("[I")).asFieldReference(); + + if (DBT.VerifyAssertions) DBT._assert(registers_regs_Fref != null); + + registers_regs_Tref = registers_regs_Fref.getFieldContentsType(); + + if (DBT.VerifyAssertions) DBT._assert(registers_regs_Tref != null); + } + + + public ARM2IR(OPT_GenerationContext context) { + super(context); + } + + @Override + protected Laziness createInitialLaziness() { + return new ARM_Laziness(); + } + + @Override + protected void fillAllRegisters() { + + OPT_RegisterOperand ps_registersOp; + + if (ps_registers != null) { + ps_registersOp = gc.temps.makeTemp(registersTref); + ps_registers = ps_registersOp.register; + appendInstructionToCurrentBlock(GetField.create(GETFIELD, ps_registersOp, + gc.makeLocal(1, psTref), new OPT_AddressConstantOperand(registersFref + .peekResolvedField().getOffset()), new OPT_LocationOperand( + registersFref), new OPT_TrueGuardOperand())); + } + else { + ps_registersOp = new OPT_RegisterOperand(ps_registers, registersTref); + } + + // Get the array of general purpose registers + OPT_RegisterOperand ps_registers_regsOp; + if (ps_registers_regs == null) { + + ps_registers_regsOp = gc.temps.makeTemp(registers_regs_Tref); + appendInstructionToCurrentBlock(GetField.create(GETFIELD, + ps_registers_regsOp, ps_registersOp.copyRO(), + new OPT_AddressConstantOperand(registers_regs_Fref.peekResolvedField() + .getOffset()), new OPT_LocationOperand(registers_regs_Fref), + new OPT_TrueGuardOperand())); + ps_registers_regs = ps_registers_regsOp.register; + } else { + ps_registers_regsOp = new OPT_RegisterOperand(ps_registers_regs, registers_regs_Tref); + } + + // Fill general purpose registers + for (int i = 0; i < regMap.length; i++) { + OPT_RegisterOperand regOp; + if (regMap[i] == null) { + regOp = makeTemp(VM_TypeReference.Int); + regMap[i] = regOp.register; + } else { + regOp = new OPT_RegisterOperand(regMap[i], VM_TypeReference.Int); + } + appendInstructionToCurrentBlock(ALoad.create(INT_ALOAD, regOp, + ps_registers_regsOp.copyRO(), new OPT_IntConstantOperand(i), + new OPT_LocationOperand(VM_TypeReference.Int), + new OPT_TrueGuardOperand())); + } + } + + public OPT_RegisterOperand getRegister(int r) { + regUsed[r] = true; + return new OPT_RegisterOperand(regMap[r], VM_TypeReference.Int); + } + + @Override + protected OPT_Register[] getUnusedRegisters() { + + ArrayList<OPT_Register> unusedRegisters = new ArrayList<OPT_Register>(); + + for (int i = 0; i < regUsed.length; i++) + if (!regUsed[i]) { + unusedRegisters.add(regMap[i]); + } + + return unusedRegisters.toArray(new OPT_Register[unusedRegisters.size()]); + } + + @Override + protected void report(String str) { + System.out.println("ARM2IR: " + str); + } + + @Override + public void resolveLaziness(Laziness laziness) { + //NO-OP, as we're not using laziness at the moment + } + + @Override + protected void spillAllRegisters() { + + // spill general purpose registers + OPT_RegisterOperand ps_registers_regsOp = new OPT_RegisterOperand( + ps_registers_regs, registers_regs_Tref); + for (int i = 0; i < regMap.length; i++) { + // We can save spills if the trace has no syscalls and the register was + // never used + if ((DBT_Options.singleInstrTranslation == false) + || (regUsed[i] == true)) { + appendInstructionToCurrentBlock(AStore.create(INT_ASTORE, + new OPT_RegisterOperand(regMap[i], VM_TypeReference.Int), + ps_registers_regsOp.copyRO(), new OPT_IntConstantOperand(i), + new OPT_LocationOperand(VM_TypeReference.Int), + new OPT_TrueGuardOperand())); + } + } + } + + @Override + protected int translateInstruction(Laziness lazy, int pc) { + return ARM_InstructionDecoder.translateInstruction(this, + (ARM_ProcessSpace) ps, (ARM_Laziness) lazy, pc); + } +} Added: src/org/binarytranslator/arch/arm/decoder/ARM_InstructionDecoder.java =================================================================== --- src/org/binarytranslator/arch/arm/decoder/ARM_InstructionDecoder.java (rev 0) +++ src/org/binarytranslator/arch/arm/decoder/ARM_InstructionDecoder.java 2007-04-02 12:41:02 UTC (rev 20) @@ -0,0 +1,163 @@ +package org.binarytranslator.arch.arm.decoder; + +import org.binarytranslator.DBT; +import org.binarytranslator.arch.arm.os.process.ARM_ProcessSpace; +import org.binarytranslator.generic.decoder.InstructionDecoder; +import org.jikesrvm.compilers.opt.ir.*; + +public class ARM_InstructionDecoder extends InstructionDecoder { + + abstract static class BasicDecoder implements OPT_Operators { + /** Return the value of a single bit. Note that the bit is 0-based.*/ + public static final boolean getBit(int word, int bit) { + if (DBT.VerifyAssertions) DBT._assert(bit >= 0 && bit <= 31); + return (word & (1 << bit)) != 0; + } + + /** Transfer a subsequence of bits within (word) into an integer. Note that all bits are 0-based. */ + public static final int getBits(int word, int from, int to) { + if (DBT.VerifyAssertions) DBT._assert(from < to && from >= 0 && to <= 31); + return (word & ((1 << (to+1)) - 1)) >> from; + } + + protected abstract int translate(ARM2IR arm2ir, ARM_ProcessSpace ps, ARM_Laziness lazy, int pc, int instr); + } + + /** Translates LDR and STR instructions */ + static class LDR_STR_Decoder extends BasicDecoder { + + @Override + protected int translate(ARM2IR arm2ir, ARM_ProcessSpace ps, ARM_Laziness lazy, int pc, int instr) { + boolean immediateOperand = getBit(instr, 25); + boolean preIndex = getBit(instr, 24); + boolean positiveOffset = getBit(instr, 23); + boolean transferByte = getBit(instr, 22); + boolean writeBack = getBit(instr, 21); + boolean loadOperation = getBit(instr, 20); + int offset = getBits(instr, 0, 11); + + int baseRegister = getBits(instr, 16, 19); + int destRegister = getBits(instr, 12, 15); + + System.out.println("Decoding LDR/STR with: "); + System.out.println("Imm: " + immediateOperand); + System.out.println("Pre Index: " + preIndex); + System.out.println("Offset: " + (positiveOffset ? "+" : "-") + offset); + System.out.println("Base: " + baseRegister); + System.out.println("Dest: " + destRegister); + System.out.println("Load Operation: " + loadOperation); + System.out.println("Write back: " + writeBack); + + //we are only handling a limitied subset of this instruction + if (DBT.VerifyAssertions) DBT._assert(immediateOperand == false && transferByte == false && writeBack == false && preIndex == true); + + //resolve correspoding memory address for this operation + OPT_Operand memoryAddr; + + //take the ARM pipeline into account when storing relative to the pc + if (baseRegister == 15) { + if (positiveOffset) + memoryAddr = new OPT_IntConstantOperand(pc + 8 + offset); + else + memoryAddr = new OPT_IntConstantOperand(pc + 8 - offset); + } + else { + OPT_Operand Rs = arm2ir.getRegister(baseRegister); + memoryAddr = arm2ir.getTempInt(0); + arm2ir.appendInstructionToCurrentBlock(Binary.create(INT_ADD, (OPT_RegisterOperand)memoryAddr, Rs, new OPT_IntConstantOperand(offset))); + } + + //resolve dest register + OPT_RegisterOperand Rd = arm2ir.getRegister(destRegister); + + if (loadOperation) { + //load a word + ps.memory.translateLoad32(memoryAddr, Rd); + } + else { + //store a word + ps.memory.translateStore32(memoryAddr, Rd); + } + + return pc+4; + } + } + + abstract static class DataProcessingOperation_Decoder extends BasicDecoder { + + protected int Rd; + protected int Rs; + protected boolean setConditionCodes; + + protected boolean hasImmediate; + protected int immediate; + + @Override + protected final int translate(ARM2IR arm2ir, ARM_ProcessSpace ps, ARM_Laziness lazy, int pc, int instr) { + hasImmediate = getBit(instr, 25); + setConditionCodes = getBit(instr, 20); + Rd = getBits(instr, 12, 15); + Rs = getBits(instr, 16, 19); + + //we're only handling a subset of the possible instruction options + if (DBT.VerifyAssertions) DBT._assert(Rd != 15 && Rs != 15 && hasImmediate == true); + + if (hasImmediate) + immediate = getBits(instr, 0, 7) << getBits(instr, 8, 11); + + System.out.println("Decoding Data Processing Instruction with: "); + System.out.println("Rs: " + Rs); + System.out.println("Rd: " + Rd); + System.out.println("Op Code: " + getBits(instr, 21, 24)); + System.out.println("Set Condition Codes: " + setConditionCodes); + + if (hasImmediate) + System.out.println("Immediate: " + immediate); + + translateActualOpcode(arm2ir, ps, lazy, pc, instr); + + if (setConditionCodes && Rd != 15) { + throw new UnsupportedOperationException("Setting conditions codes is not yet supported"); + } + + return pc+4; + } + + protected abstract void translateActualOpcode(ARM2IR arm2ir, ARM_ProcessSpace ps, ARM_Laziness lazy, int pc, int instr); + } + + static class ADD_Decoder extends DataProcessingOperation_Decoder { + + @Override + protected void translateActualOpcode(ARM2IR arm2ir, ARM_ProcessSpace ps, ARM_Laziness lazy, int pc, int instr) { + + arm2ir.appendInstructionToCurrentBlock(Binary.create(INT_ADD, arm2ir.getRegister(Rd), arm2ir.getRegister(Rs), new OPT_IntConstantOperand(immediate))); + } + } + + static class BranchDecoder extends BasicDecoder { + + @Override + protected int translate(ARM2IR arm2ir, ARM_ProcessSpace ps, ARM_Laziness lazy, int pc, int instr) { + boolean branchAndLink = getBit(instr, 24); + int offset = getBits(instr, 0, 23); + + if (DBT.VerifyAssertions) DBT._assert(branchAndLink == false); + + return pc + 8 + offset; + } + } + + public static int translateInstruction(ARM2IR arm2ir, ARM_ProcessSpace ps, ARM_Laziness lazy, int pc) { + int instr = ps.memory.loadInstruction32(pc); + + System.out.println("Translating Instruction:" + instr); + BasicDecoder decoder = null; + + if (BasicDecoder.getBits(instr, 26, 27) == 1) { + decoder = new LDR_STR_Decoder(); + } + + return decoder.translate(arm2ir, ps, lazy, pc, instr); + } +} Added: src/org/binarytranslator/arch/arm/decoder/ARM_Laziness.java =================================================================== --- src/org/binarytranslator/arch/arm/decoder/ARM_Laziness.java (rev 0) +++ src/org/binarytranslator/arch/arm/decoder/ARM_Laziness.java 2007-04-02 12:41:02 UTC (rev 20) @@ -0,0 +1,25 @@ +package org.binarytranslator.arch.arm.decoder; + +import org.binarytranslator.generic.decoder.Laziness; + +public class ARM_Laziness extends Laziness { + + @Override + public Object clone() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean equivalent(Laziness other) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Key makeKey(int pc) { + // TODO Auto-generated method stub + return null; + } + +} Modified: src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java =================================================================== --- src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java 2007-04-02 12:11:23 UTC (rev 19) +++ src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java 2007-04-02 12:41:02 UTC (rev 20) @@ -11,12 +11,12 @@ // DBT classes import java.util.ArrayList; +import org.binarytranslator.DBT; import org.binarytranslator.DBT_Options; import org.binarytranslator.arch.ppc.os.process.PPC_ProcessSpace; import org.binarytranslator.generic.decoder.DecoderUtils; import org.binarytranslator.generic.decoder.Laziness; import org.binarytranslator.vmInterface.DBT_OptimizingCompilerException; -import org.jikesrvm.VM; import org.jikesrvm.classloader.VM_Atom; import org.jikesrvm.classloader.VM_FieldReference; import org.jikesrvm.classloader.VM_MemberReference; @@ -296,8 +296,8 @@ * the number of the register to fill. */ private void fillGPRegister(int r) { - if (VM.VerifyAssertions) - VM._assert(r < 32); + if (DBT.VerifyAssertions) + DBT._assert(r < 32); OPT_RegisterOperand result; if (intRegMap[r] == null) { @@ -320,10 +320,10 @@ * the number of the register to spill. */ private void spillGPRegister(int r) { - if (VM.VerifyAssertions) - VM._assert(r < 32); - if (VM.VerifyAssertions) - VM._assert(intRegMap[r] != null); + if (DBT.VerifyAssertions) + DBT._assert(r < 32); + if (DBT.VerifyAssertions) + DBT._assert(intRegMap[r] != null); OPT_RegisterOperand regOp = new OPT_RegisterOperand(intRegMap[r], VM_TypeReference.Int); @@ -342,8 +342,8 @@ * the number of the register to fill. */ private void fillFPRegister(int r) { - if (VM.VerifyAssertions) - VM._assert(r < 32); + if (DBT.VerifyAssertions) + DBT._assert(r < 32); OPT_RegisterOperand result; if (fpRegMap[r] == null) { @@ -367,11 +367,9 @@ * the number of the register to spill. */ private void spillFPRegister(int r) { - if (VM.VerifyAssertions) - VM._assert(r < 32); - if (VM.VerifyAssertions) - VM._assert(fpRegMap[r] != null); - + if (DBT.VerifyAssertions) + DBT._assert(r < 32 && fpRegMap[r] != null); + OPT_RegisterOperand regOp = new OPT_RegisterOperand(fpRegMap[r], VM_TypeReference.Double); @@ -735,8 +733,9 @@ * the number of the PPC GP register */ public OPT_RegisterOperand getGPRegister(int r) { - if (VM.VerifyAssertions) - VM._assert(r < 32); + if (DBT.VerifyAssertions) + DBT._assert(r < 32); + intRegInUseMap[r] = true; return new OPT_RegisterOperand(intRegMap[r], VM_TypeReference.Int); } @@ -749,8 +748,8 @@ * the number of the PPC FP register */ public OPT_RegisterOperand getFPRegister(int r) { - if (VM.VerifyAssertions) - VM._assert(r < 32); + if (DBT.VerifyAssertions) + DBT._assert(r < 32); fpRegInUseMap[r] = true; return new OPT_RegisterOperand(fpRegMap[r], VM_TypeReference.Double); } Modified: src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java =================================================================== --- src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java 2007-04-02 12:11:23 UTC (rev 19) +++ src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java 2007-04-02 12:41:02 UTC (rev 20) @@ -8,13 +8,13 @@ */ package org.binarytranslator.arch.ppc.decoder; +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.decoder.InstructionDecoder; import org.binarytranslator.generic.fault.BadInstructionException; import org.binarytranslator.vmInterface.DBT_OptimizingCompilerException; -import org.jikesrvm.VM; import org.jikesrvm.compilers.opt.ir.Binary; import org.jikesrvm.compilers.opt.ir.BooleanCmp; import org.jikesrvm.compilers.opt.ir.BooleanCmp2; @@ -685,8 +685,8 @@ protected static void plantBranchToBlockDependentOnCondition(PPC2IR ppc2ir, OPT_BasicBlock targetBlock, PPC_Laziness lazy, int BI, boolean cond_true, boolean likely) { - if (VM.VerifyAssertions) - VM._assert((BI >= 0) && (BI < 32)); + if (DBT.VerifyAssertions) + DBT._assert((BI >= 0) && (BI < 32)); // Calculate the condition register field being tested int crf = BI >> 2; @@ -3898,8 +3898,8 @@ protected int translateXL_FORM(PPC2IR ppc2ir, PPC_Laziness lazy, int pc, int inst, int opcode, int crfD00, int crfS00, int zero, int secondaryOpcode, int zero2) { - if (VM.VerifyAssertions) - VM._assert((secondaryOpcode == 0) && (zero == 0) && (zero2 == 0)); + if (DBT.VerifyAssertions) + DBT._assert((secondaryOpcode == 0) && (zero == 0) && (zero2 == 0)); int crfD = crfD00 >> 2; int crfS = crfS00 >> 2; @@ -3986,8 +3986,8 @@ protected int translateXL_FORM(PPC2IR ppc2ir, PPC_Laziness lazy, int pc, int inst, int opcode, int BO, int BI, int zero, int secondaryOpcode, int lk) { - if (VM.VerifyAssertions) - VM._assert((secondaryOpcode == 16) && (zero == 0)); + if (DBT.VerifyAssertions) + DBT._assert((secondaryOpcode == 16) && (zero == 0)); // Translation process: // decode BO and optionally plant any of: @@ -4082,8 +4082,8 @@ protected int translateXL_FORM(PPC2IR ppc2ir, PPC_Laziness lazy, int pc, int inst, int opcode, int crbD, int crbA, int crbB, int secondaryOpcode, int zero) { - if (VM.VerifyAssertions) - VM._assert((secondaryOpcode == 33) && (zero == 0)); + if (DBT.VerifyAssertions) + DBT._assert((secondaryOpcode == 33) && (zero == 0)); // Resolve laziness as this instruction encodes lots of // nonsensical states for the condition register :-( @@ -4262,8 +4262,8 @@ protected int translateXL_FORM(PPC2IR ppc2ir, PPC_Laziness lazy, int pc, int inst, int opcode, int crbD, int crbA, int crbB, int secondaryOpcode, int zero) { - if (VM.VerifyAssertions) - VM._assert((secondaryOpcode == 193) && (zero == 0)); + if (DBT.VerifyAssertions) + DBT._assert((secondaryOpcode == 193) && (zero == 0)); // Resolve laziness as this instruction encodes lots of // nonsensical states for the condition register :-( @@ -4371,8 +4371,8 @@ protected int translateXL_FORM(PPC2IR ppc2ir, PPC_Laziness lazy, int pc, int inst, int opcode, int crbD, int crbA, int crbB, int secondaryOpcode, int zero) { - if (VM.VerifyAssertions) - VM._assert((secondaryOpcode == 289) && (zero == 0)); + if (DBT.VerifyAssertions) + DBT._assert((secondaryOpcode == 289) && (zero == 0)); // Resolve laziness as this instruction encodes lots of // nonsensical states for the condition register :-( @@ -4494,8 +4494,8 @@ protected int translateXL_FORM(PPC2IR ppc2ir, PPC_Laziness lazy, int pc, int inst, int opcode, int crbD, int crbA, int crbB, int secondaryOpcode, int zero) { - if (VM.VerifyAssertions) - VM._assert((secondaryOpcode == 449) && (zero == 0)); + if (DBT.VerifyAssertions) + DBT._assert((secondaryOpcode == 449) && (zero == 0)); // Resolve laziness as this instruction encodes lots of // nonsensical states for the condition register :-( @@ -4647,8 +4647,8 @@ protected int translateXL_FORM(PPC2IR ppc2ir, PPC_Laziness lazy, int pc, int inst, int opcode, int BO, int BI, int zero, int secondaryOpcode, int lk) { - if (VM.VerifyAssertions) - VM._assert((secondaryOpcode == 528) && (zero == 0)); + if (DBT.VerifyAssertions) + DBT._assert((secondaryOpcode == 528) && (zero == 0)); // Translation process: // decode BO and optionally plant any of: @@ -5045,8 +5045,8 @@ protected int translateXO_FORM(PPC2IR ppc2ir, PPC_Laziness lazy, int pc, int inst, int opcode, int rD, int rA, int rB, int OE, int secondaryOpcode, int Rc) { - if (VM.VerifyAssertions) - VM._assert(rB == 0); + if (DBT.VerifyAssertions) + DBT._assert(rB == 0); // Perform negation ppc2ir.appendInstructionToCurrentBlock(Unary.create(INT_NEG, ppc2ir @@ -5214,8 +5214,8 @@ protected int translateXO_FORM(PPC2IR ppc2ir, PPC_Laziness lazy, int pc, int inst, int opcode, int rD, int rA, int rB, int OE, int secondaryOpcode, int Rc) { - if (VM.VerifyAssertions) - VM._assert(rB == 0); + if (DBT.VerifyAssertions) + DBT._assert(rB == 0); // Get rA OPT_RegisterOperand reg_rA = ppc2ir.getGPRegister(rA); OPT_RegisterOperand reg_rD = ppc2ir.getGPRegister(rD); @@ -5274,8 +5274,8 @@ protected int translateXO_FORM(PPC2IR ppc2ir, PPC_Laziness lazy, int pc, int inst, int opcode, int rD, int rA, int rB, int OE, int secondaryOpcode, int Rc) { - if (VM.VerifyAssertions) - VM._assert(rB == 0); + if (DBT.VerifyAssertions) + DBT._assert(rB == 0); // Get rA & rD OPT_RegisterOperand reg_rA = ppc2ir.getGPRegister(rA); OPT_RegisterOperand reg_rD = ppc2ir.getGPRegister(rD); @@ -5359,8 +5359,8 @@ int inst, int opcode, int rD, int rA, int rB, int OE, int secondaryOpcode, int Rc) { - if (VM.VerifyAssertions) - VM._assert(rB == 0); + if (DBT.VerifyAssertions) + DBT._assert(rB == 0); // Get rA & rD OPT_RegisterOperand reg_rA = ppc2ir.getGPRegister(rA); OPT_RegisterOperand reg_rD = ppc2ir.getGPRegister(rD); @@ -6646,8 +6646,8 @@ */ protected int translateX_FORM(PPC2IR ppc2ir, PPC_Laziness lazy, int pc, int inst, int opcode, int crfD0L, int rA, int rB, int zero, int zero2) { - if (VM.VerifyAssertions) - VM._assert((zero == zero2) && (zero2 == 0)); + if (DBT.VerifyAssertions) + DBT._assert((zero == zero2) && (zero2 == 0)); int crfD = crfD0L >>> 2; setCRfield(ppc2ir, lazy, crfD, ppc2ir.getGPRegister(rA), ppc2ir @@ -6805,8 +6805,8 @@ protected int translateX_FORM(PPC2IR ppc2ir, PPC_Laziness lazy, int pc, int inst, int opcode, int rD, int zero1, int zero2, int secodaryOpcode, int zero3) { - if (VM.VerifyAssertions) - VM._assert((zero1 == zero2) && (zero2 == zero3) && (zero3 == 0)); + if (DBT.VerifyAssertions) + DBT._assert((zero1 == zero2) && (zero2 == zero3) && (zero3 == 0)); ppc2ir.appendInstructionToCurrentBlock(Move.create(INT_MOVE, ppc2ir .getGPRegister(rD), ppc2ir.getCRRegister())); @@ -11228,8 +11228,8 @@ */ protected int translateSC_FORM(PPC2IR ppc2ir, PPC_Laziness lazy, int pc, int inst, int opcode, int zero1, int zero2, int zero3, int one, int zero4) { - if (VM.VerifyAssertions) - VM._assert((zero1 == zero2) && (zero2 == zero3) && (zero3 == zero4) + if (DBT.VerifyAssertions) + DBT._assert((zero1 == zero2) && (zero2 == zero3) && (zero3 == zero4) && (zero4 == 0) && (one == 1)); ppc2ir.plantSystemCall(lazy, pc); return pc + 4; @@ -11733,8 +11733,8 @@ .makeJumpTarget())); ppc2ir.getCurrentBlock().deleteNormalOut(); ppc2ir.getCurrentBlock().insertOut(targetBlock); - if (VM.VerifyAssertions) - VM._assert(ppc2ir.getCurrentBlock().getNumberOfNormalOut() == 1); + if (DBT.VerifyAssertions) + DBT._assert(ppc2ir.getCurrentBlock().getNumberOfNormalOut() == 1); } else { OPT_Instruction gotoInstr = Goto.create(GOTO, null); ppc2ir.appendInstructionToCurrentBlock(gotoInstr); Modified: src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxSyscallArgumentIterator.java =================================================================== --- src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxSyscallArgumentIterator.java 2007-04-02 12:11:23 UTC (rev 19) +++ src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxSyscallArgumentIterator.java 2007-04-02 12:41:02 UTC (rev 20) @@ -1,8 +1,8 @@ package org.binarytranslator.arch.x86.os.process.linux; +import org.binarytranslator.DBT; import org.binarytranslator.arch.x86.os.process.X86_Registers; import org.binarytranslator.generic.os.abi.linux.LinuxSystemCallGenerator; -import org.jikesrvm.VM; public class X86_LinuxSyscallArgumentIterator implements Linu... [truncated message content] |
From: <mic...@us...> - 2007-04-02 12:11:29
|
Revision: 19 http://svn.sourceforge.net/pearcolator/?rev=19&view=rev Author: michael_baer Date: 2007-04-02 05:11:23 -0700 (Mon, 02 Apr 2007) Log Message: ----------- Added support for building with the latest JRVM. Modified Paths: -------------- ext/DBT_Dummy.java ext/org/jikesrvm/classloader/VM_Method.java ext/org/jikesrvm/classloader/VM_NormalMethod.java ext/org/jikesrvm/compilers/opt/OPT_Simplifier.java ext/org/jikesrvm/compilers/opt/ir/OPT_BC2IR.java ext/org/jikesrvm/compilers/opt/ir/OPT_ConditionOperand.java ext/org/jikesrvm/compilers/opt/ir/OPT_ConvertBCtoHIR.java ext/org/jikesrvm/compilers/opt/ir/OPT_GenerationContext.java ext/org/jikesrvm/compilers/opt/ir/OPT_HIRGenerator.java ext/org/jikesrvm/compilers/opt/ir/OPT_HIRInfo.java ext/org/jikesrvm/compilers/opt/ir/ia32/OPT_IA32ConditionOperand.java rvmroot.patch src/org/binarytranslator/DBT_Options.java src/org/binarytranslator/Main.java src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java src/org/binarytranslator/arch/arm/os/process/image/ARM_ImageProcessSpace.java src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java src/org/binarytranslator/arch/ppc/os/abi/linux/PPC_LinuxSystemCalls.java src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java src/org/binarytranslator/arch/x86/decoder/X862IR.java src/org/binarytranslator/arch/x86/decoder/X86_DecodedOperand.java src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java src/org/binarytranslator/generic/branch/ProcedureInformation.java src/org/binarytranslator/generic/decoder/DecoderUtils.java src/org/binarytranslator/generic/fault/BadInstructionException.java src/org/binarytranslator/generic/memory/ByteAddressedMemory.java src/org/binarytranslator/generic/memory/CallBasedMemory.java src/org/binarytranslator/generic/memory/IntAddressedPreSwappedMemory.java src/org/binarytranslator/generic/memory/Memory.java src/org/binarytranslator/generic/os/loader/Loader.java src/org/binarytranslator/generic/os/process/ProcessSpace.java src/org/binarytranslator/vmInterface/DBT_ConvertBinaryToHIR.java src/org/binarytranslator/vmInterface/DBT_OptimizingCompilerException.java src/org/binarytranslator/vmInterface/DBT_Trace.java src/org/binarytranslator/vmInterface/TranslationHelper.java Added Paths: ----------- ext/org/jikesrvm/compilers/ ext/org/jikesrvm/compilers/common/ ext/org/jikesrvm/compilers/common/VM_RuntimeCompiler.java ext/org/jikesrvm/compilers/opt/ Removed Paths: ------------- ext/org/jikesrvm/opt/ Modified: ext/DBT_Dummy.java =================================================================== --- ext/DBT_Dummy.java 2007-04-01 12:27:50 UTC (rev 18) +++ ext/DBT_Dummy.java 2007-04-02 12:11:23 UTC (rev 19) @@ -1,3 +1,4 @@ + /* * This file is part of binarytranslator.org. The binarytranslator.org * project is distributed under the Common Public License (CPL). @@ -12,16 +13,16 @@ * to find every class comprising the chnages to the opt compiler for DBT */ class OptDummy { - static org.jikesrvm.opt.ir.ia32.OPT_IA32ConditionOperand a; - static org.jikesrvm.opt.ir.OPT_HIRGenerator b; - static org.jikesrvm.opt.ir.OPT_GenerationContext c; - static org.jikesrvm.opt.ir.OPT_ConditionOperand d; - static org.jikesrvm.opt.ir.OPT_HIRInfo e; - static org.jikesrvm.opt.OPT_Simplifier f; + static org.jikesrvm.compilers.opt.ir.ia32.OPT_IA32ConditionOperand a; + static org.jikesrvm.compilers.opt.ir.OPT_HIRGenerator b; + static org.jikesrvm.compilers.opt.ir.OPT_GenerationContext c; + static org.jikesrvm.compilers.opt.ir.OPT_ConditionOperand d; + static org.jikesrvm.compilers.opt.ir.OPT_HIRInfo e; + static org.jikesrvm.compilers.opt.OPT_Simplifier f; static org.jikesrvm.ppc.PPC_Disassembler g; static org.jikesrvm.classloader.VM_Method j; static org.jikesrvm.classloader.VM_Member k; static org.jikesrvm.classloader.VM_NormalMethod l; - static org.jikesrvm.VM_RuntimeCompiler m; - static org.jikesrvm.opt.ir.OPT_ConvertBCtoHIR n; + static org.jikesrvm.compilers.common.VM_RuntimeCompiler m; + static org.jikesrvm.compilers.opt.ir.OPT_ConvertBCtoHIR n; } Modified: ext/org/jikesrvm/classloader/VM_Method.java =================================================================== --- ext/org/jikesrvm/classloader/VM_Method.java 2007-04-01 12:27:50 UTC (rev 18) +++ ext/org/jikesrvm/classloader/VM_Method.java 2007-04-02 12:11:23 UTC (rev 19) @@ -11,6 +11,8 @@ import org.jikesrvm.*; import org.jikesrvm.ArchitectureSpecific.VM_CodeArray; import org.jikesrvm.ArchitectureSpecific.VM_LazyCompilationTrampolineGenerator; +import org.jikesrvm.compilers.common.VM_CompiledMethod; +import org.jikesrvm.compilers.common.VM_CompiledMethods; import org.jikesrvm.runtime.VM_Statics; import org.jikesrvm.runtime.VM_Entrypoints; Modified: ext/org/jikesrvm/classloader/VM_NormalMethod.java =================================================================== --- ext/org/jikesrvm/classloader/VM_NormalMethod.java 2007-04-01 12:27:50 UTC (rev 18) +++ ext/org/jikesrvm/classloader/VM_NormalMethod.java 2007-04-02 12:11:23 UTC (rev 19) @@ -10,9 +10,12 @@ import org.jikesrvm.*; import org.vmmagic.pragma.*; -import org.jikesrvm.opt.ir.OPT_HIRGenerator; -import org.jikesrvm.opt.ir.OPT_BC2IR; -import org.jikesrvm.opt.ir.OPT_GenerationContext; +import org.jikesrvm.compilers.common.VM_BootImageCompiler; +import org.jikesrvm.compilers.common.VM_CompiledMethod; +import org.jikesrvm.compilers.common.VM_RuntimeCompiler; +import org.jikesrvm.compilers.opt.ir.OPT_BC2IR; +import org.jikesrvm.compilers.opt.ir.OPT_GenerationContext; +import org.jikesrvm.compilers.opt.ir.OPT_HIRGenerator; import org.jikesrvm.runtime.VM_DynamicLink; /** Added: ext/org/jikesrvm/compilers/common/VM_RuntimeCompiler.java =================================================================== --- ext/org/jikesrvm/compilers/common/VM_RuntimeCompiler.java (rev 0) +++ ext/org/jikesrvm/compilers/common/VM_RuntimeCompiler.java 2007-04-02 12:11:23 UTC (rev 19) @@ -0,0 +1,855 @@ +/* + * This file is part of Jikes RVM (http://jikesrvm.sourceforge.net). + * The Jikes RVM 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 IBM Corp. 2001, 2005 + */ +package org.jikesrvm.compilers.common; + +import org.jikesrvm.*; +import org.jikesrvm.classloader.*; +import org.jikesrvm.compilers.baseline.*; +import org.jikesrvm.compilers.opt.*; +import org.jikesrvm.adaptive.controller.VM_Controller; +import org.jikesrvm.adaptive.controller.VM_ControllerMemory; +import org.jikesrvm.adaptive.controller.VM_ControllerPlan; +import org.jikesrvm.adaptive.recompilation.VM_InvocationCounts; +import org.jikesrvm.adaptive.recompilation.VM_PreCompile; +import org.jikesrvm.adaptive.recompilation.instrumentation.VM_AOSInstrumentationPlan; +import org.jikesrvm.adaptive.util.*; +import org.jikesrvm.ArchitectureSpecific.VM_JNICompiler; +import org.jikesrvm.runtime.VM_Time; +import org.jikesrvm.scheduler.VM_Thread; + +/** + * Harness to select which compiler to dynamically compile a method in first + * invocation. + * + * A place to put code common to all runtime compilers. This includes + * instrumentation code to get equivalent data for each of the runtime + * compilers. + * <p> + * We collect the following data for each compiler + * <ol> + * <li> total number of methods complied by the compiler + * <li> total compilation time in milliseconds. + * <li> total number of bytes of bytecodes compiled by the compiler (under the + * assumption that there is no padding in the bytecode array and thus + * VM_Method.getBytecodes().length is the number bytes of bytecode for a method) + * <li> total number of machine code insructions generated by the compiler + * (under the assumption that there is no (excessive) padding in the machine + * code array and thus VM_CompiledMethod.numberOfInsturctions() is a close + * enough approximation of the number of machinecodes generated) + * </ol> + * Note that even if 3. & 4. are inflated due to padding, the numbers will still + * be an accurate measure of the space costs of the compile-only approach. + * + * @author Matthew Arnold + * @author Dave Grove + * @author Michael Hind + */ +public class VM_RuntimeCompiler implements VM_Constants, + VM_Callbacks.ExitMonitor { + + // Use these to encode the compiler for record() + public static final byte JNI_COMPILER = 0; + + public static final byte BASELINE_COMPILER = 1; + + public static final byte OPT_COMPILER = 2; + + // Data accumulators + private static final String[] name = { "JNI\t", "Base\t", "Opt\t" }; // Output + // names + + private static int[] totalMethods = { 0, 0, 0 }; + + private static double[] totalCompTime = { 0, 0, 0 }; + + private static int[] totalBCLength = { 0, 0, 0 }; + + private static int[] totalMCLength = { 0, 0, 0 }; + + // running sum of the natural logs of the rates, + // used for geometric mean, the product of rates is too big for doubles + // so we use the principle of logs to help us + // We compute e ** ((log a + log b + ... + log n) / n ) + private static double[] totalLogOfRates = { 0, 0, 0 }; + + // We can't record values until Math.log is loaded, so we miss the first few + private static int[] totalLogValueMethods = { 0, 0, 0 }; + + private static String[] earlyOptArgs = new String[0]; + + // is the opt compiler usable? + protected static boolean compilerEnabled; + + // is opt compiler currently in use? + // This flag is used to detect/avoid recursive opt compilation. + // (ie when opt compilation causes a method to be compiled). + // We also make all public entrypoints static synchronized methods + // because the opt compiler is not reentrant. + // When we actually fix defect 2912, we'll have to implement a different + // scheme that can distinguish between recursive opt compilation by the same + // thread (always bad) and parallel opt compilation (currently bad, future + // ok). + // NOTE: This code can be quite subtle, so please be absolutely sure + // you know what you're doing before modifying it!!! + protected static boolean compilationInProgress; + + // One time check to optionally preload and compile a specified class + protected static boolean preloadChecked = false; + + // Cache objects needed to cons up compilation plans + // TODO: cutting link to opt compiler by declaring type as object. + public static Object /* OPT_Options */options; + + public static Object /* OPT_OptimizationPlanElement[] */optimizationPlan; + + /** + * To be called when the VM is about to exit. + * + * @param value + * the exit value + */ + public void notifyExit(int value) { + report(false); + } + + /** + * This method records the time and sizes (bytecode and machine code) for a + * compilation. + * + * @param compiler + * the compiler used + * @param method + * the resulting VM_Method + * @param compiledMethod + * the resulting compiled method + */ + public static void record(byte compiler, VM_NormalMethod method, + VM_CompiledMethod compiledMethod) { + + recordCompilation(compiler, method.getBytecodeLength(), compiledMethod + .numberOfInstructions(), compiledMethod.getCompilationTime()); + + if (VM.BuildForAdaptiveSystem) { + if (VM_AOSLogging.booted()) { + VM_AOSLogging.recordUpdatedCompilationRates(compiler, method, method + .getBytecodeLength(), totalBCLength[compiler], compiledMethod + .numberOfInstructions(), totalMCLength[compiler], compiledMethod + .getCompilationTime(), totalCompTime[compiler], + totalLogOfRates[compiler], totalLogValueMethods[compiler], + totalMethods[compiler]); + } + } + } + + /** + * This method records the time and sizes (bytecode and machine code) for a + * compilation + * + * @param compiler + * the compiler used + * @param method + * the resulting VM_Method + * @param compiledMethod + * the resulting compiled method + */ + public static void record(byte compiler, VM_NativeMethod method, + VM_CompiledMethod compiledMethod) { + + recordCompilation(compiler, 0, // don't have any bytecode info, its native + compiledMethod.numberOfInstructions(), compiledMethod + .getCompilationTime()); + } + + /** + * This method does the actual recording + * + * @param compiler + * the compiler used + * @param BCLength + * the number of bytecodes in method source + * @param MCLength + * the length of the generated machine code + * @param compTime + * the compilation time in ms + */ + private static void recordCompilation(byte compiler, int BCLength, + int MCLength, double compTime) { + + totalMethods[compiler]++; + totalMCLength[compiler] += MCLength; + totalCompTime[compiler] += compTime; + + // Comp rate not useful for JNI compiler because there is no bytecode! + if (compiler != JNI_COMPILER) { + totalBCLength[compiler] += BCLength; + double rate = BCLength / compTime; + + // need to be fully booted before calling log + if (VM.fullyBooted) { + // we want the geometric mean, but the product of rates is too big + // for doubles, so we use the principle of logs to help us + // We compute e ** ((log a + log b + ... + log n) / n ) + totalLogOfRates[compiler] += Math.log(rate); + totalLogValueMethods[compiler]++; + } + } + } + + /** + * This method produces a summary report of compilation activities + * + * @param explain + * Explains the metrics used in the report + */ + public static void report(boolean explain) { + VM.sysWrite("\n\t\tCompilation Subsystem Report\n"); + VM.sysWrite("Comp\t#Meths\tTime\tbcb/ms\tmcb/bcb\tMCKB\tBCKB\n"); + for (int i = 0; i <= name.length - 1; i++) { + if (totalMethods[i] > 0) { + VM.sysWrite(name[i]); + // Number of methods + VM.sysWrite(totalMethods[i]); + VM.sysWrite("\t"); + // Compilation time + VM.sysWrite(totalCompTime[i]); + VM.sysWrite("\t"); + + if (i == JNI_COMPILER) { + VM.sysWrite("NA"); + } else { + // Bytecode bytes per millisecond, + // use unweighted geomean + VM + .sysWrite(Math.exp(totalLogOfRates[i] / totalLogValueMethods[i]), + 2); + } + VM.sysWrite("\t"); + // Ratio of machine code bytes to bytecode bytes + if (i != JNI_COMPILER) { + VM + .sysWrite( + (double) (totalMCLength[i] << ArchitectureSpecific.VM_RegisterConstants.LG_INSTRUCTION_WIDTH) + / (double) totalBCLength[i], 2); + } else { + VM.sysWrite("NA"); + } + VM.sysWrite("\t"); + // Generated machine code Kbytes + VM + .sysWrite( + (double) (totalMCLength[i] << ArchitectureSpecific.VM_RegisterConstants.LG_INSTRUCTION_WIDTH) / 1024, + 1); + VM.sysWrite("\t"); + // Compiled bytecode Kbytes + if (i != JNI_COMPILER) { + VM.sysWrite((double) totalBCLength[i] / 1024, 1); + } else { + VM.sysWrite("NA"); + } + VM.sysWrite("\n"); + } + } + if (explain) { + // Generate an explanation of the metrics reported + VM.sysWrite("\t\t\tExplanation of Metrics\n"); + VM + .sysWrite("#Meths:\t\tTotal number of methods compiled by the compiler\n"); + VM.sysWrite("Time:\t\tTotal compilation time in milliseconds\n"); + VM + .sysWrite("bcb/ms:\t\tNumber of bytecode bytes complied per millisecond\n"); + VM.sysWrite("mcb/bcb:\tRatio of machine code bytes to bytecode bytes\n"); + VM + .sysWrite("MCKB:\t\tTotal number of machine code bytes generated in kilobytes\n"); + VM + .sysWrite("BCKB:\t\tTotal number of bytecode bytes compiled in kilobytes\n"); + } + + VM_BaselineCompiler.generateBaselineCompilerSubsystemReport(explain); + + if (VM.BuildForAdaptiveSystem) { + // Get the opt's report + VM_TypeReference theTypeRef = VM_TypeReference + .findOrCreate( + VM_BootstrapClassLoader.getBootstrapClassLoader(), + VM_Atom + .findOrCreateAsciiAtom("Lorg/jikesrvm/opt/OPT_OptimizationPlanner;")); + VM_Type theType = theTypeRef.peekResolvedType(); + if (theType != null && theType.asClass().isInitialized()) { + OPT_OptimizationPlanner + .generateOptimizingCompilerSubsystemReport(explain); + } else { + VM + .sysWrite("\n\tNot generating Optimizing Compiler SubSystem Report because \n"); + VM.sysWrite("\tthe opt compiler was never invoked.\n\n"); + } + } + } + + /** + * Return the current estimate of basline-compiler rate, in bcb/msec + */ + public static double getBaselineRate() { + return Math.exp(totalLogOfRates[BASELINE_COMPILER] + / totalLogValueMethods[BASELINE_COMPILER]); + } + + /** + * This method will compile the passed method using the baseline compiler. + * + * @param method + * the method to compile + */ + public static VM_CompiledMethod baselineCompile(VM_NormalMethod method) { + VM_Callbacks.notifyMethodCompile(method, VM_CompiledMethod.BASELINE); + long start = 0; + if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { + start = VM_Thread.getCurrentThread().accumulateCycles(); + } + + VM_CompiledMethod cm = VM_BaselineCompiler.compile(method); + + if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { + long end = VM_Thread.getCurrentThread().accumulateCycles(); + double compileTime = VM_Time.cyclesToMillis(end - start); + cm.setCompilationTime(compileTime); + record(BASELINE_COMPILER, method, cm); + } + + return cm; + } + + /** + * Process command line argument destined for the opt compiler + */ + public static void processOptCommandLineArg(String prefix, String arg) { + if (VM.BuildForAdaptiveSystem) { + if (compilerEnabled) { + if (((OPT_Options) options).processAsOption(prefix, arg)) { + // update the optimization plan to reflect the new command line + // argument + optimizationPlan = OPT_OptimizationPlanner + .createOptimizationPlan((OPT_Options) options); + } else { + VM.sysWrite("Unrecognized opt compiler argument \"" + arg + "\""); + VM.sysExit(VM.EXIT_STATUS_BOGUS_COMMAND_LINE_ARG); + } + } else { + String[] tmp = new String[earlyOptArgs.length + 2]; + for (int i = 0; i < earlyOptArgs.length; i++) { + tmp[i] = earlyOptArgs[i]; + } + earlyOptArgs = tmp; + earlyOptArgs[earlyOptArgs.length - 2] = prefix; + earlyOptArgs[earlyOptArgs.length - 1] = arg; + } + } else { + if (VM.VerifyAssertions) + VM._assert(NOT_REACHED); + } + } + + /** + * attempt to compile the passed method with the OPT_Compiler. Don't handle + * OPT_OptimizingCompilerExceptions (leave it up to caller to decide what to + * do) Precondition: compilationInProgress "lock" has been acquired + * + * @param method + * the method to compile + * @param plan + * the plan to use for compiling the method + */ + private static VM_CompiledMethod optCompile(VM_NormalMethod method, + OPT_CompilationPlan plan) throws OPT_OptimizingCompilerException { + if (VM.BuildForOptCompiler) { + if (VM.VerifyAssertions) { + VM._assert(compilationInProgress, + "Failed to acquire compilationInProgress \"lock\""); + } + + VM_Callbacks.notifyMethodCompile(method, VM_CompiledMethod.JNI); + long start = 0; + if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { + start = VM_Thread.getCurrentThread().accumulateCycles(); + } + + VM_CompiledMethod cm = OPT_Compiler.compile(plan); + + if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { + long end = VM_Thread.getCurrentThread().accumulateCycles(); + double compileTime = VM_Time.cyclesToMillis(end - start); + cm.setCompilationTime(compileTime); + record(OPT_COMPILER, method, cm); + } + + return cm; + } else { + if (VM.VerifyAssertions) + VM._assert(false); + return null; + } + } + + // These methods are safe to invoke from VM_RuntimeCompiler.compile + + /** + * This method tries to compile the passed method with the OPT_Compiler, using + * the default compilation plan. If this fails we will use the quicker + * compiler (baseline for now) The following is carefully crafted to avoid + * (infinte) recursive opt compilation for all combinations of bootimages & + * lazy/eager compilation. Be absolutely sure you know what you're doing + * before changing it !!! + * + * @param method + * the method to compile + */ + public static synchronized VM_CompiledMethod optCompileWithFallBack( + VM_NormalMethod method) { + if (VM.BuildForOptCompiler) { + if (compilationInProgress) { + return fallback(method); + } else { + try { + compilationInProgress = true; + OPT_CompilationPlan plan = new OPT_CompilationPlan(method, + (OPT_OptimizationPlanElement[]) optimizationPlan, null, + (OPT_Options) options); + return optCompileWithFallBackInternal(method, plan); + } finally { + compilationInProgress = false; + } + } + } else { + if (VM.VerifyAssertions) + VM._assert(false); + return null; + } + } + + /** + * This method tries to compile the passed method with the OPT_Compiler with + * the passed compilation plan. If this fails we will use the quicker compiler + * (baseline for now) The following is carefully crafted to avoid (infinte) + * recursive opt compilation for all combinations of bootimages & lazy/eager + * compilation. Be absolutely sure you know what you're doing before changing + * it !!! + * + * @param method + * the method to compile + * @param plan + * the compilation plan to use for the compile + */ + public static synchronized VM_CompiledMethod optCompileWithFallBack( + VM_NormalMethod method, OPT_CompilationPlan plan) { + if (VM.BuildForOptCompiler) { + if (compilationInProgress) { + return fallback(method); + } else { + try { + compilationInProgress = true; + return optCompileWithFallBackInternal(method, plan); + } finally { + compilationInProgress = false; + } + } + } else { + if (VM.VerifyAssertions) + VM._assert(false); + return null; + } + } + + /** + * This real method that performs the opt compilation. + * + * @param method + * the method to compile + * @param plan + * the compilation plan to use + */ + private static VM_CompiledMethod optCompileWithFallBackInternal( + VM_NormalMethod method, OPT_CompilationPlan plan) { + if (VM.BuildForOptCompiler) { + if (method.hasNoOptCompileAnnotation()) + return fallback(method); + try { + return optCompile(method, plan); + } catch (OPT_OptimizingCompilerException e) { + String msg = "VM_RuntimeCompiler: can't optimize \"" + method + + "\" (error was: " + e + "): reverting to baseline compiler\n"; + if (e.isFatal && VM.ErrorsFatal) { + e.printStackTrace(); + VM.sysFail(msg); + } else { + boolean printMsg = true; + if (e instanceof OPT_MagicNotImplementedException) { + printMsg = !((OPT_MagicNotImplementedException) e).isExpected; + } + if (printMsg) + VM.sysWrite(msg); + } + return fallback(method); + } + } else { + if (VM.VerifyAssertions) + VM._assert(false); + return null; + } + } + + /* recompile the specialized method with OPT_Compiler. */ + public static VM_CompiledMethod recompileWithOptOnStackSpecialization( + OPT_CompilationPlan plan) { + if (VM.BuildForOptCompiler) { + if (VM.VerifyAssertions) { + VM._assert(plan.method.isForOsrSpecialization()); + } + if (compilationInProgress) { + return null; + } + + try { + compilationInProgress = true; + + // the compiler will check if isForOsrSpecialization of the method + VM_CompiledMethod cm = optCompile(plan.method, plan); + + // we donot replace the compiledMethod of original method, + // because it is temporary method + return cm; + } catch (OPT_OptimizingCompilerException e) { + e.printStackTrace(); + String msg = "Optimizing compiler " + + "(via recompileWithOptOnStackSpecialization): " + + "can't optimize \"" + plan.method + "\" (error was: " + e + ")\n"; + + if (e.isFatal && VM.ErrorsFatal) { + VM.sysFail(msg); + } else { + VM.sysWrite(msg); + } + return null; + } finally { + compilationInProgress = false; + } + } else { + if (VM.VerifyAssertions) + VM._assert(false); + return null; + } + } + + /** + * This method tries to compile the passed method with the OPT_Compiler. It + * will install the new compiled method in the VM, if sucessful. NOTE: the + * recompile method should never be invoked via VM_RuntimeCompiler.compile; it + * does not have sufficient guards against recursive recompilation. + * + * @param plan + * the compilation plan to use + * @return the CMID of the new method if successful, -1 if the recompilation + * failed. + * + */ + public static synchronized int recompileWithOpt(OPT_CompilationPlan plan) { + if (VM.BuildForOptCompiler) { + if (compilationInProgress) { + return -1; + } else { + try { + compilationInProgress = true; + VM_CompiledMethod cm = optCompile(plan.method, plan); + try { + plan.method.replaceCompiledMethod(cm); + } catch (Throwable e) { + String msg = "Failure in VM_Method.replaceCompiledMethod (via recompileWithOpt): while replacing \"" + + plan.method + "\" (error was: " + e + ")\n"; + if (VM.ErrorsFatal) { + e.printStackTrace(); + VM.sysFail(msg); + } else { + VM.sysWrite(msg); + } + return -1; + } + return cm.getId(); + } catch (OPT_OptimizingCompilerException e) { + String msg = "Optimizing compiler (via recompileWithOpt): can't optimize \"" + + plan.method + "\" (error was: " + e + ")\n"; + if (e.isFatal && VM.ErrorsFatal) { + e.printStackTrace(); + VM.sysFail(msg); + } else { + // VM.sysWrite(msg); + } + return -1; + } finally { + compilationInProgress = false; + } + } + } else { + if (VM.VerifyAssertions) + VM._assert(false); + return -1; + } + } + + /** + * A wrapper method for those callers who don't want to make optimization + * plans + * + * @param method + * the method to recompile + */ + public static int recompileWithOpt(VM_NormalMethod method) { + if (VM.BuildForOptCompiler) { + OPT_CompilationPlan plan = new OPT_CompilationPlan(method, + (OPT_OptimizationPlanElement[]) optimizationPlan, null, + (OPT_Options) options); + return recompileWithOpt(plan); + } else { + if (VM.VerifyAssertions) + VM._assert(false); + return -1; + } + } + + /** + * This method uses the default compiler (baseline) to compile a method It is + * typically called when a more aggressive compilation fails. This method is + * safe to invoke from VM_RuntimeCompiler.compile + */ + protected static VM_CompiledMethod fallback(VM_NormalMethod method) { + // call the inherited method "baselineCompile" + return baselineCompile(method); + } + + public static void boot() { + if (VM.MeasureCompilation) { + VM_Callbacks.addExitMonitor(new VM_RuntimeCompiler()); + } + if (VM.BuildForAdaptiveSystem) { + options = new OPT_Options(); + optimizationPlan = OPT_OptimizationPlanner + .createOptimizationPlan((OPT_Options) options); + if (VM.MeasureCompilation) { + OPT_OptimizationPlanner.initializeMeasureCompilation(); + } + + OPT_Compiler.init((OPT_Options) options); + + VM_PreCompile.init(); + // when we reach here the OPT compiler is enabled. + compilerEnabled = true; + + for (int i = 0; i < earlyOptArgs.length; i += 2) { + processOptCommandLineArg(earlyOptArgs[i], earlyOptArgs[i + 1]); + } + } + } + + public static void processCommandLineArg(String prefix, String arg) { + if (VM.BuildForAdaptiveSystem) { + if (VM_Controller.options != null && VM_Controller.options.optIRC()) { + processOptCommandLineArg(prefix, arg); + } else { + VM_BaselineCompiler.processCommandLineArg(prefix, arg); + } + } else { + VM_BaselineCompiler.processCommandLineArg(prefix, arg); + } + } + + /** + * Compile a Java method when it is first invoked. + * + * @param method + * the method to compile + * @return its compiled method. + */ + public static VM_CompiledMethod compile(VM_NormalMethod method) { + if (VM.BuildForAdaptiveSystem) { + VM_CompiledMethod cm; + if (!VM_Controller.enabled) { + // System still early in boot process; compile with baseline compiler + cm = baselineCompile(method); + VM_ControllerMemory.incrementNumBase(); + } else { + if (!preloadChecked) { + preloadChecked = true; // prevent subsequent calls + // N.B. This will use irc options + if (VM_BaselineCompiler.options.PRELOAD_CLASS != null) { + compilationInProgress = true; // use baseline during preload + // Other than when boot options are requested (processed during + // preloadSpecialClass + // It is hard to communicate options for these special compilations. + // Use the + // default options and at least pick up the verbose if requested for + // base/irc + OPT_Options tmpoptions = (OPT_Options) ((OPT_Options) options) + .clone(); + tmpoptions.PRELOAD_CLASS = VM_BaselineCompiler.options.PRELOAD_CLASS; + tmpoptions.PRELOAD_AS_BOOT = VM_BaselineCompiler.options.PRELOAD_AS_BOOT; + if (VM_BaselineCompiler.options.PRINT_METHOD) { + tmpoptions.PRINT_METHOD = true; + } else { + tmpoptions = (OPT_Options) options; + } + OPT_Compiler.preloadSpecialClass(tmpoptions); + compilationInProgress = false; + } + } + if (VM_Controller.options.optIRC() || method.optCompileOnly()) { + if (// will only run once: don't bother optimizing + method.isClassInitializer() || + // exception in progress. can't use opt compiler: + // it uses exceptions and runtime doesn't support + // multiple pending (undelivered) exceptions [--DL] + VM_Thread.getCurrentThread().hardwareExceptionRegisters.inuse) { + // compile with baseline compiler + cm = baselineCompile(method); + VM_ControllerMemory.incrementNumBase(); + } else { // compile with opt compiler + VM_AOSInstrumentationPlan instrumentationPlan = new VM_AOSInstrumentationPlan( + VM_Controller.options, method); + OPT_CompilationPlan compPlan = new OPT_CompilationPlan(method, + (OPT_OptimizationPlanElement[]) optimizationPlan, + instrumentationPlan, (OPT_Options) options); + if (!method.optCompileOnly()) { + cm = optCompileWithFallBack(method, compPlan); + } else { + compilationInProgress = true; + try { + cm = optCompile(method, compPlan); + } catch (OPT_OptimizingCompilerException e) { + String msg = "Optimizing compiler " + + "(on method that can only be optimizing compiler compiled): " + + "can't optimize \"" + method + "\""; + throw new Error(msg, e); + } finally { + compilationInProgress = false; + } + } + } + } else { + if ((VM_Controller.options.BACKGROUND_RECOMPILATION + && (!VM_Controller.options.ENABLE_REPLAY_COMPILE) && (!VM_Controller.options.ENABLE_PRECOMPILE))) { + // must be an inital compilation: compile with baseline compiler + // or if recompilation with OSR. + cm = baselineCompile(method); + VM_ControllerMemory.incrementNumBase(); + } else { + if (VM_CompilerAdviceAttribute.hasAdvice()) { + VM_CompilerAdviceAttribute attr = VM_CompilerAdviceAttribute + .getCompilerAdviceInfo(method); + if (attr.getCompiler() != VM_CompiledMethod.OPT) { + cm = fallback(method); + VM_AOSLogging.recordCompileTime(cm, 0.0); + return cm; + } + int newCMID = -2; + OPT_CompilationPlan compPlan; + if (VM_Controller.options.counters()) { + // for invocation counter, we only use one optimization level + compPlan = VM_InvocationCounts.createCompilationPlan(method); + } else { + // for now there is not two options for sampling, so + // we don't have to use: if (VM_Controller.options.sampling()) + compPlan = VM_Controller.recompilationStrategy + .createCompilationPlan(method, attr.getOptLevel(), null); + } + VM_AOSLogging.recompilationStarted(compPlan); + newCMID = recompileWithOpt(compPlan); + cm = newCMID == -1 ? null : VM_CompiledMethods + .getCompiledMethod(newCMID); + if (newCMID == -1) { + VM_AOSLogging.recompilationAborted(compPlan); + } else if (newCMID > 0) { + VM_AOSLogging.recompilationCompleted(compPlan); + } + if (cm == null) { // if recompilation is aborted + cm = baselineCompile(method); + VM_ControllerMemory.incrementNumBase(); + } + } else { + // check to see if there is a compilation plan for this method. + VM_ControllerPlan plan = VM_ControllerMemory + .findLatestPlan(method); + if (plan == null + || plan.getStatus() != VM_ControllerPlan.IN_PROGRESS) { + // initial compilation or some other funny state: compile with + // baseline compiler + cm = baselineCompile(method); + VM_ControllerMemory.incrementNumBase(); + } else { + cm = plan.doRecompile(); + if (cm == null) { + // opt compilation aborted for some reason. + cm = baselineCompile(method); + } + } + } + } + } + } + if ((VM_Controller.options.ENABLE_ADVICE_GENERATION) + && (cm.getCompilerType() == VM_CompiledMethod.BASELINE) + && VM_Controller.enabled) { + VM_AOSGenerator.baseCompilationCompleted(cm); + } + VM_AOSLogging.recordCompileTime(cm, 0.0); + return cm; + } else { + return baselineCompile(method); + } + } + + /** + * Compile the stub for a native method when it is first invoked. + * + * @param method + * the method to compile + * @return its compiled method. + */ + public static VM_CompiledMethod compile(VM_NativeMethod method) { + VM_Callbacks.notifyMethodCompile(method, VM_CompiledMethod.JNI); + long start = 0; + if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { + start = VM_Thread.getCurrentThread().accumulateCycles(); + } + + VM_CompiledMethod cm = VM_JNICompiler.compile(method); + if (VM.verboseJNI) { + VM.sysWriteln("[Dynamic-linking native method " + + method.getDeclaringClass() + "." + method.getName() + " " + + method.getDescriptor()); + } + + if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { + long end = VM_Thread.getCurrentThread().accumulateCycles(); + double compileTime = VM_Time.cyclesToMillis(end - start); + cm.setCompilationTime(compileTime); + record(JNI_COMPILER, method, cm); + } + + return cm; + } + + /** + * returns the string version of compiler number, using the naming scheme in + * this file + * + * @param compiler + * the compiler of interest + * @return the string version of compiler number + */ + public static String getCompilerName(byte compiler) { + return name[compiler]; + } + +} Copied: ext/org/jikesrvm/compilers/opt (from rev 16, ext/org/jikesrvm/opt) Modified: ext/org/jikesrvm/compilers/opt/OPT_Simplifier.java =================================================================== --- ext/org/jikesrvm/opt/OPT_Simplifier.java 2007-03-31 14:04:36 UTC (rev 16) +++ ext/org/jikesrvm/compilers/opt/OPT_Simplifier.java 2007-04-02 12:11:23 UTC (rev 19) @@ -6,130 +6,138 @@ * * (C) Copyright IBM Corp. 2001 */ -package org.jikesrvm.opt; +package org.jikesrvm.compilers.opt; import org.jikesrvm.classloader.*; +import org.jikesrvm.compilers.opt.ir.*; +import org.jikesrvm.objectmodel.VM_TIBLayoutConstants; import org.jikesrvm.VM; -import org.jikesrvm.VM_TIBLayoutConstants; -import org.jikesrvm.opt.ir.*; import org.vmmagic.unboxed.*; import java.lang.reflect.Array; import static org.jikesrvm.VM_SizeConstants.*; -import static org.jikesrvm.opt.ir.OPT_Operators.*; +import static org.jikesrvm.compilers.opt.ir.OPT_Operators.*; + /** - * A constant folder, strength reducer and axiomatic simplifier. - * - * <p> This module performs no analysis, it simply attempts to - * simplify the instruction as is. The intent is that - * analysis modules can call this transformation engine, allowing us to - * share the tedious simplification code among multiple analysis modules. - * - * <p> NOTE: For maintainability purposes, I've intentionally avoided being - * clever about combining 'similar' operators together into a combined case - * of the main switch switch statement. Also, operators are in sorted ordered - * within each major grouping. Please maintain this coding style. - * I'd rather have this module be 2000 lines of obviously correct code than - * 500 lines of clever code. - * + * A constant folder, strength reducer and axiomatic simplifier. + * + * <p> + * This module performs no analysis, it simply attempts to simplify the + * instruction as is. The intent is that analysis modules can call this + * transformation engine, allowing us to share the tedious simplification code + * among multiple analysis modules. + * + * <p> + * NOTE: For maintainability purposes, I've intentionally avoided being clever + * about combining 'similar' operators together into a combined case of the main + * switch switch statement. Also, operators are in sorted ordered within each + * major grouping. Please maintain this coding style. I'd rather have this + * module be 2000 lines of obviously correct code than 500 lines of clever code. + * * @author Dave Grove * @author Ian Rogers */ public abstract class OPT_Simplifier extends OPT_IRTools { // NOTE: The convention is that constant folding is controlled based // on the type of the result of the operator, not the type of its inputs. - /** + /** * Constant fold integer operations? */ public static final boolean CF_INT = true; - /** + + /** * Constant fold address operations? */ public static final boolean CF_LONG = true; - /** + /** * Constant fold address operations? */ public static final boolean CF_ADDR = true; - /** - * Constant fold float operations? Default is true, flip to avoid - * consuming precious JTOC slots to hold new constant values. + /** + * Constant fold float operations? Default is true, flip to avoid consuming + * precious JTOC slots to hold new constant values. */ public static final boolean CF_FLOAT = true; - /** - * Constant fold double operations? Default is true, flip to avoid - * consuming precious JTOC slots to hold new constant values. + + /** + * Constant fold double operations? Default is true, flip to avoid consuming + * precious JTOC slots to hold new constant values. */ public static final boolean CF_DOUBLE = true; - /** - * Constant fold field operations? Default is true, flip to avoid - * consuming precious JTOC slots to hold new constant values. + + /** + * Constant fold field operations? Default is true, flip to avoid consuming + * precious JTOC slots to hold new constant values. */ public static final boolean CF_FIELDS = false; - /** - * Constant fold TIB operations? Default is true, flip to avoid - * consuming precious JTOC slots to hold new constant values. + /** + * Constant fold TIB operations? Default is true, flip to avoid consuming + * precious JTOC slots to hold new constant values. */ public static final boolean CF_TIB = false; /** * Effect of the simplification on Def-Use chains */ - public enum DefUseEffect{ + public enum DefUseEffect { /** - * Enumeration value to indicate an operation is unchanged, - * although the order of operands may have been canonicalized and - * type information strengthened. + * Enumeration value to indicate an operation is unchanged, although the + * order of operands may have been canonicalized and type information + * strengthened. */ UNCHANGED, /** - * Enumeration value to indicate an operation has been replaced by - * a move instruction with a constant right hand side. + * Enumeration value to indicate an operation has been replaced by a move + * instruction with a constant right hand side. */ MOVE_FOLDED, /** - * Enumeration value to indicate an operation has been replaced by - * a move instruction with a non-constant right hand side. + * Enumeration value to indicate an operation has been replaced by a move + * instruction with a non-constant right hand side. */ MOVE_REDUCED, /** - * Enumeration value to indicate an operation has been replaced by - * an unconditional trap instruction. + * Enumeration value to indicate an operation has been replaced by an + * unconditional trap instruction. */ TRAP_REDUCED, /** - * Enumeration value to indicate an operation has been replaced by - * a cheaper, but non-move instruction. + * Enumeration value to indicate an operation has been replaced by a + * cheaper, but non-move instruction. */ REDUCED - } + } /** - * Given an instruction, attempt to simplify it. - * The instruction will be mutated in place. - * - * <p> We don't deal with branching operations here -- - * doing peephole optimizations of branches - * is the job of a separate module. - * - * @param regpool register pool in case simplification requires a temporary register - * @param s the instruction to simplify + * Given an instruction, attempt to simplify it. The instruction will be + * mutated in place. + * + * <p> + * We don't deal with branching operations here -- doing peephole + * optimizations of branches is the job of a separate module. + * + * @param regpool + * register pool in case simplification requires a temporary register + * @param s + * the instruction to simplify * @return one of UNCHANGED, MOVE_FOLDED, MOVE_REDUCED, TRAP_REDUCED, REDUCED */ - public static DefUseEffect simplify(OPT_AbstractRegisterPool regpool, OPT_Instruction s) { + public static DefUseEffect simplify(OPT_AbstractRegisterPool regpool, + OPT_Instruction s) { DefUseEffect result; char opcode = s.getOpcode(); switch (opcode) { - //////////////////// - // GUARD operations - //////////////////// + // ////////////////// + // GUARD operations + // ////////////////// case GUARD_COMBINE_opcode: result = guardCombine(s); break; - //////////////////// - // TRAP operations - //////////////////// + // ////////////////// + // TRAP operations + // ////////////////// case TRAP_IF_opcode: result = trapIf(s); break; @@ -166,9 +174,9 @@ case MUST_IMPLEMENT_INTERFACE_opcode: result = mustImplementInterface(s); break; - //////////////////// - // Conditional moves - //////////////////// + // ////////////////// + // Conditional moves + // ////////////////// case INT_COND_MOVE_opcode: result = intCondMove(s); break; @@ -187,9 +195,9 @@ case GUARD_COND_MOVE_opcode: result = guardCondMove(s); break; - //////////////////// - // INT ALU operations - //////////////////// + // ////////////////// + // INT ALU operations + // ////////////////// case BOOLEAN_NOT_opcode: result = booleanNot(s); break; @@ -202,9 +210,9 @@ case BOOLEAN_CMP2_INT_OR_opcode: result = booleanCmp2IntOr(s); break; - //case BOOLEAN_CMP2_INT_AND: - //result = booleanCmp2IntAnd(s); - //break; + // case BOOLEAN_CMP2_INT_AND: + // result = booleanCmp2IntAnd(s); + // break; case INT_ADD_opcode: result = intAdd(s); break; @@ -244,9 +252,9 @@ case INT_XOR_opcode: result = intXor(s); break; - //////////////////// - // WORD ALU operations - //////////////////// + // ////////////////// + // WORD ALU operations + // ////////////////// case REF_ADD_opcode: result = refAdd(s); break; @@ -274,9 +282,9 @@ case REF_XOR_opcode: result = refXor(s); break; - //////////////////// - // LONG ALU operations - //////////////////// + // ////////////////// + // LONG ALU operations + // ////////////////// case LONG_ADD_opcode: result = longAdd(s); break; @@ -319,9 +327,9 @@ case LONG_XOR_opcode: result = longXor(s); break; - //////////////////// - // FLOAT ALU operations - //////////////////// + // ////////////////// + // FLOAT ALU operations + // ////////////////// case FLOAT_ADD_opcode: result = floatAdd(s); break; @@ -346,9 +354,9 @@ case FLOAT_SUB_opcode: result = floatSub(s); break; - //////////////////// - // DOUBLE ALU operations - //////////////////// + // ////////////////// + // DOUBLE ALU operations + // ////////////////// case DOUBLE_ADD_opcode: result = doubleAdd(s); break; @@ -373,9 +381,9 @@ case DOUBLE_SUB_opcode: result = doubleSub(s); break; - //////////////////// - // CONVERSION operations - //////////////////// + // ////////////////// + // CONVERSION operations + // ////////////////// case DOUBLE_2FLOAT_opcode: result = double2Float(s); break; @@ -448,9 +456,9 @@ case LONG_BITS_AS_DOUBLE_opcode: result = longBitsAsDouble(s); break; - //////////////////// - // Field operations - //////////////////// + // ////////////////// + // Field operations + // ////////////////// case ARRAYLENGTH_opcode: result = arrayLength(s); break; @@ -488,28 +496,28 @@ result = DefUseEffect.UNCHANGED; } if (VM.VerifyAssertions) { - switch (result) { - case MOVE_FOLDED: - // Check move has constant RHS - VM._assert(Move.conforms(s) && - (Move.getVal(s) instanceof OPT_ConstantOperand), - "RHS of move " + s + " should be constant during simplification of " - + OPT_OperatorNames.operatorName[opcode]); - break; - case MOVE_REDUCED: - // Check move has non-constant RHS - VM._assert(Move.conforms(s) && - !(Move.getVal(s) instanceof OPT_ConstantOperand), - "RHS of move " + s + " shouldn't be constant during simplification of " - + OPT_OperatorNames.operatorName[opcode]); - break; - default: - // Nothing to check - } + switch (result) { + case MOVE_FOLDED: + // Check move has constant RHS + VM._assert(Move.conforms(s) + && (Move.getVal(s) instanceof OPT_ConstantOperand), "RHS of move " + + s + " should be constant during simplification of " + + OPT_OperatorNames.operatorName[opcode]); + break; + case MOVE_REDUCED: + // Check move has non-constant RHS + VM._assert(Move.conforms(s) + && !(Move.getVal(s) instanceof OPT_ConstantOperand), "RHS of move " + + s + " shouldn't be constant during simplification of " + + OPT_OperatorNames.operatorName[opcode]); + break; + default: + // Nothing to check + } } return result; } - + private static DefUseEffect guardCombine(OPT_Instruction s) { OPT_Operand op1 = Binary.getVal1(s); OPT_Operand op2 = Binary.getVal2(s); @@ -522,26 +530,25 @@ // ONLY OP2 IS TrueGuard: MOVE REDUCE return DefUseEffect.MOVE_REDUCED; } - } - else if(op1 instanceof OPT_TrueGuardOperand) { + } else if (op1 instanceof OPT_TrueGuardOperand) { // ONLY OP1 IS TrueGuard: MOVE REDUCE Move.mutate(s, GUARD_MOVE, Binary.getClearResult(s), op2); return DefUseEffect.MOVE_REDUCED; - } - else { + } else { return DefUseEffect.UNCHANGED; } } + private static DefUseEffect trapIf(OPT_Instruction s) { - { + { OPT_Operand op1 = TrapIf.getVal1(s); OPT_Operand op2 = TrapIf.getVal2(s); if (op1.isConstant()) { if (op2.isConstant()) { int willTrap = TrapIf.getCond(s).evaluate(op1, op2); if (willTrap == OPT_ConditionOperand.TRUE) { - Trap.mutate(s, TRAP, TrapIf.getClearGuardResult(s), - TrapIf.getClearTCode(s)); + Trap.mutate(s, TRAP, TrapIf.getClearGuardResult(s), TrapIf + .getClearTCode(s)); return DefUseEffect.TRAP_REDUCED; } else if (willTrap == OPT_ConditionOperand.FALSE) { Move.mutate(s, GUARD_MOVE, TrapIf.getClearGuardResult(s), TG()); @@ -549,44 +556,43 @@ } } else { // canonicalize - TrapIf.mutate(s, TRAP_IF, TrapIf.getClearGuardResult(s), - TrapIf.getClearVal2(s), - TrapIf.getClearVal1(s), - TrapIf.getClearCond(s).flipOperands(), - TrapIf.getClearTCode(s)); + TrapIf.mutate(s, TRAP_IF, TrapIf.getClearGuardResult(s), TrapIf + .getClearVal2(s), TrapIf.getClearVal1(s), TrapIf.getClearCond(s) + .flipOperands(), TrapIf.getClearTCode(s)); } } - } + } return DefUseEffect.UNCHANGED; } + private static DefUseEffect nullCheck(OPT_Instruction s) { - OPT_Operand ref = NullCheck.getRef(s); - if (ref.isNullConstant() || - (ref.isAddressConstant() && ref.asAddressConstant().value.isZero())) { - Trap.mutate(s, TRAP, NullCheck.getClearGuardResult(s), - OPT_TrapCodeOperand.NullPtr()); - return DefUseEffect.TRAP_REDUCED; - } else if (ref.isConstant()) { - // object, string, class or non-null address constant - - // Make the slightly suspect assumption that all non-zero address - // constants are actually valid pointers. Not necessarily true, - // but unclear what else we can do. - Move.mutate(s, GUARD_MOVE, NullCheck.getClearGuardResult(s), TG()); - return DefUseEffect.MOVE_FOLDED; - } - else { - return DefUseEffect.UNCHANGED; - } + OPT_Operand ref = NullCheck.getRef(s); + if (ref.isNullConstant() + || (ref.isAddressConstant() && ref.asAddressConstant().value.isZero())) { + Trap.mutate(s, TRAP, NullCheck.getClearGuardResult(s), + OPT_TrapCodeOperand.NullPtr()); + return DefUseEffect.TRAP_REDUCED; + } else if (ref.isConstant()) { + // object, string, class or non-null address constant + + // Make the slightly suspect assumption that all non-zero address + // constants are actually valid pointers. Not necessarily true, + // but unclear what else we can do. + Move.mutate(s, GUARD_MOVE, NullCheck.getClearGuardResult(s), TG()); + return DefUseEffect.MOVE_FOLDED; + } else { + return DefUseEffect.UNCHANGED; + } } + private static DefUseEffect intZeroCheck(OPT_Instruction s) { - { + { OPT_Operand op = ZeroCheck.getValue(s); if (op.isIntConstant()) { int val = op.asIntConstant().value; if (val == 0) { Trap.mutate(s, TRAP, ZeroCheck.getClearGuardResult(s), - OPT_TrapCodeOperand.DivByZero()); + OPT_TrapCodeOperand.DivByZero()); return DefUseEffect.TRAP_REDUCED; } else { Move.mutate(s, GUARD_MOVE, ZeroCheck.getClearGuardResult(s), TG()); @@ -596,14 +602,15 @@ } return DefUseEffect.UNCHANGED; } + private static DefUseEffect longZeroCheck(OPT_Instruction s) { - { + { OPT_Operand op = ZeroCheck.getValue(s); if (op.isLongConstant()) { long val = op.asLongConstant().value; if (val == 0L) { Trap.mutate(s, TRAP, ZeroCheck.getClearGuardResult(s), - OPT_TrapCodeOperand.DivByZero()); + OPT_TrapCodeOperand.DivByZero()); return DefUseEffect.TRAP_REDUCED; } else { Move.mutate(s, GUARD_MOVE, ZeroCheck.getClearGuardResult(s), TG()); @@ -613,7 +620,9 @@ } return DefUseEffect.UNCHANGED; } - private static DefUseEffect checkcast(OPT_AbstractRegisterPool regpool, OPT_Instruction s) { + + private static DefUseEffect checkcast(OPT_AbstractRegisterPool regpool, + OPT_Instruction s) { OPT_Operand ref = TypeCheck.getRef(s); if (ref.isNullConstant()) { Empty.mutate(s, NOP); @@ -634,6 +643,7 @@ } } } + private static DefUseEffect checkcastNotNull(OPT_Instruction s) { OPT_Operand ref = TypeCheck.getRef(s); VM_TypeReference lhsType = TypeCheck.getType(s).getTypeRef(); @@ -645,18 +655,20 @@ } else if (ans == OPT_Constants.NO) { VM_Type rType = rhsType.peekResolvedType(); if (rType != null && rType.isClassType() && rType.asClass().isFinal()) { - // only final (or precise) rhs types can be optimized since rhsType may be conservative + // only final (or precise) rhs types can be optimized since rhsType may + // be conservative Trap.mutate(s, TRAP, null, OPT_TrapCodeOperand.CheckCast()); return DefUseEffect.TRAP_REDUCED; } else { return DefUseEffect.UNCHANGED; } - } - else { + } else { return DefUseEffect.UNCHANGED; } } - private static DefUseEffect instanceOf(OPT_AbstractRegisterPool regpool, OPT_Instruction s) { + + private static DefUseEffect instanceOf(OPT_AbstractRegisterPool regpool, + OPT_Instruction s) { OPT_Operand ref = InstanceOf.getRef(s); if (ref.isNullConstant()) { Move.mutate(s, INT_MOVE, InstanceOf.getClearResult(s), IC(0)); @@ -668,25 +680,26 @@ VM_TypeReference lhsType = InstanceOf.getType(s).getTypeRef(); VM_TypeReference rhsType = ref.getType(); byte ans = OPT_ClassLoaderProxy.includesType(lhsType, rhsType); - // NOTE: OPT_Constants.YES doesn't help because ref may be null and null instanceof T is false + // NOTE: OPT_Constants.YES doesn't help because ref may be null and null + // instanceof T is false if (ans == OPT_Constants.NO) { VM_Type rType = rhsType.peekResolvedType(); if (rType != null && rType.isClassType() && rType.asClass().isFinal()) { - // only final (or precise) rhs types can be optimized since rhsType may be conservative + // only final (or precise) rhs types can be optimized since rhsType + // may be conservative Move.mutate(s, INT_MOVE, InstanceOf.getClearResult(s), IC(0)); return DefUseEffect.MOVE_FOLDED; - } - else { + } else { return DefUseEffect.UNCHANGED; } - } - else { + } else { return DefUseEffect.UNCHANGED; } } } + private static DefUseEffect instanceOfNotNull(OPT_Instruction s) { - { + { OPT_Operand ref = InstanceOf.getRef(s); VM_TypeReference lhsType = InstanceOf.getType(s).getTypeRef(); VM_TypeReference rhsType = ref.getType(); @@ -697,7 +710,8 @@ } else if (ans == OPT_Constants.NO) { VM_Type rType = rhsType.peekResolvedType(); if (rType != null && rType.isClassType() && rType.asClass().isFinal()) { - // only final (or precise) rhs types can be optimized since rhsType may be conservative + // only final (or precise) rhs types can be optimized since rhsType + // may be conservative Move.mutate(s, INT_MOVE, InstanceOf.getClearResult(s), IC(0)); return DefUseEffect.MOVE_FOLDED; } @@ -705,103 +719,118 @@ } return DefUseEffect.UNCHANGED; } - private static DefUseEffect objarrayStoreCheck(OPT_Instruction s){ + + private static DefUseEffect objarrayStoreCheck(OPT_Instruction s) { OPT_Operand val = StoreCheck.getVal(s); if (val.isNullConstant()) { // Writing null into an array is trivially safe - Move.mutate(s, GUARD_MOVE, StoreCheck.getClearGuardResult(s), StoreCheck.getClearGuard(s)); + Move.mutate(s, GUARD_MOVE, StoreCheck.getClearGuardResult(s), StoreCheck + .getClearGuard(s)); return DefUseEffect.MOVE_REDUCED; - } - else { + } else { OPT_Operand ref = StoreCheck.getRef(s); VM_TypeReference arrayTypeRef = ref.getType(); - VM_Type typeOfIMElem = arrayTypeRef.getInnermostElementType().peekResolvedType(); + VM_Type typeOfIMElem = arrayTypeRef.getInnermostElementType() + .peekResolvedType(); if (typeOfIMElem != null) { VM_Type typeOfVal = val.getType().peekResolvedType(); - if ((typeOfIMElem == typeOfVal) && - (typeOfIMElem.isPrimitiveType() || - typeOfIMElem.asClass().isFinal())) { + if ((typeOfIMElem == typeOfVal) + && (typeOfIMElem.isPrimitiveType() || typeOfIMElem.asClass() + .isFinal())) { // Writing something of a final type to an array of that // final type is safe Move.mutate(s, GUARD_MOVE, StoreCheck.getClearGuardResult(s), - StoreCheck.getClearGuard(s)); + StoreCheck.getClearGu... [truncated message content] |
From: <mic...@us...> - 2007-04-01 12:27:50
|
Revision: 18 http://svn.sourceforge.net/pearcolator/?rev=18&view=rev Author: michael_baer Date: 2007-04-01 05:27:50 -0700 (Sun, 01 Apr 2007) Log Message: ----------- Changed Memory interface to enable loads and stores to constant memory addresses Modified Paths: -------------- src/org/binarytranslator/generic/memory/CallBasedMemory.java src/org/binarytranslator/generic/memory/Memory.java Modified: src/org/binarytranslator/generic/memory/CallBasedMemory.java =================================================================== --- src/org/binarytranslator/generic/memory/CallBasedMemory.java 2007-03-31 22:03:22 UTC (rev 17) +++ src/org/binarytranslator/generic/memory/CallBasedMemory.java 2007-04-01 12:27:50 UTC (rev 18) @@ -24,6 +24,7 @@ import org.jikesrvm.opt.ir.OPT_Instruction; import org.jikesrvm.opt.ir.OPT_LocationOperand; import org.jikesrvm.opt.ir.OPT_MethodOperand; +import org.jikesrvm.opt.ir.OPT_Operand; import org.jikesrvm.opt.ir.OPT_Operators; import org.jikesrvm.opt.ir.OPT_Register; import org.jikesrvm.opt.ir.OPT_RegisterOperand; @@ -185,7 +186,7 @@ * the address of the value to load */ private void translateLoad(VM_Method loadMethod, int bcIndex, - OPT_RegisterOperand addr, OPT_RegisterOperand dest) { + OPT_Operand addr, OPT_RegisterOperand dest) { OPT_Instruction s = Call.create(CALL, dest, null, null, null, 2); VM_MethodReference loadMethRef = loadMethod.getMemberRef() .asMethodReference(); @@ -212,7 +213,7 @@ * @param addr * the address of the value to load */ - public void translateLoadSigned8(OPT_RegisterOperand addr, + public void translateLoadSigned8(OPT_Operand addr, OPT_RegisterOperand dest) { translateLoad(loadS8, DBT_Trace.MEMORY_LOAD8, addr, dest); } @@ -226,7 +227,7 @@ * @param addr * the address of the value to load */ - public void translateLoadUnsigned8(OPT_RegisterOperand addr, + public void translateLoadUnsigned8(OPT_Operand addr, OPT_RegisterOperand dest) { translateLoad(loadU8, DBT_Trace.MEMORY_ULOAD8, addr, dest); } @@ -240,7 +241,7 @@ * @param addr * the address of the value to load */ - public void translateLoadSigned16(OPT_RegisterOperand addr, + public void translateLoadSigned16(OPT_Operand addr, OPT_RegisterOperand dest) { translateLoad(loadS16, DBT_Trace.MEMORY_LOAD16, addr, dest); } @@ -254,7 +255,7 @@ * @param addr * the address of the value to load */ - public void translateLoadUnsigned16(OPT_RegisterOperand addr, + public void translateLoadUnsigned16(OPT_Operand addr, OPT_RegisterOperand dest) { translateLoad(loadU16, DBT_Trace.MEMORY_ULOAD16, addr, dest); } @@ -267,7 +268,7 @@ * @param addr * the address of the value to load */ - public void translateLoad32(OPT_RegisterOperand addr, OPT_RegisterOperand dest) { + public void translateLoad32(OPT_Operand addr, OPT_RegisterOperand dest) { translateLoad(load32, DBT_Trace.MEMORY_LOAD32, addr, dest); } @@ -280,7 +281,7 @@ * @param addr * the address of the value to load */ - protected void translateCallBasedLoadSigned16(OPT_RegisterOperand addr, + protected void translateCallBasedLoadSigned16(OPT_Operand addr, OPT_RegisterOperand dest) { translateLoad(loadS16, DBT_Trace.MEMORY_LOAD16, addr, dest); } @@ -294,7 +295,7 @@ * @param addr * the address of the value to load */ - protected void translateCallBasedLoadUnsigned16(OPT_RegisterOperand addr, + protected void translateCallBasedLoadUnsigned16(OPT_Operand addr, OPT_RegisterOperand dest) { translateLoad(loadU16, DBT_Trace.MEMORY_ULOAD16, addr, dest); } @@ -307,7 +308,7 @@ * @param addr * the address of the value to load */ - protected void translateCallBasedLoad32(OPT_RegisterOperand addr, + protected void translateCallBasedLoad32(OPT_Operand addr, OPT_RegisterOperand dest) { translateLoad(load32, DBT_Trace.MEMORY_LOAD32, addr, dest); } @@ -326,7 +327,7 @@ * the address of the value to store */ private void translateStore(VM_Method storeMethod, int bcIndex, - OPT_RegisterOperand addr, OPT_RegisterOperand src) { + OPT_Operand addr, OPT_RegisterOperand src) { OPT_Instruction s = Call.create(CALL, null, null, null, null, 3); VM_MethodReference storeMethRef = storeMethod.getMemberRef() .asMethodReference(); @@ -352,7 +353,7 @@ * @param addr * the address of the value to store */ - public void translateStore8(OPT_RegisterOperand addr, OPT_RegisterOperand src) { + public void translateStore8(OPT_Operand addr, OPT_RegisterOperand src) { translateStore(store8, DBT_Trace.MEMORY_STORE8, addr, src); } @@ -364,7 +365,7 @@ * @param addr * the address of the value to store */ - public void translateStore16(OPT_RegisterOperand addr, OPT_RegisterOperand src) { + public void translateStore16(OPT_Operand addr, OPT_RegisterOperand src) { translateStore(store16, DBT_Trace.MEMORY_STORE16, addr, src); } @@ -376,7 +377,7 @@ * @param addr * the address of the value to store */ - public void translateStore32(OPT_RegisterOperand addr, OPT_RegisterOperand src) { + public void translateStore32(OPT_Operand addr, OPT_RegisterOperand src) { translateStore(store32, DBT_Trace.MEMORY_STORE32, addr, src); } @@ -388,7 +389,7 @@ * @param addr * the address of the value to store */ - public void translateCallBasedStore8(OPT_RegisterOperand addr, + public void translateCallBasedStore8(OPT_Operand addr, OPT_RegisterOperand src) { translateStore(store8, DBT_Trace.MEMORY_STORE8, addr, src); } @@ -401,7 +402,7 @@ * @param addr * the address of the value to store */ - public void translateCallBasedStore16(OPT_RegisterOperand addr, + public void translateCallBasedStore16(OPT_Operand addr, OPT_RegisterOperand src) { translateStore(store16, DBT_Trace.MEMORY_STORE16, addr, src); } @@ -414,7 +415,7 @@ * @param addr * the address of the value to store */ - public void translateCallBasedStore32(OPT_RegisterOperand addr, + public void translateCallBasedStore32(OPT_Operand addr, OPT_RegisterOperand src) { translateStore(store32, DBT_Trace.MEMORY_STORE32, addr, src); } Modified: src/org/binarytranslator/generic/memory/Memory.java =================================================================== --- src/org/binarytranslator/generic/memory/Memory.java 2007-03-31 22:03:22 UTC (rev 17) +++ src/org/binarytranslator/generic/memory/Memory.java 2007-04-01 12:27:50 UTC (rev 18) @@ -8,6 +8,7 @@ */ package org.binarytranslator.generic.memory; +import org.jikesrvm.opt.ir.OPT_Operand; import org.jikesrvm.opt.ir.OPT_RegisterOperand; import org.jikesrvm.classloader.VM_MethodReference; import org.binarytranslator.vmInterface.TranslationHelper; @@ -201,7 +202,7 @@ * @param addr * the address of the value to load */ - public abstract void translateLoadSigned8(OPT_RegisterOperand addr, + public abstract void translateLoadSigned8(OPT_Operand addr, OPT_RegisterOperand dest); /** @@ -213,7 +214,7 @@ * @param addr * the address of the value to load */ - public abstract void translateLoadUnsigned8(OPT_RegisterOperand addr, + public abstract void translateLoadUnsigned8(OPT_Operand addr, OPT_RegisterOperand dest); /** @@ -225,7 +226,7 @@ * @param addr * the address of the value to load */ - public abstract void translateLoadSigned16(OPT_RegisterOperand addr, + public abstract void translateLoadSigned16(OPT_Operand addr, OPT_RegisterOperand dest); /** @@ -237,7 +238,7 @@ * @param addr * the address of the value to load */ - public abstract void translateLoadUnsigned16(OPT_RegisterOperand addr, + public abstract void translateLoadUnsigned16(OPT_Operand addr, OPT_RegisterOperand dest); /** @@ -248,7 +249,7 @@ * @param addr * the address of the value to load */ - public abstract void translateLoad32(OPT_RegisterOperand addr, + public abstract void translateLoad32(OPT_Operand addr, OPT_RegisterOperand dest); /** @@ -259,7 +260,7 @@ * @param addr * the address of the value to store */ - public abstract void translateStore8(OPT_RegisterOperand addr, + public abstract void translateStore8(OPT_Operand addr, OPT_RegisterOperand src); /** @@ -270,7 +271,7 @@ * @param addr * the address of the value to store */ - public abstract void translateStore16(OPT_RegisterOperand addr, + public abstract void translateStore16(OPT_Operand addr, OPT_RegisterOperand src); /** @@ -281,7 +282,7 @@ * @param addr * the address of the value to store */ - public abstract void translateStore32(OPT_RegisterOperand addr, + public abstract void translateStore32(OPT_Operand addr, OPT_RegisterOperand src); /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mic...@us...> - 2007-03-31 22:03:22
|
Revision: 17 http://svn.sourceforge.net/pearcolator/?rev=17&view=rev Author: michael_baer Date: 2007-03-31 15:03:22 -0700 (Sat, 31 Mar 2007) Log Message: ----------- Enforced JRVM formatting guidelines, introduced generics, reduced no. of warnings Modified Paths: -------------- ext/org/jikesrvm/classloader/VM_Member.java ext/org/jikesrvm/classloader/VM_Method.java ext/org/jikesrvm/classloader/VM_NormalMethod.java ext/org/jikesrvm/ppc/PPC_Disassembler.java ext/org/jikesrvm/ppc/opcodeXX.java ext/org/jikesrvm/ppc/opcode_tab.java src/org/binarytranslator/DBT_Options.java src/org/binarytranslator/Main.java src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java src/org/binarytranslator/arch/arm/os/process/ARM_Registers.java src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java src/org/binarytranslator/arch/arm/os/process/linux/ARM_SyscallArgumentIterator.java src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java src/org/binarytranslator/arch/ppc/decoder/PPC_Constants.java src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java src/org/binarytranslator/arch/ppc/decoder/PPC_Laziness.java src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxSyscallArgumentIterator.java src/org/binarytranslator/arch/x86/decoder/X862IR.java src/org/binarytranslator/arch/x86/decoder/X86_Constants.java src/org/binarytranslator/arch/x86/decoder/X86_DecodedOperand.java src/org/binarytranslator/arch/x86/decoder/X86_FlagLaziness.java src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java src/org/binarytranslator/arch/x86/decoder/X86_Laziness.java src/org/binarytranslator/arch/x86/decoder/X86_ModRM_Decoder.java src/org/binarytranslator/arch/x86/decoder/X86_RegisterSyncLaziness.java src/org/binarytranslator/arch/x86/decoder/X86_Registers.java src/org/binarytranslator/arch/x86/decoder/X86_SIB_Decoder.java src/org/binarytranslator/arch/x86/os/abi/linux/X86_LinuxSystemCalls.java src/org/binarytranslator/generic/branch/BranchLogic.java src/org/binarytranslator/generic/branch/CallAndReturnAddress.java src/org/binarytranslator/generic/branch/ProcedureInformation.java src/org/binarytranslator/generic/decoder/DecoderUtils.java src/org/binarytranslator/generic/decoder/InstructionDecoder.java src/org/binarytranslator/generic/decoder/Laziness.java src/org/binarytranslator/generic/gdbstub/GDBStub.java src/org/binarytranslator/generic/gdbstub/GDBTarget.java src/org/binarytranslator/generic/memory/ByteAddressedByteSwapMemory.java src/org/binarytranslator/generic/memory/ByteAddressedMemory.java src/org/binarytranslator/generic/memory/ByteAddressedReversedMemory.java src/org/binarytranslator/generic/memory/CallBasedMemory.java src/org/binarytranslator/generic/memory/IntAddressedByteSwapMemory.java src/org/binarytranslator/generic/memory/IntAddressedMemory.java src/org/binarytranslator/generic/memory/IntAddressedPreSwappedMemory.java src/org/binarytranslator/generic/memory/IntAddressedReversedMemory.java src/org/binarytranslator/generic/memory/Memory.java src/org/binarytranslator/generic/memory/MemoryMapException.java src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java src/org/binarytranslator/generic/os/loader/image/ImageLoader.java src/org/binarytranslator/generic/os/process/ProcessSpace.java src/org/binarytranslator/vmInterface/DBT_ConvertBinaryToHIR.java src/org/binarytranslator/vmInterface/DBT_Trace.java src/org/binarytranslator/vmInterface/DynamicCodeRunner.java src/org/binarytranslator/vmInterface/TranslationHelper.java Modified: ext/org/jikesrvm/classloader/VM_Member.java =================================================================== --- ext/org/jikesrvm/classloader/VM_Member.java 2007-03-31 14:04:36 UTC (rev 16) +++ ext/org/jikesrvm/classloader/VM_Member.java 2007-03-31 22:03:22 UTC (rev 17) @@ -14,16 +14,17 @@ /** * A field or method of a java class. - * + * * @author Bowen Alpern * @author Dave Grove * @author Derek Lieber */ -public abstract class VM_Member extends VM_AnnotatedElement implements VM_Constants, VM_ClassLoaderConstants { +public abstract class VM_Member extends VM_AnnotatedElement implements + VM_Constants, VM_ClassLoaderConstants { /** - * The class that declared this member, avaliable by calling - * getDeclaringClass once the class is loaded. + * The class that declared this member, avaliable by calling getDeclaringClass + * once the class is loaded. */ private final VM_TypeReference declaringClass; @@ -38,46 +39,53 @@ public final short modifiers; /** - * The signature is a string representing the generic type for this - * field or method declaration, may be null + * The signature is a string representing the generic type for this field or + * method declaration, may be null */ private final VM_Atom signature; /** - * The member's jtoc/obj/tib offset in bytes. - * Set by {@link VM_Class#resolve()} + * The member's jtoc/obj/tib offset in bytes. Set by + * {@link VM_Class#resolve()} */ protected int offset; /** - * NOTE: Only {@link VM_Class} is allowed to create an instance of a VM_Member. + * NOTE: Only {@link VM_Class} is allowed to create an instance of a + * VM_Member. * - * @param declaringClass the VM_TypeReference object of the class that declared this member - * @param memRef the canonical memberReference for this member. - * @param modifiers modifiers associated with this member. - * @param signature generic type of this member - * @param annotations array of runtime visible annotations + * @param declaringClass + * the VM_TypeReference object of the class that declared this member + * @param memRef + * the canonical memberReference for this member. + * @param modifiers + * modifiers associated with this member. + * @param signature + * generic type of this member + * @param annotations + * array of runtime visible annotations */ - protected VM_Member(VM_TypeReference declaringClass, VM_MemberReference memRef, - short modifiers, VM_Atom signature, - VM_Annotation[] annotations) { + protected VM_Member(VM_TypeReference declaringClass, + VM_MemberReference memRef, short modifiers, VM_Atom signature, + VM_Annotation[] annotations) { super(annotations); this.declaringClass = declaringClass; this.memRef = memRef; this.modifiers = modifiers; this.signature = signature; - this.offset = Short.MIN_VALUE+1; // invalid value. Set to valid value during VM_Class.resolve() + this.offset = Short.MIN_VALUE + 1; // invalid value. Set to valid value + // during VM_Class.resolve() } - //--------------------------------------------------------------------// - // Section 1. // - // The following are available after class loading. // - //--------------------------------------------------------------------// + // --------------------------------------------------------------------// + // Section 1. // + // The following are available after class loading. // + // --------------------------------------------------------------------// /** - * Class that declared this field or method. Not available before - * the class is loaded. - */ + * Class that declared this field or method. Not available before the class is + * loaded. + */ @Uninterruptible public final VM_Class getDeclaringClass() { return declaringClass.peekResolvedType().asClass(); @@ -85,26 +93,26 @@ /** * Canonical member reference for this member. - */ + */ @Uninterruptible - public final VM_MemberReference getMemberRef() { + public final VM_MemberReference getMemberRef() { return memRef; } /** * Name of this member. - */ + */ @Uninterruptible - public final VM_Atom getName() { + public final VM_Atom getName() { return memRef.getName(); } /** - * Descriptor for this member. - * something like "I" for a field or "(I)V" for a method. - */ + * Descriptor for this member. something like "I" for a field or "(I)V" for a + * method. + */ @Uninterruptible - public final VM_Atom getDescriptor() { + public final VM_Atom getDescriptor() { return memRef.getDescriptor(); } @@ -116,47 +124,47 @@ } /** - * Get a unique id for this member. - * The id is the id of the canonical VM_MemberReference for this member - * and thus may be used to find the member by first finding the member reference. + * Get a unique id for this member. The id is the id of the canonical + * VM_MemberReference for this member and thus may be used to find the member + * by first finding the member reference. */ @Uninterruptible - public final int getId() { + public final int getId() { return memRef.getId(); } /* - * Define hashcode in terms of VM_Atom.hashCode to enable - * consistent hash codes during bootImage writing and run-time. + * Define hashcode in terms of VM_Atom.hashCode to enable consistent hash + * codes during bootImage writing and run-time. */ - public int hashCode() { + public int hashCode() { return memRef.hashCode(); } public final String toString() { return declaringClass + "." + getName() + " " + getDescriptor(); } - + /** * Usable from classes outside its package? - */ + */ public final boolean isPublic() { - return (modifiers & ACC_PUBLIC) != 0; + return (modifiers & ACC_PUBLIC) != 0; } /** * Usable only from this class? - */ - public final boolean isPrivate() { - return (modifiers & ACC_PRIVATE) != 0; + */ + public final boolean isPrivate() { + return (modifiers & ACC_PRIVATE) != 0; } - + /** * Usable from subclasses? - */ - public final boolean isProtected() { - return (modifiers & ACC_PROTECTED) != 0; - } + */ + public final boolean isProtected() { + return (modifiers & ACC_PROTECTED) != 0; + } /** * Get the member's modifiers. @@ -165,31 +173,34 @@ return modifiers; } - //------------------------------------------------------------------// - // Section 2. // - // The following are available after the declaring class has been // - // "resolved". // - //------------------------------------------------------------------// + // ------------------------------------------------------------------// + // Section 2. // + // The following are available after the declaring class has been // + // "resolved". // + // ------------------------------------------------------------------// /** * Offset of this field or method, in bytes. * <ul> - * <li> For a static field: offset of field from start of jtoc - * <li> For a static method: offset of code object reference from start of jtoc - * <li> For a non-static field: offset of field from start of object - * <li> For a non-static method: offset of code object reference from start of tib + * <li> For a static field: offset of field from start of jtoc + * <li> For a static method: offset of code object reference from start of + * jtoc + * <li> For a non-static field: offset of field from start of object + * <li> For a non-static method: offset of code object reference from start of + * tib * </ul> - */ + */ @Uninterruptible - public final Offset getOffset() { - if (VM.VerifyAssertions) VM._assert(declaringClass.isResolved()); + public final Offset getOffset() { + if (VM.VerifyAssertions) + VM._assert(declaringClass.isResolved()); return Offset.fromIntSignExtend(offset); } /** - * Only meant to be used by VM_ObjectModel.layoutInstanceFields. - * TODO: refactor system so this functionality is in the classloader package - * and this method doesn't have to be final. + * Only meant to be used by VM_ObjectModel.layoutInstanceFields. TODO: + * refactor system so this functionality is in the classloader package and + * this method doesn't have to be final. */ public final void setOffset(Offset off) { offset = off.toInt(); Modified: ext/org/jikesrvm/classloader/VM_Method.java =================================================================== --- ext/org/jikesrvm/classloader/VM_Method.java 2007-03-31 14:04:36 UTC (rev 16) +++ ext/org/jikesrvm/classloader/VM_Method.java 2007-03-31 22:03:22 UTC (rev 17) @@ -21,121 +21,143 @@ import org.vmmagic.pragma.*; /** - * A method of a java class corresponding to a method_info structure - * in the class file. A method is read from a class file using the - * {@link #readMethod} method. - * + * A method of a java class corresponding to a method_info structure in the + * class file. A method is read from a class file using the {@link #readMethod} + * method. + * * @author Bowen Alpern * @author Dave Grove * @author Derek Lieber * @author Ian Rogers */ -public abstract class VM_Method extends VM_Member implements VM_BytecodeConstants { +public abstract class VM_Method extends VM_Member implements + VM_BytecodeConstants { /** * current compiled method for this method */ protected VM_CompiledMethod currentCompiledMethod; + /** * exceptions this method might throw (null --> none) */ protected final VM_TypeReference[] exceptionTypes; + /** - * Method paramter annotations from the class file that are - * described as runtime visible. These annotations are available to - * the reflection API. + * Method paramter annotations from the class file that are described as + * runtime visible. These annotations are available to the reflection API. */ protected final VM_Annotation[] parameterAnnotations; + /** * A value present in the method info tables of annotation types. It * represents the default result from an annotation method. */ protected final Object annotationDefault; + /** - * The offset of this virtual method in the jtoc if it's been placed - * there by constant propagation, otherwise 0. + * The offset of this virtual method in the jtoc if it's been placed there by + * constant propagation, otherwise 0. */ private Offset jtocOffset; /** * Construct a read method - * - * @param declaringClass the VM_Class object of the class that declared this field - * @param memRef the canonical memberReference for this method. - * @param modifiers modifiers associated with this method. - * @param exceptionTypes exceptions thrown by this method. - * @param signature generic type of this method. - * @param annotations array of runtime visible annotations - * @param parameterAnnotations array of runtime visible parameter annotations - * @param annotationDefault value for this annotation that appears + * + * @param declaringClass + * the VM_Class object of the class that declared this field + * @param memRef + * the canonical memberReference for this method. + * @param modifiers + * modifiers associated with this method. + * @param exceptionTypes + * exceptions thrown by this method. + * @param signature + * generic type of this method. + * @param annotations + * array of runtime visible annotations + * @param parameterAnnotations + * array of runtime visible parameter annotations + * @param annotationDefault + * value for this annotation that appears */ - protected VM_Method(VM_TypeReference declaringClass, VM_MemberReference memRef, - short modifiers, VM_TypeReference[] exceptionTypes, VM_Atom signature, - VM_Annotation[] annotations, - VM_Annotation[] parameterAnnotations, - Object annotationDefault) - { - super(declaringClass, memRef, (short)(modifiers & APPLICABLE_TO_METHODS), signature, annotations); + protected VM_Method(VM_TypeReference declaringClass, + VM_MemberReference memRef, short modifiers, + VM_TypeReference[] exceptionTypes, VM_Atom signature, + VM_Annotation[] annotations, VM_Annotation[] parameterAnnotations, + Object annotationDefault) { + super(declaringClass, memRef, (short) (modifiers & APPLICABLE_TO_METHODS), + signature, annotations); this.parameterAnnotations = parameterAnnotations; this.annotationDefault = annotationDefault; memRef.asMethodReference().setResolvedMember(this); this.exceptionTypes = exceptionTypes; this.jtocOffset = Offset.fromIntSignExtend(-1); } - + /** - * Called from {@link VM_Class#readClass(VM_TypeReference, DataInputStream)} to create an - * instance of a VM_Method by reading the relevant data from the argument bytecode stream. + * Called from {@link VM_Class#readClass(VM_TypeReference, DataInputStream)} + * to create an instance of a VM_Method by reading the relevant data from the + * argument bytecode stream. * - * @param declaringClass the VM_TypeReference of the class being loaded - * @param constantPool the constantPool of the VM_Class object that's being constructed - * @param memRef the canonical memberReference for this member. - * @param modifiers modifiers associated with this member. - * @param input the DataInputStream to read the method's attributes from + * @param declaringClass + * the VM_TypeReference of the class being loaded + * @param constantPool + * the constantPool of the VM_Class object that's being constructed + * @param memRef + * the canonical memberReference for this member. + * @param modifiers + * modifiers associated with this member. + * @param input + * the DataInputStream to read the method's attributes from */ - static VM_Method readMethod(VM_TypeReference declaringClass, int[] constantPool, VM_MemberReference memRef, - short modifiers, DataInputStream input) throws IOException { + static VM_Method readMethod(VM_TypeReference declaringClass, + int[] constantPool, VM_MemberReference memRef, short modifiers, + DataInputStream input) throws IOException { short tmp_localWords = 0; - short tmp_operandWords = 0; - byte[] tmp_bytecodes = null; + short tmp_operandWords = 0; + byte[] tmp_bytecodes = null; VM_ExceptionHandlerMap tmp_exceptionHandlerMap = null; VM_TypeReference[] tmp_exceptionTypes = null; - int[] tmp_lineNumberMap = null; + int[] tmp_lineNumberMap = null; VM_Atom tmp_signature = null; VM_Annotation[] annotations = null; VM_Annotation[] parameterAnnotations = null; Object tmp_annotationDefault = null; // Read the attributes - for (int i = 0, n = input.readUnsignedShort(); i<n; i++) { - VM_Atom attName = VM_Class.getUtf(constantPool, input.readUnsignedShort()); - int attLength = input.readInt(); + for (int i = 0, n = input.readUnsignedShort(); i < n; i++) { + VM_Atom attName = VM_Class + .getUtf(constantPool, input.readUnsignedShort()); + int attLength = input.readInt(); // Only bother to interpret non-boring Method attributes if (attName == VM_ClassLoader.codeAttributeName) { tmp_operandWords = input.readShort(); - tmp_localWords = input.readShort(); + tmp_localWords = input.readShort(); tmp_bytecodes = new byte[input.readInt()]; input.readFully(tmp_bytecodes); - tmp_exceptionHandlerMap = VM_ExceptionHandlerMap.readExceptionHandlerMap(input, constantPool); + tmp_exceptionHandlerMap = VM_ExceptionHandlerMap + .readExceptionHandlerMap(input, constantPool); // Read the attributes portion of the code attribute - for (int j = 0, n2 = input.readUnsignedShort(); j<n2; j++) { - attName = VM_Class.getUtf(constantPool, input.readUnsignedShort()); + for (int j = 0, n2 = input.readUnsignedShort(); j < n2; j++) { + attName = VM_Class.getUtf(constantPool, input.readUnsignedShort()); attLength = input.readInt(); if (attName == VM_ClassLoader.lineNumberTableAttributeName) { int cnt = input.readUnsignedShort(); if (cnt != 0) { tmp_lineNumberMap = new int[cnt]; - for (int k = 0; k<cnt; k++) { + for (int k = 0; k < cnt; k++) { int startPC = input.readUnsignedShort(); int lineNumber = input.readUnsignedShort(); tmp_lineNumberMap[k] = (lineNumber << BITS_IN_SHORT) | startPC; } } } else { - // All other entries in the attribute portion of the code attribute are boring. + // All other entries in the attribute portion of the code attribute + // are boring. input.skipBytes(attLength); } } @@ -144,24 +166,26 @@ if (cnt != 0) { tmp_exceptionTypes = new VM_TypeReference[cnt]; for (int j = 0, m = tmp_exceptionTypes.length; j < m; ++j) { - tmp_exceptionTypes[j] = VM_Class.getTypeRef(constantPool, input.readUnsignedShort()); + tmp_exceptionTypes[j] = VM_Class.getTypeRef(constantPool, input + .readUnsignedShort()); } } } else if (attName == VM_ClassLoader.syntheticAttributeName) { modifiers |= ACC_SYNTHETIC; } else if (attName == VM_ClassLoader.signatureAttributeName) { - tmp_signature = VM_Class.getUtf(constantPool, input.readUnsignedShort()); + tmp_signature = VM_Class + .getUtf(constantPool, input.readUnsignedShort()); } else if (attName == VM_ClassLoader.runtimeVisibleAnnotationsAttributeName) { - annotations = VM_AnnotatedElement.readAnnotations(constantPool, input, 2, - declaringClass.getClassLoader()); + annotations = VM_AnnotatedElement.readAnnotations(constantPool, input, + 2, declaringClass.getClassLoader()); } else if (attName == VM_ClassLoader.runtimeVisibleParameterAnnotationsAttributeName) { - parameterAnnotations = VM_AnnotatedElement.readAnnotations(constantPool, input, 1, - declaringClass.getClassLoader()); + parameterAnnotations = VM_AnnotatedElement.readAnnotations( + constantPool, input, 1, declaringClass.getClassLoader()); } else if (attName == VM_ClassLoader.annotationDefaultAttributeName) { try { - tmp_annotationDefault = VM_Annotation.readValue(constantPool, input, declaringClass.getClassLoader()); - } - catch (ClassNotFoundException e){ + tmp_annotationDefault = VM_Annotation.readValue(constantPool, input, + declaringClass.getClassLoader()); + } catch (ClassNotFoundException e) { throw new Error(e); } } else { @@ -171,175 +195,173 @@ } VM_Method method; if ((modifiers & ACC_NATIVE) != 0) { - method = new VM_NativeMethod(declaringClass, memRef, modifiers, tmp_exceptionTypes, tmp_signature, - annotations, parameterAnnotations, tmp_annotationDefault); + method = new VM_NativeMethod(declaringClass, memRef, modifiers, + tmp_exceptionTypes, tmp_signature, annotations, parameterAnnotations, + tmp_annotationDefault); } else if ((modifiers & ACC_ABSTRACT) != 0) { - method = new VM_AbstractMethod(declaringClass, memRef, modifiers, tmp_exceptionTypes, tmp_signature, - annotations, parameterAnnotations, tmp_annotationDefault); + method = new VM_AbstractMethod(declaringClass, memRef, modifiers, + tmp_exceptionTypes, tmp_signature, annotations, parameterAnnotations, + tmp_annotationDefault); } else { - method = new VM_NormalMethod(declaringClass, memRef, modifiers, tmp_exceptionTypes, - tmp_localWords, tmp_operandWords, tmp_bytecodes, - tmp_exceptionHandlerMap, tmp_lineNumberMap, - constantPool, tmp_signature, - annotations, parameterAnnotations, tmp_annotationDefault); + method = new VM_NormalMethod(declaringClass, memRef, modifiers, + tmp_exceptionTypes, tmp_localWords, tmp_operandWords, tmp_bytecodes, + tmp_exceptionHandlerMap, tmp_lineNumberMap, constantPool, + tmp_signature, annotations, parameterAnnotations, + tmp_annotationDefault); } return method; } /** - * Create a copy of the method that occurs in the annotation - * interface. The method body will contain a read of the field at - * the constant pool index specified. - * - * @param annotationClass the class this method belongs to - * @param constantPool for the class - * @param memRef the member reference corresponding to this method - * @param interfaceMethod the interface method that will copied to - * produce the annotation method - * @param constantPoolIndex the index of the field that will be - * returned by this method + * Create a copy of the method that occurs in the annotation interface. The + * method body will contain a read of the field at the constant pool index + * specified. + * + * @param annotationClass + * the class this method belongs to + * @param constantPool + * for the class + * @param memRef + * the member reference corresponding to this method + * @param interfaceMethod + * the interface method that will copied to produce the annotation + * method + * @param constantPoolIndex + * the index of the field that will be returned by this method * @return the created method */ - static VM_Method createAnnotationMethod(VM_TypeReference annotationClass, int[] constantPool, - VM_MemberReference memRef, VM_Method interfaceMethod, - int constantPoolIndex) { - byte[] bytecodes = new byte[] { - (byte)JBC_aload_0, - (byte)JBC_getfield, - (byte)(constantPoolIndex >>> 8), - (byte)constantPoolIndex, - // Xreturn - (byte)typeRefToReturnBytecode(interfaceMethod.getReturnType()) - }; - return new VM_NormalMethod(annotationClass, memRef, (short)(ACC_PUBLIC|ACC_FINAL|ACC_SYNTHETIC), null, - (short)1, (short)2, bytecodes, - null, null, - constantPool, - null, null, null, null); + static VM_Method createAnnotationMethod(VM_TypeReference annotationClass, + int[] constantPool, VM_MemberReference memRef, VM_Method interfaceMethod, + int constantPoolIndex) { + byte[] bytecodes = new byte[] { (byte) JBC_aload_0, (byte) JBC_getfield, + (byte) (constantPoolIndex >>> 8), (byte) constantPoolIndex, + // Xreturn + (byte) typeRefToReturnBytecode(interfaceMethod.getReturnType()) }; + return new VM_NormalMethod(annotationClass, memRef, (short) (ACC_PUBLIC + | ACC_FINAL | ACC_SYNTHETIC), null, (short) 1, (short) 2, bytecodes, + null, null, constantPool, null, null, null, null); } + /** * Create a method to initialise the annotation class - * - * @param aClass the class this method belongs to - * @param constantPool for the class - * @param memRef the member reference corresponding to this method - * @param objectInitIndex an index into the constant pool for a - * method reference to java.lang.Object.<init> + * + * @param aClass + * the class this method belongs to + * @param constantPool + * for the class + * @param memRef + * the member reference corresponding to this method + * @param objectInitIndex + * an index into the constant pool for a method reference to + * java.lang.Object.<init> * @param aFields * @param aMethods * @return the created method */ - static VM_Method createAnnotationInit(VM_TypeReference aClass, int[] constantPool, - VM_MemberReference memRef, int objectInitIndex, - VM_Field[] aFields, VM_Method[] aMethods, - int[] defaultConstants) { - byte[] bytecode = new byte[6+(defaultConstants.length*7)]; - bytecode[0] = (byte)JBC_aload_0; // stack[0] = this - bytecode[1] = (byte)JBC_aload_1; // stack[1] = instanceof VM_Annotation - bytecode[2] = (byte)JBC_invokespecial; - bytecode[3] = (byte)(objectInitIndex >>> 8); - bytecode[4] = (byte)objectInitIndex; - for(int i=0, j=0; i < aMethods.length; i++) { - if(aMethods[i].annotationDefault != null) { - bytecode[(j*7)+5+0] = (byte)JBC_aload_0; // stack[0] = this - if(VM_Class.getLiteralSize(constantPool, defaultConstants[j]) == BYTES_IN_INT) { - bytecode[(j*7)+5+1] = (byte)JBC_ldc_w; // stack[1] = value + static VM_Method createAnnotationInit(VM_TypeReference aClass, + int[] constantPool, VM_MemberReference memRef, int objectInitIndex, + VM_Field[] aFields, VM_Method[] aMethods, int[] defaultConstants) { + byte[] bytecode = new byte[6 + (defaultConstants.length * 7)]; + bytecode[0] = (byte) JBC_aload_0; // stack[0] = this + bytecode[1] = (byte) JBC_aload_1; // stack[1] = instanceof VM_Annotation + bytecode[2] = (byte) JBC_invokespecial; + bytecode[3] = (byte) (objectInitIndex >>> 8); + bytecode[4] = (byte) objectInitIndex; + for (int i = 0, j = 0; i < aMethods.length; i++) { + if (aMethods[i].annotationDefault != null) { + bytecode[(j * 7) + 5 + 0] = (byte) JBC_aload_0; // stack[0] = this + if (VM_Class.getLiteralSize(constantPool, defaultConstants[j]) == BYTES_IN_INT) { + bytecode[(j * 7) + 5 + 1] = (byte) JBC_ldc_w; // stack[1] = value + } else { + bytecode[(j * 7) + 5 + 1] = (byte) JBC_ldc2_w;// stack[1&2] = value } - else { - bytecode[(j*7)+5+1] = (byte)JBC_ldc2_w;// stack[1&2] = value - } - bytecode[(j*7)+5+2] = (byte)(defaultConstants[j] >>> 8); - bytecode[(j*7)+5+3] = (byte)defaultConstants[j]; - bytecode[(j*7)+5+4] = (byte)JBC_putfield; - bytecode[(j*7)+5+5] = (byte)(i >>> 8); - bytecode[(j*7)+5+6] = (byte)i; + bytecode[(j * 7) + 5 + 2] = (byte) (defaultConstants[j] >>> 8); + bytecode[(j * 7) + 5 + 3] = (byte) defaultConstants[j]; + bytecode[(j * 7) + 5 + 4] = (byte) JBC_putfield; + bytecode[(j * 7) + 5 + 5] = (byte) (i >>> 8); + bytecode[(j * 7) + 5 + 6] = (byte) i; j++; } } - bytecode[bytecode.length-1] = (byte)JBC_return; - return new VM_NormalMethod(aClass, memRef, (short)(ACC_PUBLIC|ACC_FINAL|ACC_SYNTHETIC), null, - (short)2, (short)3, bytecode, - null, null, - constantPool, - null, null, null, null); + bytecode[bytecode.length - 1] = (byte) JBC_return; + return new VM_NormalMethod(aClass, memRef, + (short) (ACC_PUBLIC | ACC_FINAL | ACC_SYNTHETIC), null, (short) 2, + (short) 3, bytecode, null, null, constantPool, null, null, null, null); } /** - * What would be the appropriate return bytecode for the given type - * reference? + * What would be the appropriate return bytecode for the given type reference? */ private static int typeRefToReturnBytecode(VM_TypeReference tr) { - if(!tr.isPrimitiveType()) { + if (!tr.isPrimitiveType()) { return JBC_areturn; } else { - VM_Primitive pt = (VM_Primitive)tr.peekResolvedType(); - if((pt == VM_Type.BooleanType)||(pt == VM_Type.ByteType)||(pt == VM_Type.ShortType)|| - (pt == VM_Type.CharType)||(pt == VM_Type.IntType)) { + VM_Primitive pt = (VM_Primitive) tr.peekResolvedType(); + if ((pt == VM_Type.BooleanType) || (pt == VM_Type.ByteType) + || (pt == VM_Type.ShortType) || (pt == VM_Type.CharType) + || (pt == VM_Type.IntType)) { return JBC_ireturn; - } - else if(pt == VM_Type.LongType) { + } else if (pt == VM_Type.LongType) { return JBC_lreturn; - } - else if(pt == VM_Type.FloatType) { + } else if (pt == VM_Type.FloatType) { return JBC_freturn; - } - else if(pt == VM_Type.DoubleType) { + } else if (pt == VM_Type.DoubleType) { return JBC_dreturn; - } - else { + } else { VM._assert(false); return -1; } } } + /** * Is this method a class initializer? */ @Uninterruptible - public final boolean isClassInitializer() { - return getName() == VM_ClassLoader.StandardClassInitializerMethodName; + public final boolean isClassInitializer() { + return getName() == VM_ClassLoader.StandardClassInitializerMethodName; } /** * Is this method an object initializer? */ @Uninterruptible - public final boolean isObjectInitializer() { - return getName() == VM_ClassLoader.StandardObjectInitializerMethodName; + public final boolean isObjectInitializer() { + return getName() == VM_ClassLoader.StandardObjectInitializerMethodName; } /** * Is this method a compiler-generated object initializer helper? */ @Uninterruptible - public final boolean isObjectInitializerHelper() { - return getName() == VM_ClassLoader.StandardObjectInitializerHelperMethodName; + public final boolean isObjectInitializerHelper() { + return getName() == VM_ClassLoader.StandardObjectInitializerHelperMethodName; } /** * Type of this method's return value. */ @Uninterruptible - public final VM_TypeReference getReturnType() { + public final VM_TypeReference getReturnType() { return memRef.asMethodReference().getReturnType(); } /** - * Type of this method's parameters. - * Note: does *not* include implicit "this" parameter, if any. + * Type of this method's parameters. Note: does *not* include implicit "this" + * parameter, if any. */ @Uninterruptible - public final VM_TypeReference[] getParameterTypes() { + public final VM_TypeReference[] getParameterTypes() { return memRef.asMethodReference().getParameterTypes(); } /** - * Space required by this method for its parameters, in words. - * Note: does *not* include implicit "this" parameter, if any. + * Space required by this method for its parameters, in words. Note: does + * *not* include implicit "this" parameter, if any. */ @Uninterruptible - public final int getParameterWords() { + public final int getParameterWords() { return memRef.asMethodReference().getParameterWords(); } @@ -351,15 +373,16 @@ } /** - * Get the current compiled method for this method. - * Will return null if there is no current compiled method! - * - * We make this method Unpreemptible to avoid a race-condition - * in VM_Reflection.invoke. + * Get the current compiled method for this method. Will return null if there + * is no current compiled method! + * + * We make this method Unpreemptible to avoid a race-condition in + * VM_Reflection.invoke. + * * @return compiled method - */ + */ @Unpreemptible - public final synchronized VM_CompiledMethod getCurrentCompiledMethod() { + public final synchronized VM_CompiledMethod getCurrentCompiledMethod() { return currentCompiledMethod; } @@ -367,7 +390,7 @@ * Declared as statically dispatched? */ @Uninterruptible - public final boolean isStatic() { + public final boolean isStatic() { return (modifiers & ACC_STATIC) != 0; } @@ -375,7 +398,7 @@ * Declared as non-overridable by subclasses? */ @Uninterruptible - public final boolean isFinal() { + public final boolean isFinal() { return (modifiers & ACC_FINAL) != 0; } @@ -383,7 +406,7 @@ * Guarded by monitorenter/monitorexit? */ @Uninterruptible - public final boolean isSynchronized() { + public final boolean isSynchronized() { return (modifiers & ACC_SYNCHRONIZED) != 0; } @@ -391,7 +414,7 @@ * Not implemented in java? */ @Uninterruptible - public final boolean isNative() { + public final boolean isNative() { return (modifiers & ACC_NATIVE) != 0; } @@ -399,14 +422,15 @@ * Not implemented in Java and use C not JNI calling convention */ public final boolean isSysCall() { - return isNative() && isStatic() && isAnnotationDeclared(VM_TypeReference.SysCall); + return isNative() && isStatic() + && isAnnotationDeclared(VM_TypeReference.SysCall); } - + /** * Implemented in subclass? */ @Uninterruptible - public final boolean isAbstract() { + public final boolean isAbstract() { return (modifiers & ACC_ABSTRACT) != 0; } @@ -418,46 +442,58 @@ } /** - * Exceptions thrown by this method - - * something like { "java/lang/IOException", "java/lang/EOFException" } + * Exceptions thrown by this method - something like { + * "java/lang/IOException", "java/lang/EOFException" } + * * @return info (null --> method doesn't throw any exceptions) */ @Uninterruptible - public final VM_TypeReference[] getExceptionTypes() { + public final VM_TypeReference[] getExceptionTypes() { return exceptionTypes; } /** - * Is this method interruptible? - * In other words, should the compiler insert yieldpoints - * in method prologue, epilogue, and backwards branches. - * Also, only methods that are Interruptible have stackoverflow checks - * in the method prologue (since there is no mechanism for handling a stackoverflow - * that doesn't violate the uninterruptiblity of the method). - * To determine if a method is interruptible, the following conditions - * are checked (<em>in order</em>): + * Is this method interruptible? In other words, should the compiler insert + * yieldpoints in method prologue, epilogue, and backwards branches. Also, + * only methods that are Interruptible have stackoverflow checks in the method + * prologue (since there is no mechanism for handling a stackoverflow that + * doesn't violate the uninterruptiblity of the method). To determine if a + * method is interruptible, the following conditions are checked (<em>in order</em>): * <ul> * <li> If it is a <clinit> or <init> method then it is interruptible. - * <li> If is the synthetic 'this' method used by jikes to - * factor out default initializers for <init> methods then it is interruptible. - * <li> If it is annotated with <CODE>Interruptible</CODE> it is interruptible. - * <li> If it is annotated with <CODE>Preemptible</CODE> it is interruptible. - * <li> If it is annotated with <CODE>Uninterruptible</CODE> it is not interruptible. - * <li> If it is annotated with <CODE>UninterruptibleNoWarn</CODE> it is not interruptible. - * <li> If it is annotated with <CODE>Unpreemptible</CODE> it is not interruptible. + * <li> If is the synthetic 'this' method used by jikes to factor out default + * initializers for <init> methods then it is interruptible. + * <li> If it is annotated with <CODE>Interruptible</CODE> it is + * interruptible. + * <li> If it is annotated with <CODE>Preemptible</CODE> it is + * interruptible. + * <li> If it is annotated with <CODE>Uninterruptible</CODE> it is not + * interruptible. + * <li> If it is annotated with <CODE>UninterruptibleNoWarn</CODE> it is not + * interruptible. + * <li> If it is annotated with <CODE>Unpreemptible</CODE> it is not + * interruptible. * <li> If its declaring class is annotated with <CODE>Uninterruptible</CODE> - * or <CODE>Unpreemptible</CODE> it is not interruptible. + * or <CODE>Unpreemptible</CODE> it is not interruptible. * </ul> */ public final boolean isInterruptible() { - if (isClassInitializer() || isObjectInitializer()) return true; - if (isObjectInitializerHelper()) return true; - if (hasInterruptibleAnnotation()) return true; - if (hasPreemptibleAnnotation()) return true; - if (hasUninterruptibleNoWarnAnnotation()) return false; - if (hasUninterruptibleAnnotation()) return false; - if (hasUnpreemptibleAnnotation()) return false; - if (getDeclaringClass().hasUnpreemptibleAnnotation()) return false; + if (isClassInitializer() || isObjectInitializer()) + return true; + if (isObjectInitializerHelper()) + return true; + if (hasInterruptibleAnnotation()) + return true; + if (hasPreemptibleAnnotation()) + return true; + if (hasUninterruptibleNoWarnAnnotation()) + return false; + if (hasUninterruptibleAnnotation()) + return false; + if (hasUnpreemptibleAnnotation()) + return false; + if (getDeclaringClass().hasUnpreemptibleAnnotation()) + return false; return !getDeclaringClass().hasUninterruptibleAnnotation(); } @@ -465,13 +501,20 @@ * Is the method Unpreemptible? See the comment in {@link #isInterruptible} */ public final boolean isUnpreemptible() { - if (isClassInitializer() || isObjectInitializer()) return false; - if (isObjectInitializerHelper()) return false; - if (hasInterruptibleAnnotation()) return false; - if (hasPreemptibleAnnotation()) return false; - if (hasUninterruptibleAnnotation()) return false; - if (hasUninterruptibleNoWarnAnnotation()) return false; - if (hasUnpreemptibleAnnotation()) return true; + if (isClassInitializer() || isObjectInitializer()) + return false; + if (isObjectInitializerHelper()) + return false; + if (hasInterruptibleAnnotation()) + return false; + if (hasPreemptibleAnnotation()) + return false; + if (hasUninterruptibleAnnotation()) + return false; + if (hasUninterruptibleNoWarnAnnotation()) + return false; + if (hasUnpreemptibleAnnotation()) + return true; return getDeclaringClass().hasUnpreemptibleAnnotation(); } @@ -479,20 +522,27 @@ * Is the method Uninterruptible? See the comment in {@link #isInterruptible} */ public final boolean isUninterruptible() { - if (isClassInitializer() || isObjectInitializer()) return false; - if (isObjectInitializerHelper()) return false; - if (hasInterruptibleAnnotation()) return false; - if (hasPreemptibleAnnotation()) return false; - if (hasUnpreemptibleAnnotation()) return false; - if (hasUninterruptibleAnnotation()) return true; - if (hasUninterruptibleNoWarnAnnotation()) return true; + if (isClassInitializer() || isObjectInitializer()) + return false; + if (isObjectInitializerHelper()) + return false; + if (hasInterruptibleAnnotation()) + return false; + if (hasPreemptibleAnnotation()) + return false; + if (hasUnpreemptibleAnnotation()) + return false; + if (hasUninterruptibleAnnotation()) + return true; + if (hasUninterruptibleNoWarnAnnotation()) + return true; return getDeclaringClass().hasUninterruptibleAnnotation(); } /** - * Has this method been marked as forbidden to inline? - * ie., it is marked with the <CODE>NoInline</CODE> annotation or - * the <CODE>NoOptCompile</CODE> annotation? + * Has this method been marked as forbidden to inline? ie., it is marked with + * the <CODE>NoInline</CODE> annotation or the <CODE>NoOptCompile</CODE> + * annotation? */ public final boolean hasNoInlinePragma() { return (hasNoInlineAnnotation() || hasNoOptCompileAnnotation()); @@ -502,70 +552,81 @@ * @return true if the method may write to a given field */ public boolean mayWrite(VM_Field field) { - return true; // be conservative. native methods can write to anything + return true; // be conservative. native methods can write to anything } /** - * @return true if the method is the implementation of a runtime service - * that is called "under the covers" from the generated code and thus is not subject to - * inlining via the normal mechanisms. + * @return true if the method is the implementation of a runtime service that + * is called "under the covers" from the generated code and thus is + * not subject to inlining via the normal mechanisms. */ public boolean isRuntimeServiceMethod() { - return false; // only VM_NormalMethods can be runtime service impls in Jikes RVM and they override this method + return false; // only VM_NormalMethods can be runtime service impls in Jikes + // RVM and they override this method } - //------------------------------------------------------------------// - // Section 2. // - // The following are available after the declaring class has been // - // "resolved". // - //------------------------------------------------------------------// + // ------------------------------------------------------------------// + // Section 2. // + // The following are available after the declaring class has been // + // "resolved". // + // ------------------------------------------------------------------// /** - * Get the code array that corresponds to the entry point (prologue) for the method. + * Get the code array that corresponds to the entry point (prologue) for the + * method. */ public final synchronized VM_CodeArray getCurrentEntryCodeArray() { VM_Class declaringClass = getDeclaringClass(); - if (VM.VerifyAssertions) VM._assert(declaringClass.isResolved()); + if (VM.VerifyAssertions) + VM._assert(declaringClass.isResolved()); if (isCompiled()) { return currentCompiledMethod.getEntryCodeArray(); } else if (!VM.writingBootImage || isNative()) { if (!isStatic() && !isObjectInitializer() && !isPrivate()) { // A non-private virtual method. - if (declaringClass.isJavaLangObjectType() || - declaringClass.getSuperClass().findVirtualMethod(getName(), getDescriptor()) == null) { - // The root method of a virtual method family can use the lazy method invoker directly. - return VM_Entrypoints.lazyMethodInvokerMethod.getCurrentEntryCodeArray(); + if (declaringClass.isJavaLangObjectType() + || declaringClass.getSuperClass().findVirtualMethod(getName(), + getDescriptor()) == null) { + // The root method of a virtual method family can use the lazy method + // invoker directly. + return VM_Entrypoints.lazyMethodInvokerMethod + .getCurrentEntryCodeArray(); } else { - // All other virtual methods in the family must generate unique stubs to - // ensure correct operation of the method test (guarded inlining of virtual calls). + // All other virtual methods in the family must generate unique stubs + // to + // ensure correct operation of the method test (guarded inlining of + // virtual calls). return VM_LazyCompilationTrampolineGenerator.getTrampoline(); } } else { // We'll never do a method test against this method. // Therefore we can use the lazy method invoker directly. - return VM_Entrypoints.lazyMethodInvokerMethod.getCurrentEntryCodeArray(); + return VM_Entrypoints.lazyMethodInvokerMethod + .getCurrentEntryCodeArray(); } } else { - compile(); + compile(); return currentCompiledMethod.getEntryCodeArray(); } } /** - * Generate machine code for this method if valid - * machine code doesn't already exist. - * Return the resulting VM_CompiledMethod object. + * Generate machine code for this method if valid machine code doesn't already + * exist. Return the resulting VM_CompiledMethod object. */ public final synchronized void compile() { - if (VM.VerifyAssertions) VM._assert(getDeclaringClass().isResolved()); - if (isCompiled()) return; + if (VM.VerifyAssertions) + VM._assert(getDeclaringClass().isResolved()); + if (isCompiled()) + return; - if (VM.TraceClassLoading && VM.runningVM) VM.sysWrite("VM_Method: (begin) compiling " + this + "\n"); + if (VM.TraceClassLoading && VM.runningVM) + VM.sysWrite("VM_Method: (begin) compiling " + this + "\n"); VM_CompiledMethod cm = genCode(); // Ensure that cm wasn't invalidated while it was being compiled. - synchronized(cm) { + synchronized (cm) { if (cm.isInvalid()) { VM_CompiledMethods.setCompiledMethodObsolete(cm); } else { @@ -573,34 +634,40 @@ } } - if (VM.TraceClassLoading && VM.runningVM) VM.sysWrite("VM_Method: (end) compiling " + this + "\n"); + if (VM.TraceClassLoading && VM.runningVM) + VM.sysWrite("VM_Method: (end) compiling " + this + "\n"); } protected abstract VM_CompiledMethod genCode(); - //----------------------------------------------------------------// - // Section 3. // - // The following are available after the declaring class has been // - // "instantiated". // - //----------------------------------------------------------------// + // ----------------------------------------------------------------// + // Section 3. // + // The following are available after the declaring class has been // + // "instantiated". // + // ----------------------------------------------------------------// /** - * Change machine code that will be used by future executions of this method + * Change machine code that will be used by future executions of this method * (ie. optimized <-> non-optimized) - * @param compiledMethod new machine code - * Side effect: updates jtoc or method dispatch tables - * ("type information blocks") - * for this class and its subclasses - */ - public synchronized void replaceCompiledMethod(VM_CompiledMethod compiledMethod) { - if (VM.VerifyAssertions) VM._assert(getDeclaringClass().isInstantiated()); - // If we're replacing with a non-null compiledMethod, ensure that is still valid! + * + * @param compiledMethod + * new machine code Side effect: updates jtoc or method dispatch + * tables ("type information blocks") for this class and its + * subclasses + */ + public synchronized void replaceCompiledMethod( + VM_CompiledMethod compiledMethod) { + if (VM.VerifyAssertions) + VM._assert(getDeclaringClass().isInstantiated()); + // If we're replacing with a non-null compiledMethod, ensure that is still + // valid! if (compiledMethod != null) { - synchronized(compiledMethod) { - if (compiledMethod.isInvalid()) return; + synchronized (compiledMethod) { + if (compiledMethod.isInvalid()) + return; } } - + // Grab version that is being replaced VM_CompiledMethod oldCompiledMethod = currentCompiledMethod; currentCompiledMethod = compiledMethod; @@ -610,7 +677,7 @@ getDeclaringClass().updateMethod(this); // Replace constant-ified virtual method in JTOC if necessary - if(jtocOffset.toInt() != -1) { + if (jtocOffset.toInt() != -1) { VM_Statics.setSlotContents(jtocOffset, getCurrentEntryCodeArray()); } @@ -621,10 +688,11 @@ } /** - * If CM is the current compiled code for this, then invaldiate it. + * If CM is the current compiled code for this, then invaldiate it. */ public final synchronized void invalidateCompiledMethod(VM_CompiledMethod cm) { - if (VM.VerifyAssertions) VM._assert(getDeclaringClass().isInstantiated()); + if (VM.VerifyAssertions) + VM._assert(getDeclaringClass().isInstantiated()); if (currentCompiledMethod == cm) { replaceCompiledMethod(null); } @@ -634,8 +702,9 @@ * Find or create a jtoc offset for this method */ public final synchronized Offset findOrCreateJtocOffset() { - if (VM.VerifyAssertions) VM._assert(!isStatic() && !isObjectInitializer()); - if(jtocOffset.EQ(Offset.zero())) { + if (VM.VerifyAssertions) + VM._assert(!isStatic() && !isObjectInitializer()); + if (jtocOffset.EQ(Offset.zero())) { jtocOffset = VM_Statics.allocateReferenceSlot(); VM_Statics.setSlotContents(jtocOffset, getCurrentEntryCodeArray()); } Modified: ext/org/jikesrvm/classloader/VM_NormalMethod.java =================================================================== --- ext/org/jikesrvm/classloader/VM_NormalMethod.java 2007-03-31 14:04:36 UTC (rev 16) +++ ext/org/jikesrvm/classloader/VM_NormalMethod.java 2007-03-31 22:03:22 UTC (rev 17) @@ -17,80 +17,103 @@ /** * A method of a java class that has bytecodes. - * + * * @author Bowen Alpern * @author Stephen Fink * @author Dave Grove * @author Derek Lieber * @modified Ian Rogers */ -public class VM_NormalMethod - extends VM_Method - implements VM_BytecodeConstants -{ +public class VM_NormalMethod extends VM_Method implements VM_BytecodeConstants { - /* As we read the bytecodes for the method, we compute - * a simple summary of some interesting properties of the method. - * Because we do this for every method, we require the summarization to - * be fast and the computed summary to be very space efficient. + /* + * As we read the bytecodes for the method, we compute a simple summary of + * some interesting properties of the method. Because we do this for every + * method, we require the summarization to be fast and the computed summary to + * be very space efficient. * - * The following constants encode the estimated relative cost in - * machine instructions when a particular class of bytecode is compiled - * by the optimizing compiler. The estimates approximate the typical - * optimization the compiler is able to perform. - * This information is used to estimate how big a method will be when - * it is inlined. + * The following constants encode the estimated relative cost in machine + * instructions when a particular class of bytecode is compiled by the + * optimizing compiler. The estimates approximate the typical optimization the + * compiler is able to perform. This information is used to estimate how big a + * method will be when it is inlined. */ public static final int SIMPLE_OPERATION_COST = 1; + public static final int LONG_OPERATION_COST = 2; + public static final int ARRAY_LOAD_COST = 2; + public static final int ARRAY_STORE_COST = 2; + public static final int JSR_COST = 5; + public static final int CALL_COST = 6; + // Bias to inlining methods with magic // most magics are quite cheap (0-1 instructions) public static final int MAGIC_COST = 0; + // News are actually more expensive than calls // but bias to inline methods that allocate - // objects becuase we expect better downstream optimization of + // objects becuase we expect better downstream optimization of // the caller due to class analysis // and propagation of nonNullness public static final int ALLOCATION_COST = 4; + // Approximations, assuming some CSE/PRE of object model computations - public static final int CLASS_CHECK_COST = 2*SIMPLE_OPERATION_COST; - public static final int STORE_CHECK_COST = 4*SIMPLE_OPERATION_COST; + public static final int CLASS_CHECK_COST = 2 * SIMPLE_OPERATION_COST; + + public static final int STORE_CHECK_COST = 4 * SIMPLE_OPERATION_COST; + // Just a call. public static final int THROW_COST = CALL_COST; + // Really a bunch of operations plus a call, but undercharge because // we don't have worry about this causing an exponential growth of call chain - // and we probably want to inline synchronization + // and we probably want to inline synchronization // (to get a chance to optimize it). - public static final int SYNCH_COST = 4*SIMPLE_OPERATION_COST; - // The additional cost of a switch isn't that large, since if the - // switch has more than a few cases the method will be too big to inline + public static final int SYNCH_COST = 4 * SIMPLE_OPERATION_COST; + + // The additional cost of a switch isn't that large, since if the + // switch has more than a few cases the method will be too big to inline // anyways. public static final int SWITCH_COST = CALL_COST; // Definition of flag bits - protected static final char HAS_MAGIC = 0x8000; - protected static final char HAS_SYNCH = 0x4000; + protected static final char HAS_MAGIC = 0x8000; + + protected static final char HAS_SYNCH = 0x4000; + protected static final char HAS_ALLOCATION = 0x2000; - protected static final char HAS_THROW = 0x1000; - protected static final char HAS_INVOKE = 0x0800; + + protected static final char HAS_THROW = 0x1000; + + protected static final char HAS_INVOKE = 0x0800; + protected static final char HAS_FIELD_READ = 0x0400; - protected static final char HAS_FIELD_WRITE= 0x0200; + + protected static final char HAS_FIELD_WRITE = 0x0200; + protected static final char HAS_ARRAY_READ = 0x0100; - protected static final char HAS_ARRAY_WRITE= 0x0080; - protected static final char HAS_JSR = 0x0040; - protected static final char HAS_COND_BRANCH= 0x0020; - protected static final char HAS_SWITCH = 0x0010; - protected static final char HAS_BACK_BRANCH= 0x0008; - protected static final char IS_RS_METHOD = 0x0004; - + + protected static final char HAS_ARRAY_WRITE = 0x0080; + + protected static final char HAS_JSR = 0x0040; + + protected static final char HAS_COND_BRANCH = 0x0020; + + protected static final char HAS_SWITCH = 0x0010; + + protected static final char HAS_BACK_BRANCH = 0x0008; + + protected static final char IS_RS_METHOD = 0x0004; + /** * storage for bytecode summary flags */ protected char summaryFlags; + /** * storage for bytecode summary size */ @@ -99,68 +122,83 @@ /** * words needed for local variables (including parameters) */ - private final short localWords; + private final short localWords; /** - * words needed for operand stack (high water mark) - * TODO: OSR redesign; add subclass of NormalMethod for OSR method - * and then make this field final in NormalMethod. + * words needed for operand stack (high water mark) TODO: OSR redesign; add + * subclass of NormalMethod for OSR method and then make this field final in + * NormalMethod. */ - private short operandWords; + private short operandWords; /** * bytecodes for this method (null --> none) */ - public final byte[] bytecodes; + public final byte[] bytecodes; /** * try/catch/finally blocks for this method (null --> none) */ - private final VM_ExceptionHandlerMap exceptionHandlerMap; + private final VM_ExceptionHandlerMap exceptionHandlerMap; /** - * pc to source-line info (null --> none) - * Each entry contains both the line number (upper 16 bits) - * and corresponding start PC (lower 16 bits). + * pc to source-line info (null --> none) Each entry contains both the line + * number (upper 16 bits) and corresponding start PC (lower 16 bits). */ - private final int[] lineNumberMap; + private final int[] lineNumberMap; // Extra fields for on-stack replacement - // TODO: rework the system so we don't waste space for this on the VM_Method object + //... [truncated message content] |
From: <mic...@us...> - 2007-03-31 14:04:41
|
Revision: 16 http://svn.sourceforge.net/pearcolator/?rev=16&view=rev Author: michael_baer Date: 2007-03-31 07:04:36 -0700 (Sat, 31 Mar 2007) Log Message: ----------- Added missing files for a working build Modified Paths: -------------- src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java src/org/binarytranslator/generic/os/process/ProcessSpace.java Added Paths: ----------- src/org/binarytranslator/arch/arm/os/process/image/ src/org/binarytranslator/arch/arm/os/process/image/ARM_ImageProcessSpace.java Modified: src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java 2007-03-30 15:38:52 UTC (rev 15) +++ src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java 2007-03-31 14:04:36 UTC (rev 16) @@ -4,7 +4,7 @@ import org.jikesrvm.opt.ir.OPT_HIRGenerator; import org.jikesrvm.opt.ir.OPT_GenerationContext; import org.binarytranslator.DBT_Options; -import org.binarytranslator.arch.arm.os.process.image.ARM_SimpleProcessSpace; +import org.binarytranslator.arch.arm.os.process.image.ARM_ImageProcessSpace; import org.binarytranslator.arch.arm.os.process.linux.ARM_LinuxProcessSpace; import org.binarytranslator.arch.x86.decoder.X862IR; import org.binarytranslator.arch.x86.os.process.X86_Registers; @@ -77,11 +77,11 @@ public static ProcessSpace createProcessSpaceFromBinary(Loader loader) throws IOException { if (loader.isARM_ABI() || loader.isSysV_ABI()) { - report("ARM ABI"); + report("Creating ARM Linux ABI [rocess space"); return new ARM_LinuxProcessSpace(); } else { - report("Creating simple ARM process space."); - return new ARM_SimpleProcessSpace(); + report("Creating ARM image process space."); + return new ARM_ImageProcessSpace(); } } Added: src/org/binarytranslator/arch/arm/os/process/image/ARM_ImageProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/arm/os/process/image/ARM_ImageProcessSpace.java (rev 0) +++ src/org/binarytranslator/arch/arm/os/process/image/ARM_ImageProcessSpace.java 2007-03-31 14:04:36 UTC (rev 16) @@ -0,0 +1,25 @@ +package org.binarytranslator.arch.arm.os.process.image; + +import org.binarytranslator.arch.arm.os.process.ARM_ProcessSpace; +import org.binarytranslator.arch.arm.os.process.ARM_Registers; +import org.binarytranslator.generic.gdbstub.GDBTarget; +import org.binarytranslator.generic.os.loader.Loader; + +public class ARM_ImageProcessSpace extends ARM_ProcessSpace { + + @Override + public void doSysCall() { + throw new UnsupportedOperationException("Syscalls not supported."); + } + + @Override + public GDBTarget getGDBTarget() { + throw new UnsupportedOperationException("GDB not implemented."); + } + + @Override + public void initialise(Loader loader, int pc, int brk, String[] args) { + registers.write(ARM_Registers.PC, pc); + } + +} Modified: src/org/binarytranslator/generic/os/process/ProcessSpace.java =================================================================== --- src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-03-30 15:38:52 UTC (rev 15) +++ src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-03-31 14:04:36 UTC (rev 16) @@ -208,13 +208,13 @@ throws IOException { ProcessSpace result; if (loader.isX86_ISA()) { - report("X86 ELF Binary"); + report("X86 Binary"); result = X86_ProcessSpace.createProcessSpaceFromBinary(loader); } else if (loader.isPPC_ISA()) { - report("PPC ELF Binary"); + report("PPC Binary"); result = PPC_ProcessSpace.createProcessSpaceFromBinary(loader); } else if (loader.isARM_ISA()) { - report("ARM ELF Binary"); + report("ARM Binary"); result = ARM_ProcessSpace.createProcessSpaceFromBinary(loader); } else { throw new UnsupportedOperationException("Binary of " + loader.getArchitectureString() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mic...@us...> - 2007-03-30 15:38:56
|
Revision: 15 http://svn.sourceforge.net/pearcolator/?rev=15&view=rev Author: michael_baer Date: 2007-03-30 08:38:52 -0700 (Fri, 30 Mar 2007) Log Message: ----------- Introduced various refactorings Modified Paths: -------------- src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java src/org/binarytranslator/arch/arm/os/process/ARM_Registers.java src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java src/org/binarytranslator/generic/gdbstub/GDBStub.java src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCallGenerator.java src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java src/org/binarytranslator/generic/os/loader/Loader.java src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java src/org/binarytranslator/generic/os/process/ProcessSpace.java Added Paths: ----------- src/org/binarytranslator/arch/arm/os/process/linux/ARM_SyscallArgumentIterator.java src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxSyscallArgumentIterator.java src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxSyscallArgumentIterator.java src/org/binarytranslator/generic/gdbstub/GDBTarget.java src/org/binarytranslator/generic/os/loader/image/ src/org/binarytranslator/generic/os/loader/image/ImageLoader.java Modified: src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java 2007-03-29 13:53:07 UTC (rev 14) +++ src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java 2007-03-30 15:38:52 UTC (rev 15) @@ -4,6 +4,7 @@ import org.jikesrvm.opt.ir.OPT_HIRGenerator; import org.jikesrvm.opt.ir.OPT_GenerationContext; import org.binarytranslator.DBT_Options; +import org.binarytranslator.arch.arm.os.process.image.ARM_SimpleProcessSpace; import org.binarytranslator.arch.arm.os.process.linux.ARM_LinuxProcessSpace; import org.binarytranslator.arch.x86.decoder.X862IR; import org.binarytranslator.arch.x86.os.process.X86_Registers; @@ -24,43 +25,6 @@ */ public ARM_Registers registers; - /* GDB Interface */ - /** - * Read a register and turn into a byte array conforming to the endianness of - * the architecture - */ - public byte[] readRegisterGDB(int regNum) { - throw new RuntimeException("Not yet implemented"); - } - - /** - * Has frame base register? - */ - public boolean hasFrameBaseRegister() { - throw new RuntimeException("Not yet implemented"); - } - - /** - * Get the value of the frame base register - */ - public int getGDBFrameBaseRegister() { - throw new RuntimeException("Not yet implemented"); - } - - /** - * Get the value of the frame base register - */ - public int getGDBStackPointerRegister() { - throw new RuntimeException("Not yet implemented"); - } - - /** - * Get the value of the frame base register - */ - public int getGDBProgramCountRegister() { - throw new RuntimeException("Not yet implemented"); - } - /* * Utility functions */ @@ -99,6 +63,7 @@ * @return a HIR generator */ public OPT_HIRGenerator createHIRGenerator(OPT_GenerationContext context) { + System.out.println("Executing instr: " + memory.load32(0)); throw new RuntimeException("Not yet implemented"); } @@ -111,12 +76,12 @@ */ public static ProcessSpace createProcessSpaceFromBinary(Loader loader) throws IOException { - if (loader.isARM_ABI()) { + if (loader.isARM_ABI() || loader.isSysV_ABI()) { report("ARM ABI"); return new ARM_LinuxProcessSpace(); } else { - throw new UnsupportedOperationException("Binary of " + loader.getABIString() - + " ABI is unsupported for the ARM architecture"); + report("Creating simple ARM process space."); + return new ARM_SimpleProcessSpace(); } } @@ -132,21 +97,21 @@ * Return as an integer the current instruction's address */ public int getCurrentInstructionAddress() { - return registers.getPC(); + return registers.read(ARM_Registers.PC); } /** * Sets the current instruction's address */ public void setCurrentInstructionAddress(int pc) { - registers.setPC(pc); + registers.write(ARM_Registers.PC, pc); } /** * Return as an integer the current instruction's address */ public int getCurrentStackAddress() { - throw new RuntimeException("Not yet implemented"); + return registers.read(14); } /** Modified: src/org/binarytranslator/arch/arm/os/process/ARM_Registers.java =================================================================== --- src/org/binarytranslator/arch/arm/os/process/ARM_Registers.java 2007-03-29 13:53:07 UTC (rev 14) +++ src/org/binarytranslator/arch/arm/os/process/ARM_Registers.java 2007-03-30 15:38:52 UTC (rev 15) @@ -1,7 +1,12 @@ package org.binarytranslator.arch.arm.os.process; +import org.jikesrvm.VM; + public final class ARM_Registers { + public final static int SP = 14; + public final static int PC = 15; + /** * The currently visible ARM general purpose registers. Register 15 also serves as the PC. */ @@ -58,7 +63,7 @@ /** * Definition of symbolic constants for all valid operating modes */ - public final static byte OPERATING_MODE_USER = 0x10; + public final static byte OPERATING_MODE_USR = 0x10; public final static byte OPERATING_MODE_FIQ = 0x11; public final static byte OPERATING_MODE_IRQ = 0x12; public final static byte OPERATING_MODE_SVC = 0x13; @@ -68,18 +73,16 @@ public ARM_Registers() { } - /** - * Sets the pc to a new value - */ - public void setPC(int pc) { - regs[15] = pc; + public int read(int reg) { + if (VM.VerifyAssertions) VM._assert(reg < 16); + + return regs[reg]; } - /** - * Sets the pc to a new value - */ - public int getPC() { - return regs[15]; + public void write(int reg, int value) { + if (VM.VerifyAssertions) VM._assert(reg < 16); + + regs[reg] = value; } /** Modified: src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java 2007-03-29 13:53:07 UTC (rev 14) +++ src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java 2007-03-30 15:38:52 UTC (rev 15) @@ -3,6 +3,8 @@ import org.binarytranslator.DBT_Options; import org.binarytranslator.arch.arm.os.abi.linux.ARM_LinuxSystemCalls; import org.binarytranslator.arch.arm.os.process.ARM_ProcessSpace; +import org.binarytranslator.arch.arm.os.process.ARM_Registers; +import org.binarytranslator.generic.gdbstub.GDBTarget; import org.binarytranslator.generic.os.abi.linux.LinuxStackInitializer; import org.binarytranslator.generic.os.abi.linux.LinuxSystemCallGenerator; import org.binarytranslator.generic.os.abi.linux.LinuxSystemCalls; @@ -16,6 +18,11 @@ private final LinuxSystemCalls sysCalls; /** + * A re-used iterator that allows enumerating the argument of the current system call + */ + private final ARM_SyscallArgumentIterator syscallArgs; + + /** * The top of the stack */ private static final int STACK_TOP = 0xC0000000; @@ -27,6 +34,7 @@ public ARM_LinuxProcessSpace() { sysCalls = new ARM_LinuxSystemCalls(this); + syscallArgs = new ARM_SyscallArgumentIterator(this); } @Override @@ -36,7 +44,7 @@ @Override public void initialise(Loader loader, int pc, int brk, String[] args) { - registers.setPC(pc); + registers.write(ARM_Registers.PC, pc); this.brk = brk; //initialize the stack @@ -66,15 +74,15 @@ return brk; } - public int[] getSysCallArguments(int n) { - // TODO Auto-generated method stub - return null; - } - public int getSysCallNumber() { // TODO Auto-generated method stub return 0; } + + public CallArgumentIterator getSysCallArguments() { + syscallArgs.reset(); + return syscallArgs; + } public void setBrk(int address) { brk = address; @@ -88,4 +96,10 @@ // TODO Auto-generated method stub } + @Override + public GDBTarget getGDBTarget() { + // TODO Auto-generated method stub + return null; + } + } Added: src/org/binarytranslator/arch/arm/os/process/linux/ARM_SyscallArgumentIterator.java =================================================================== --- src/org/binarytranslator/arch/arm/os/process/linux/ARM_SyscallArgumentIterator.java (rev 0) +++ src/org/binarytranslator/arch/arm/os/process/linux/ARM_SyscallArgumentIterator.java 2007-03-30 15:38:52 UTC (rev 15) @@ -0,0 +1,35 @@ +package org.binarytranslator.arch.arm.os.process.linux; + +import org.binarytranslator.generic.os.abi.linux.LinuxSystemCallGenerator; + +public class ARM_SyscallArgumentIterator implements LinuxSystemCallGenerator.CallArgumentIterator { + + private final ARM_LinuxProcessSpace ps; + private int currentArgument; + + public ARM_SyscallArgumentIterator(ARM_LinuxProcessSpace ps) { + this.ps = ps; + this.currentArgument = 0; + } + + public int nextInt() { + return ps.registers.read(currentArgument++); + } + + public long nextLong() { + // only start reading longs from even registers + if ((currentArgument & 1) == 1) + currentArgument++; + + //TODO: This code is actually assuming that we're on little endian + long lowWord = nextInt(); + long highWord = nextInt(); + + return highWord << 32 | lowWord; + } + + public void reset() { + currentArgument = 0; + } + +} Modified: src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java 2007-03-29 13:53:07 UTC (rev 14) +++ src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java 2007-03-30 15:38:52 UTC (rev 15) @@ -19,6 +19,7 @@ import org.binarytranslator.generic.os.process.ProcessSpace; import org.binarytranslator.generic.os.loader.Loader; import org.binarytranslator.generic.fault.BadInstructionException; +import org.binarytranslator.generic.gdbstub.GDBTarget; import org.binarytranslator.vmInterface.*; import java.util.*; import java.io.*; @@ -26,7 +27,7 @@ /** * Capture the running of a PowerPC process */ -public abstract class PPC_ProcessSpace extends ProcessSpace +public abstract class PPC_ProcessSpace extends ProcessSpace implements GDBTarget { /* Here's what would be in the PowerPC's registers if the binary were running on a real PowerPC. For speed I am using individual Modified: src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java 2007-03-29 13:53:07 UTC (rev 14) +++ src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java 2007-03-30 15:38:52 UTC (rev 15) @@ -11,6 +11,7 @@ import org.binarytranslator.DBT_Options; import org.binarytranslator.arch.ppc.os.process.PPC_ProcessSpace; import org.binarytranslator.arch.ppc.os.abi.linux.PPC_LinuxSystemCalls; +import org.binarytranslator.generic.gdbstub.GDBTarget; import org.binarytranslator.generic.os.abi.linux.LinuxStackInitializer; import org.binarytranslator.generic.os.abi.linux.LinuxSystemCallGenerator; import org.binarytranslator.generic.os.abi.linux.LinuxSystemCalls; @@ -29,6 +30,11 @@ * System calls object for handling system calls generated by this process */ final LinuxSystemCalls syscalls; + + /** + * Provides access to the single arguments of a system call. + */ + final PPC_LinuxSyscallArgumentIterator syscallArgs; /** * The top of the bss segment @@ -45,6 +51,7 @@ */ public PPC_LinuxProcessSpace(Loader loader) { syscalls = new PPC_LinuxSystemCalls(this); + syscallArgs = new PPC_LinuxSyscallArgumentIterator(this); } /** @@ -114,15 +121,12 @@ } /** * Create an array of arguments for the system call - * @param n number of system call arguments to read * @return array of system call argument values */ - public int[] getSysCallArguments(int n) { - int args[] = new int[n]; - for (int i=0; i < n; i++) { - args[i] = getRegister(3+i); - } - return args; + public CallArgumentIterator getSysCallArguments() { + + syscallArgs.reset(); + return syscallArgs; } /** @@ -158,4 +162,16 @@ brk = address; } + public GDBTarget getGDBTarget() { + return this; + } + + public int getGDBFrameBaseRegister() { + return -1; + } + + public boolean hasFrameBaseRegister() { + return false; + } + } Added: src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxSyscallArgumentIterator.java =================================================================== --- src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxSyscallArgumentIterator.java (rev 0) +++ src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxSyscallArgumentIterator.java 2007-03-30 15:38:52 UTC (rev 15) @@ -0,0 +1,54 @@ +package org.binarytranslator.arch.ppc.os.process.linux; + +import org.binarytranslator.generic.os.abi.linux.LinuxSystemCallGenerator; + +final class PPC_LinuxSyscallArgumentIterator implements LinuxSystemCallGenerator.CallArgumentIterator { + + /** + * That process space that this class is enumerating the arguments from. + */ + private final PPC_LinuxProcessSpace ps; + + /** + * The index of the argument that is fetched by the next call to next<datatype>() + */ + private int nextArgument; + + public PPC_LinuxSyscallArgumentIterator(PPC_LinuxProcessSpace ps) { + this.ps = ps; + this.nextArgument = 0; + } + + /** + * Return the next integer argument by reading it from a register, starting with GPR3. + */ + public int nextInt() { + return ps.getRegister(3 + nextArgument++); + } + + /** + * Returns the next long argument. + * This implementation follows the information on p. 3-19f of http://refspecs.freestandards.org/elf/elfspec_ppc.pdf + */ + public long nextLong() { + + //Start reading long arguments only from uneven registers + if ((nextArgument & 1) == 0) { + nextArgument++; + } + + long lowWord = nextInt(); + long highWord = nextInt(); + + return highWord << 32 | lowWord; + } + + /** + * We're actually reusing that class instead of initializing a new one each time syscall arguments are inspected. + * Therefore, this function starts iterating over all arguments anew. + */ + public void reset() { + nextArgument = 0; + } + +} Modified: src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java 2007-03-29 13:53:07 UTC (rev 14) +++ src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java 2007-03-30 15:38:52 UTC (rev 15) @@ -17,6 +17,7 @@ import org.binarytranslator.generic.os.process.ProcessSpace; import org.binarytranslator.generic.memory.ByteAddressedMemory; import org.binarytranslator.generic.fault.BadInstructionException; +import org.binarytranslator.generic.gdbstub.GDBTarget; import org.binarytranslator.arch.x86.os.process.linux.X86_LinuxProcessSpace; import org.binarytranslator.arch.x86.decoder.X862IR; import org.binarytranslator.generic.os.loader.Loader; @@ -24,7 +25,7 @@ /** * Encapsulate the parts of an X86 process that are common across operating systems */ -public abstract class X86_ProcessSpace extends ProcessSpace { +public abstract class X86_ProcessSpace extends ProcessSpace implements GDBTarget { /* * Process defaults @@ -104,6 +105,10 @@ public int getGDBProgramCountRegister() { return 8; } + + public GDBTarget getGDBTarget() { + return this; + } /* * Utility functions @@ -161,7 +166,7 @@ * Run a single instruction */ public void runOneInstruction() throws BadInstructionException { - // TODO + throw new UnsupportedOperationException("To be implemented"); } /** Modified: src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java 2007-03-29 13:53:07 UTC (rev 14) +++ src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java 2007-03-30 15:38:52 UTC (rev 15) @@ -12,6 +12,7 @@ import org.binarytranslator.generic.os.abi.linux.LinuxStackInitializer; import org.binarytranslator.generic.os.abi.linux.LinuxSystemCallGenerator; import org.binarytranslator.generic.os.abi.linux.LinuxSystemCalls; +import org.binarytranslator.generic.os.abi.linux.LinuxSystemCallGenerator.CallArgumentIterator; import org.binarytranslator.arch.x86.os.process.X86_ProcessSpace; import org.binarytranslator.arch.x86.os.process.X86_Registers; import org.binarytranslator.arch.x86.os.abi.linux.X86_LinuxSystemCalls; @@ -25,6 +26,11 @@ * System calls object for handling system calls generated by this process */ LinuxSystemCalls syscalls; + + /** + * Allows uniform access to the arguments of a system call. We cache this object for reuse. + */ + private final X86_LinuxSyscallArgumentIterator syscallArgs; /** * The top of the bss segment @@ -41,6 +47,7 @@ */ public X86_LinuxProcessSpace(Loader loader) { syscalls = new X86_LinuxSystemCalls(this); + syscallArgs = new X86_LinuxSyscallArgumentIterator(this); } /** @@ -97,22 +104,12 @@ return registers.readGP32(X86_Registers.EAX); } - public int[] getSysCallArguments(int n) { - int[] args = new int[n]; - if (n <= 6) { - int[] order = {X86_Registers.EBX, X86_Registers.ECX, X86_Registers.EDX, X86_Registers.ESI, X86_Registers.EDI, X86_Registers.EBP}; - - for (int i = 0; i < n; i++) { - args[i] = registers.readGP32(order[i]); - } - } else { - throw new Error("We should check this"); -// for (int i = 0; i < n; i++) { -// args[i] = memory.load32(registers.readGP32(X86_Registers.EBX) + (i * 4)); -// } - } - - return args; + /** + * Returns an interface to read the arguments of a system call. + */ + public CallArgumentIterator getSysCallArguments() { + syscallArgs.reset(); + return syscallArgs; } public void setSysCallReturn(int r) { Added: src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxSyscallArgumentIterator.java =================================================================== --- src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxSyscallArgumentIterator.java (rev 0) +++ src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxSyscallArgumentIterator.java 2007-03-30 15:38:52 UTC (rev 15) @@ -0,0 +1,37 @@ +package org.binarytranslator.arch.x86.os.process.linux; + +import org.binarytranslator.arch.x86.os.process.X86_Registers; +import org.binarytranslator.generic.os.abi.linux.LinuxSystemCallGenerator; +import org.jikesrvm.VM; + +public class X86_LinuxSyscallArgumentIterator implements LinuxSystemCallGenerator.CallArgumentIterator { + + private final static int[] order = {X86_Registers.EBX, X86_Registers.ECX, X86_Registers.EDX, X86_Registers.ESI, X86_Registers.EDI, X86_Registers.EBP}; + + private final X86_LinuxProcessSpace ps; + private int nextParameter; + + public X86_LinuxSyscallArgumentIterator(X86_LinuxProcessSpace ps) { + this.ps = ps; + this.nextParameter = 0; + } + + public int nextInt() { + if (VM.VerifyAssertions) VM._assert(nextParameter <= 6); + + return ps.registers.readGP32(order[nextParameter++]); + } + + public long nextLong() { + throw new UnsupportedOperationException("X86 System Calls do not support long arguments, yet."); + } + + /** + * We're actually reusing that class instead of initializing a new one each time syscall arguments are inspected. + * Therefore, this function starts iterating over all arguments anew. + */ + public void reset() { + nextParameter = 0; + } + +} Modified: src/org/binarytranslator/generic/gdbstub/GDBStub.java =================================================================== --- src/org/binarytranslator/generic/gdbstub/GDBStub.java 2007-03-29 13:53:07 UTC (rev 14) +++ src/org/binarytranslator/generic/gdbstub/GDBStub.java 2007-03-30 15:38:52 UTC (rev 15) @@ -40,7 +40,7 @@ /** * The process being debugged */ - private final ProcessSpace ps; + private final GDBTarget target; /** * Thread to continue or step, a value of -1 means all threads, 0 * means any thread. @@ -93,7 +93,7 @@ /** * Constructor */ - public GDBStub(int port, ProcessSpace ps) { + public GDBStub(int port, GDBTarget target) { try { ServerSocket connectionSocket = new ServerSocket(port); socket = connectionSocket.accept(); @@ -105,7 +105,7 @@ throw new Error("Error opening socket", e); } breakpoints = new int[0]; - this.ps = ps; + this.target = target; } /** @@ -228,14 +228,14 @@ // byte command[] = {'S','0','5'}; <- a command to just say stopped by SIGTRAP byte command[]; int index; - if (ps.hasFrameBaseRegister()) { + if (target.hasFrameBaseRegister()) { // Add base pointer to packet command = new byte[39]; - int bpReg = ps.getGDBFrameBaseRegister(); + int bpReg = target.getGDBFrameBaseRegister(); command[3] = intToHex(bpReg >> 4); command[4] = intToHex(bpReg); command[5] = ':'; - byte bpVal[] = ps.readRegisterGDB(bpReg); + byte bpVal[] = target.readRegisterGDB(bpReg); command[6] = intToHex(bpVal[0] >> 4); command[7] = intToHex(bpVal[0]); command[8] = intToHex(bpVal[1] >> 4); @@ -254,11 +254,11 @@ command[1] = '0'; command[2] = '5'; // stopped by trap { // Add stack pointer to packet - int spReg = ps.getGDBStackPointerRegister(); + int spReg = target.getGDBStackPointerRegister(); command[index] = intToHex(spReg >> 4); index++; command[index] = intToHex(spReg); index++; command[index] = ':'; index++; - byte spVal[] = ps.readRegisterGDB(spReg); + byte spVal[] = target.readRegisterGDB(spReg); command[index] = intToHex(spVal[0] >> 4); index++; command[index] = intToHex(spVal[0]); index++; command[index] = intToHex(spVal[1] >> 4); index++; @@ -270,11 +270,11 @@ command[index] = ';'; index++; } { // Add program counter to packet - int pcReg = ps.getGDBProgramCountRegister(); + int pcReg = target.getGDBProgramCountRegister(); command[index] = intToHex(pcReg >> 4); index++; command[index] = intToHex(pcReg); index++; command[index] = ':'; index++; - byte pcVal[] = ps.readRegisterGDB(pcReg); + byte pcVal[] = target.readRegisterGDB(pcReg); command[index] = intToHex(pcVal[0] >> 4); index++; command[index] = intToHex(pcVal[0]); index++; command[index] = intToHex(pcVal[1] >> 4); index++; @@ -357,7 +357,7 @@ } else { regNum = hexToInt(buffer[2]); } - byte value[] = ps.readRegisterGDB(regNum); + byte value[] = target.readRegisterGDB(regNum); byte hexValue[] = new byte[value.length * 2]; for(int i=0; i < value.length; i++) { hexValue[i*2] = intToHex(value[i] >> 4); @@ -378,7 +378,7 @@ try { byte value[] = new byte[count*2]; for(int i=0; i < count; i++) { - byte byteVal = ps.memoryLoad8(address+i); + byte byteVal = target.memoryLoad8(address+i); value[i*2] = intToHex(byteVal >> 4); value[(i*2)+1] = intToHex(byteVal); } @@ -401,7 +401,7 @@ byte value[] = new byte[2]; for(int i=0; i < count; i++) { byte byteVal = (byte)((hexToInt(buffer[start+(i*2)]) << 4) | (hexToInt(buffer[start+(i*2)+1]))); - ps.memoryStore8(address+i, byteVal); + target.memoryStore8(address+i, byteVal); } replyOK(); } catch (NullPointerException e) { @@ -444,7 +444,7 @@ // the next two optional characters specify the thread // to step, we have one thread so we ignore them try { - ps.runOneInstruction(); + target.runOneInstruction(); index = dataEnd; // report that a SIGTRAP halted the debugger sendStoppedByTrap(); @@ -461,9 +461,9 @@ try { boolean hitBreakpoint; do { - ps.runOneInstruction(); + target.runOneInstruction(); hitBreakpoint = false; - int pc = ps.getCurrentInstructionAddress(); + int pc = target.getCurrentInstructionAddress(); for(int i=0; i < breakpoints.length; i++) { if(pc == breakpoints[i]) { hitBreakpoint = true; Added: src/org/binarytranslator/generic/gdbstub/GDBTarget.java =================================================================== --- src/org/binarytranslator/generic/gdbstub/GDBTarget.java (rev 0) +++ src/org/binarytranslator/generic/gdbstub/GDBTarget.java 2007-03-30 15:38:52 UTC (rev 15) @@ -0,0 +1,53 @@ +package org.binarytranslator.generic.gdbstub; + +import org.binarytranslator.generic.fault.BadInstructionException; + +public interface GDBTarget { + /** + * Read a register from the target machine. + * + * @param regNum + * A register number, starting from 0. + */ + byte[] readRegisterGDB(int regNum); + + /** + * Run a single instruction + */ + void runOneInstruction() throws BadInstructionException; + + /** + * Has frame base register? + */ + boolean hasFrameBaseRegister(); + + /** + * Get the value of the frame base register + */ + int getGDBFrameBaseRegister(); + + /** + * Get the value of the frame base register + */ + int getGDBStackPointerRegister(); + + /** + * Get the value of the frame base register + */ + int getGDBProgramCountRegister(); + + /** + * Return the address of the current instruction. + */ + int getCurrentInstructionAddress(); + + /** + * Store the given bye of data at the given address within the process. + */ + void memoryStore8(int address, byte data); + + /** + * Load a byte from the given address within the process. + */ + byte memoryLoad8(int address); +} Modified: src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCallGenerator.java =================================================================== --- src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCallGenerator.java 2007-03-29 13:53:07 UTC (rev 14) +++ src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCallGenerator.java 2007-03-30 15:38:52 UTC (rev 15) @@ -15,7 +15,23 @@ * the memory and registers of various architectures. */ public interface LinuxSystemCallGenerator { + /** + * This interface allows you to iteratively grab all arguments to a system call. + */ + public interface CallArgumentIterator { + /** + * Interpret the next system call argument as an integer and return it. + */ + int nextInt(); + + /** + * Interpret the next system call argument as a long and return it. + */ + long nextLong(); + } + + /** * Return the system call number from the generator */ public int getSysCallNumber(); @@ -24,7 +40,7 @@ * @param n number of system call arguments to read * @return array of system call argument values */ - public int[] getSysCallArguments(int n); + public CallArgumentIterator getSysCallArguments(); /** * Set the return value for a system call * @param r the return value Modified: src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java =================================================================== --- src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java 2007-03-29 13:53:07 UTC (rev 14) +++ src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java 2007-03-30 15:38:52 UTC (rev 15) @@ -445,6 +445,14 @@ */ public abstract void doSysCall(); } + + abstract class ParameterizedSystemCall extends SystemCall { + protected LinuxSystemCallGenerator.CallArgumentIterator arguments; + + public ParameterizedSystemCall() { + arguments = src.getSysCallArguments(); + } + } /** * Unknown System Call @@ -466,11 +474,9 @@ /** * Exit system call */ - public class SysExit extends SystemCall { + public class SysExit extends ParameterizedSystemCall { public void doSysCall() { - int[] args = src.getSysCallArguments(1); - int status = args[0]; - + int status = arguments.nextInt(); System.exit(status); } } @@ -478,12 +484,11 @@ /** * Read from a file */ - public class SysRead extends SystemCall { + public class SysRead extends ParameterizedSystemCall { public void doSysCall() { - int[] args = src.getSysCallArguments(3); - int fd = args[0]; - int buf = args[1]; - int count = args[2]; + int fd = arguments.nextInt(); + int buf = arguments.nextInt(); + int count = arguments.nextInt(); if(fd == 0) { // read from stdin byte[] b = new byte[256]; @@ -528,12 +533,11 @@ /** * Write to a file */ - public class SysWrite extends SystemCall { + public class SysWrite extends ParameterizedSystemCall { public void doSysCall() { - int[] args = src.getSysCallArguments(3); - int fd = args[0]; - int buf = args[1]; - int count = args[2]; + int fd = arguments.nextInt(); + int buf = arguments.nextInt(); + int count = arguments.nextInt(); if(fd == 1) { // stdout for(int c = 0 ; c < count; c++) { @@ -579,12 +583,11 @@ /** * Write data into multiple buffers */ - public class SysWriteV extends SystemCall { - public void doSysCall() { - int[] args = src.getSysCallArguments(3); - int fd = args[0]; - int vector = args[1]; - int count = args[2]; + public class SysWriteV extends ParameterizedSystemCall { + public void doSysCall() { + int fd = arguments.nextInt(); + int vector = arguments.nextInt(); + int count = arguments.nextInt(); if((fd == 1)||(fd == 2)) { // stdout || stderr PrintStream out = (fd == 1) ? System.out : System.err; @@ -609,11 +612,10 @@ } } - public class SysOpen extends SystemCall { + public class SysOpen extends ParameterizedSystemCall { public void doSysCall() { - int[] args = src.getSysCallArguments(2); - int pathname = args[0]; - int flags = args[1]; + int pathname = arguments.nextInt(); + int flags = arguments.nextInt(); // Examine the flags argument and open read or read-write // accordingly. args[0] points to the file name. @@ -660,10 +662,9 @@ } } - public class SysClose extends SystemCall { + public class SysClose extends ParameterizedSystemCall { public void doSysCall() { - int[] args = src.getSysCallArguments(1); - int fd = args[0]; + int fd = arguments.nextInt(); RandomAccessFile raFile = getRAFile(fd); // Check that fd is a valid file descriptor if(raFile == null) { @@ -705,16 +706,17 @@ } } - public class SysBrk extends SystemCall { + public class SysBrk extends ParameterizedSystemCall { public void doSysCall() { - int args[] = src.getSysCallArguments(1); - if(args[0] == 0) { + int brk = arguments.nextInt(); + + if(brk == 0) { // Request for the current top of bss. src.setSysCallReturn(src.getBrk()); } else { // Changing the value. - src.setBrk(args[0]); + src.setBrk(brk); } } } @@ -724,13 +726,11 @@ } } - public class SysFcntl64 extends SystemCall { + public class SysFcntl64 extends ParameterizedSystemCall { public void doSysCall() { // This is complicated so fudge it for now. - int[] args = src.getSysCallArguments(2); - - int fd = args[0]; - int cmd = args[1]; + int fd = arguments.nextInt(); + int cmd = arguments.nextInt(); if( ((fd == 0) | (fd == 1) | (fd == 2)) & (cmd == 1) ) src.setSysCallReturn(0); @@ -739,11 +739,12 @@ } } - public class SysUname extends SystemCall { + public class SysUname extends ParameterizedSystemCall { public void doSysCall() { // Simple uname support - int[] args = src.getSysCallArguments(1); - if (args[0] != 0) { + int addr = arguments.nextInt(); + + if (addr != 0) { String localhostString, domainName, hostName; try { InetAddress localhost = InetAddress.getLocalHost(); @@ -762,12 +763,12 @@ hostName = localhostString.substring(0,index); } // Fill in utsname struct - see /usr/include/sys/utsname.h - src.memoryWriteString (args[0], getSysName()); // sysname - src.memoryWriteString (args[0]+65, hostName); // nodename - src.memoryWriteString (args[0]+130, getRelease()); // release - src.memoryWriteString (args[0]+195, getVersion()); // version - src.memoryWriteString (args[0]+260, getMachine()); // machine - src.memoryWriteString (args[0]+325, domainName); // __domainname + src.memoryWriteString (addr, getSysName()); // sysname + src.memoryWriteString (addr+65, hostName); // nodename + src.memoryWriteString (addr+130, getRelease()); // release + src.memoryWriteString (addr+195, getVersion()); // version + src.memoryWriteString (addr+260, getMachine()); // machine + src.memoryWriteString (addr+325, domainName); // __domainname src.setSysCallReturn(0); } else { @@ -777,15 +778,15 @@ } } - public class SysMmap extends SystemCall { + public class SysMmap extends ParameterizedSystemCall { public void doSysCall() { - int[] args = src.getSysCallArguments(6); - int start = args[0]; - int length = args[1]; - int prot = args[2]; - int flags = args[3]; - int fd = args[4]; - int offset = args[5]; + + int start = arguments.nextInt(); + int length = arguments.nextInt(); + int prot = arguments.nextInt(); + int flags = arguments.nextInt(); + int fd = arguments.nextInt(); + int offset = arguments.nextInt(); if((flags & mman.MAP_ANONYMOUS) != 0 ) { try { src.setSysCallReturn(src.memoryMap(start, length, @@ -802,20 +803,20 @@ } } - public class SysMunmap extends SystemCall { + public class SysMunmap extends ParameterizedSystemCall { public void doSysCall() { - int[] args = src.getSysCallArguments(2); - int start = args[0]; - int length = args[1]; + + int start = arguments.nextInt(); + int length = arguments.nextInt(); throw new Error("TODO!"); //src.setSysCallReturn(src.munmap(start, length)); } } - public class SysExitGroup extends SystemCall { + public class SysExitGroup extends ParameterizedSystemCall { public void doSysCall() { // For now, equivalent to SysExit - System.exit(src.getSysCallArguments(1)[0]); + System.exit(arguments.nextInt()); } } } Modified: src/org/binarytranslator/generic/os/loader/Loader.java =================================================================== --- src/org/binarytranslator/generic/os/loader/Loader.java 2007-03-29 13:53:07 UTC (rev 14) +++ src/org/binarytranslator/generic/os/loader/Loader.java 2007-03-30 15:38:52 UTC (rev 15) @@ -10,6 +10,7 @@ import org.binarytranslator.generic.os.process.ProcessSpace; import org.binarytranslator.generic.os.loader.elf.ELF_Loader; +import org.binarytranslator.generic.os.loader.image.ImageLoader; import org.binarytranslator.DBT_Options; import java.io.*; @@ -97,30 +98,19 @@ * @return a binaryloader to create a process */ public static Loader getLoader(String filename) throws IOException - { - File file = new File(filename); - RandomAccessFile rFile = new RandomAccessFile(file, "r"); - report("Opened file: " + filename); - - byte[] id = new byte[4]; - rFile.read(id); - report("Read ID"); - - if (isELF_Binary(id)) { + { + if (ELF_Loader.conforms(filename)) { report("ELF object file found"); return new ELF_Loader(); - } else { + } + else if (ImageLoader.conforms(filename)) { + report("Image Loader file found."); + return new ImageLoader(); + } + else { throw new Error("File " + filename + " has an unrecognized binary format"); } } - /** - * Determine if the id array corresponds with the initial part of an - * ELF binary - * @param id start of binary - * @return whether this is an ELF binary - */ - private static boolean isELF_Binary(byte[] id) { - return (id[0] == 0x7f) && (id[1] == 'E') && (id[2] == 'L') && (id[3] == 'F'); - } + } Modified: src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java =================================================================== --- src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java 2007-03-29 13:53:07 UTC (rev 14) +++ src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java 2007-03-30 15:38:52 UTC (rev 15) @@ -121,9 +121,8 @@ */ public ProcessSpace readBinary(String[] args) throws IOException { - File elfFile = new File(args[0]); - RandomAccessFile rFile = new RandomAccessFile(elfFile, "r"); - report("Opened File: " + elfFile); + report("Opening File: " + args[0]); + RandomAccessFile rFile = new RandomAccessFile(args[0], "r"); elfHeader = new ELF_Header(rFile); //NB also sets up reader report("ELF header read successfully"); @@ -154,6 +153,35 @@ return ps; } + + /** + * Determine if the id array corresponds with the initial part of an + * ELF binary + * @param filename Name of the file to check + * @return whether this is an ELF binary + */ + public static boolean conforms(String filename) { + + RandomAccessFile rFile = null; + report("Testing is file is ELF: " + filename); + + try { + rFile = new RandomAccessFile(filename, "r"); + byte[] id = new byte[4]; + rFile.read(id); + + return (id[0] == 0x7f) && (id[1] == 'E') && (id[2] == 'L') && (id[3] == 'F'); + } + catch (Exception e) { + return false; + } + finally { + try { + rFile.close(); + } + catch(Exception e) {} + } + } /** * Read and construct the program segment headers Added: src/org/binarytranslator/generic/os/loader/image/ImageLoader.java =================================================================== --- src/org/binarytranslator/generic/os/loader/image/ImageLoader.java (rev 0) +++ src/org/binarytranslator/generic/os/loader/image/ImageLoader.java 2007-03-30 15:38:52 UTC (rev 15) @@ -0,0 +1,156 @@ +package org.binarytranslator.generic.os.loader.image; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.io.UnsupportedEncodingException; + +import org.binarytranslator.DBT_Options; +import org.binarytranslator.generic.memory.MemoryMapException; +import org.binarytranslator.generic.os.loader.Loader; +import org.binarytranslator.generic.os.process.ProcessSpace; + +/** + * A very simple loader, that will load binary directly into memory and then start executing it from address 0. + * Actually, this is just a hack to the .bin file format to include some header information that tells us the + * architecture for this image. + * The file format is: + * [Identifier] <8 ASCII-CHARS> EXT_IMG\0 + * [File Version] <1 BYTE> 0x0 + * [Architecture ID] <4 ASCII-CHARS> <ARM|PPC|X86> \0 + * [Padding] <3 BYTE> + * [Image data] <BINARY-Data> <Assembly Code, to be loaded at addr #0> + * @author baerm + * + */ +public class ImageLoader extends Loader { + + private String architecture; + + @Override + public String getABIString() { + return null; + } + + @Override + public String getArchitectureString() { + return architecture; + } + + @Override + public boolean isARM_ABI() { + return false; + } + + @Override + public boolean isARM_ISA() { + return architecture.equals("ARM"); + } + + @Override + public boolean isLinuxABI() { + return false; + } + + @Override + public boolean isPPC_ISA() { + return architecture.equals("ISA"); + } + + @Override + public boolean isSysV_ABI() { + return false; + } + + @Override + public boolean isX86_ISA() { + return architecture.equals("X86"); + } + + /** + * Read from the given file and determine whether it contains the correct ID string for an + * ASM Loader file. + */ + private static boolean readAndCheckID(RandomAccessFile file) { + try { + byte[] ID = new byte[8]; + if (file.read(ID) != ID.length) + return false; + + return ID[0] == 'E' && ID[1] == 'X' && ID[2] == 'T' && ID[3] == '_' + && ID[4] == 'I' && ID[5] == 'M' && ID[6] == 'G' && ID[7] == 0; + } + catch (Exception e) { + return false; + } + } + + public ProcessSpace readBinary(String[] args) throws IOException { + + report("Reading: " + args[0]); + RandomAccessFile file = new RandomAccessFile(args[0], "r"); + + if (!readAndCheckID(file)) + throw new IOException("File does not contain the expected EXT_IMG ID string."); + + //check the file version. Currently, we only support one version anyway. + byte version = file.readByte(); + + if (version != 0) { + throw new IOException("Unsupported image file version."); + } + + byte[] architecture = new byte[3]; + if (file.read(architecture) != architecture.length) + throw new IOException("Unable to read architecture string."); + + //read the architecture string + this.architecture = new String(architecture, "ASCII"); + + //skip the double-word padding and the delimiter of the architecture string + //file.skipBytes(4); + + ProcessSpace ps = ProcessSpace.createProcessSpaceFromBinary(this); + + int fileAndMemSize = (int)file.length() - 16; + try { + ps.createSegment(file, 16, 0, fileAndMemSize, fileAndMemSize, true, true, true); + } + catch (MemoryMapException e) { + e.printStackTrace(); + return null; + } + + ps.initialise(this, 0, -1, args); + return ps; + } + + /** + * Checks if the given file is an ASM Loader file. + */ + public static boolean conforms(String filename) { + + report("Testing if file conforms: " + filename); + RandomAccessFile file = null; + + try { + //if the file contains the correct ID string, then we assume it to be an ASM loader file + file = new RandomAccessFile(filename, "r"); + return readAndCheckID(file); + } + catch (Exception e) { + return false; + } + finally { + try { + file.close(); + } + catch (Exception e) {} + } + } + + private static void report(String s){ + if (DBT_Options.debugLoader) { + System.out.print("Image Loader:"); + System.out.println(s); + } + } +} Modified: src/org/binarytranslator/generic/os/process/ProcessSpace.java =================================================================== --- src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-03-29 13:53:07 UTC (rev 14) +++ src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-03-30 15:38:52 UTC (rev 15) @@ -24,6 +24,7 @@ import org.binarytranslator.generic.memory.MemoryMapException; import org.binarytranslator.generic.fault.BadInstructionException; import org.binarytranslator.generic.gdbstub.GDBStub; +import org.binarytranslator.generic.gdbstub.GDBTarget; import org.binarytranslator.generic.os.loader.Loader; import org.binarytranslator.arch.x86.os.process.X86_ProcessSpace; import org.binarytranslator.arch.arm.os.process.ARM_ProcessSpace; @@ -191,8 +192,10 @@ * the generation context for the HIR generation * @return a HIR generator */ + public abstract OPT_HIRGenerator createHIRGenerator( - OPT_GenerationContext context); + OPT_GenerationContext context); + /** * Given an ELF binary loader, create the appropriate process space @@ -316,7 +319,7 @@ 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) { @@ -324,7 +327,7 @@ } return code; } - + private VM_CodeArray translateCode(DBT_Trace trace) { if (DBT_Options.debugRuntime) { report("Translating code for 0x" + Integer.toHexString(trace.pc)); @@ -334,6 +337,8 @@ replaceCompiledTrace(cm, trace); return cm.getEntryCodeArray(); } + + /* /** * Record a branch instruction @@ -415,7 +420,7 @@ System.out.println(e.toString()); } } else { - GDBStub gdbStub = new GDBStub(DBT_Options.gdbStubPort, this); + GDBStub gdbStub = new GDBStub(DBT_Options.gdbStubPort, getGDBTarget()); gdbStub.run(); } } @@ -474,40 +479,9 @@ * DataInputStream(printenv.getInputStream()); variables.readUTF(); } */ } - - /* GDB stub interface */ + /** - * Read a register and turn into a byte array conforming to the endianness of - * the architecture + * Return an interface that allows GDB to read from this process */ - public abstract byte[] readRegisterGDB(int regNum); - - /** - * Run a single instruction - */ - public abstract void runOneInstruction() throws BadInstructionException; - - /** - * Has frame base register? - */ - public boolean hasFrameBaseRegister() { - return false; - } - - /** - * Get the value of the frame base register - */ - public int getGDBFrameBaseRegister() { - return -1; - } - - /** - * Get the value of the frame base register - */ - public abstract int getGDBStackPointerRegister(); - - /** - * Get the value of the frame base register - */ - public abstract int getGDBProgramCountRegister(); + public abstract GDBTarget getGDBTarget(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mic...@us...> - 2007-03-29 13:54:53
|
Revision: 14 http://svn.sourceforge.net/pearcolator/?rev=14&view=rev Author: michael_baer Date: 2007-03-29 06:53:07 -0700 (Thu, 29 Mar 2007) Log Message: ----------- Loading ARM ELF binaries Modified Paths: -------------- src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java src/org/binarytranslator/generic/os/loader/Loader.java src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java src/org/binarytranslator/generic/os/process/ProcessSpace.java Added Paths: ----------- src/org/binarytranslator/arch/arm/ src/org/binarytranslator/arch/arm/os/ src/org/binarytranslator/arch/arm/os/abi/ src/org/binarytranslator/arch/arm/os/abi/linux/ src/org/binarytranslator/arch/arm/os/abi/linux/ARM_LinuxSystemCalls.java src/org/binarytranslator/arch/arm/os/process/ src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java src/org/binarytranslator/arch/arm/os/process/ARM_Registers.java src/org/binarytranslator/arch/arm/os/process/linux/ src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java Added: src/org/binarytranslator/arch/arm/os/abi/linux/ARM_LinuxSystemCalls.java =================================================================== --- src/org/binarytranslator/arch/arm/os/abi/linux/ARM_LinuxSystemCalls.java (rev 0) +++ src/org/binarytranslator/arch/arm/os/abi/linux/ARM_LinuxSystemCalls.java 2007-03-29 13:53:07 UTC (rev 14) @@ -0,0 +1,23 @@ +package org.binarytranslator.arch.arm.os.abi.linux; + +import org.binarytranslator.generic.os.abi.linux.LinuxSystemCallGenerator; +import org.binarytranslator.generic.os.abi.linux.LinuxSystemCalls; + +public class ARM_LinuxSystemCalls extends LinuxSystemCalls { + + public ARM_LinuxSystemCalls(LinuxSystemCallGenerator src) { + super(src); + } + + @Override + protected String getMachine() { + //TODO: Grab this from a real machine + return "ARM"; + } + + @Override + public String sysCallToString(int syscall) { + throw new RuntimeException("Not yet implemented."); + } + +} Added: src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java (rev 0) +++ src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java 2007-03-29 13:53:07 UTC (rev 14) @@ -0,0 +1,158 @@ +package org.binarytranslator.arch.arm.os.process; + +import java.io.IOException; +import org.jikesrvm.opt.ir.OPT_HIRGenerator; +import org.jikesrvm.opt.ir.OPT_GenerationContext; +import org.binarytranslator.DBT_Options; +import org.binarytranslator.arch.arm.os.process.linux.ARM_LinuxProcessSpace; +import org.binarytranslator.arch.x86.decoder.X862IR; +import org.binarytranslator.arch.x86.os.process.X86_Registers; +import org.binarytranslator.arch.x86.os.process.linux.X86_LinuxProcessSpace; +import org.binarytranslator.generic.fault.BadInstructionException; +import org.binarytranslator.generic.memory.ByteAddressedMemory; +import org.binarytranslator.generic.os.loader.Loader; +import org.binarytranslator.generic.os.process.ProcessSpace; + +public abstract class ARM_ProcessSpace extends ProcessSpace { + + /* + * Instance data + */ + + /** + * Registers used by this process + */ + public ARM_Registers registers; + + /* GDB Interface */ + /** + * Read a register and turn into a byte array conforming to the endianness of + * the architecture + */ + public byte[] readRegisterGDB(int regNum) { + throw new RuntimeException("Not yet implemented"); + } + + /** + * Has frame base register? + */ + public boolean hasFrameBaseRegister() { + throw new RuntimeException("Not yet implemented"); + } + + /** + * Get the value of the frame base register + */ + public int getGDBFrameBaseRegister() { + throw new RuntimeException("Not yet implemented"); + } + + /** + * Get the value of the frame base register + */ + public int getGDBStackPointerRegister() { + throw new RuntimeException("Not yet implemented"); + } + + /** + * Get the value of the frame base register + */ + public int getGDBProgramCountRegister() { + throw new RuntimeException("Not yet implemented"); + } + + /* + * Utility functions + */ + + /** + * Debug information + * + * @param s + * string of debug information + */ + private static void report(String s) { + if (DBT_Options.debugLoader) { + System.out.print("ARM ProcessSpace:"); + System.out.println(s); + } + } + + /* + * Methods + */ + + /** + * Constructor + */ + protected ARM_ProcessSpace() { + registers = new ARM_Registers(); + memory = new ByteAddressedMemory(); + } + + /** + * Create an optimizing compiler HIR code generator suitable for this + * architecture + * + * @param context + * the generation context for the HIR generation + * @return a HIR generator + */ + public OPT_HIRGenerator createHIRGenerator(OPT_GenerationContext context) { + throw new RuntimeException("Not yet implemented"); + } + + /** + * Given an ELF binary loader, create the appropriate process space + * + * @param elf + * the elf binary loader + * @return the appropriate process space + */ + public static ProcessSpace createProcessSpaceFromBinary(Loader loader) + throws IOException { + if (loader.isARM_ABI()) { + report("ARM ABI"); + return new ARM_LinuxProcessSpace(); + } else { + throw new UnsupportedOperationException("Binary of " + loader.getABIString() + + " ABI is unsupported for the ARM architecture"); + } + } + + /** + * Run a single instruction + */ + public void runOneInstruction() throws BadInstructionException { + // TODO + throw new RuntimeException("Not yet implemented"); + } + + /** + * Return as an integer the current instruction's address + */ + public int getCurrentInstructionAddress() { + return registers.getPC(); + } + + /** + * Sets the current instruction's address + */ + public void setCurrentInstructionAddress(int pc) { + registers.setPC(pc); + } + + /** + * Return as an integer the current instruction's address + */ + public int getCurrentStackAddress() { + throw new RuntimeException("Not yet implemented"); + } + + /** + * Turn the process space into a string (for debug) + */ + public String toString() { + return registers.toString(); + } +} Added: src/org/binarytranslator/arch/arm/os/process/ARM_Registers.java =================================================================== --- src/org/binarytranslator/arch/arm/os/process/ARM_Registers.java (rev 0) +++ src/org/binarytranslator/arch/arm/os/process/ARM_Registers.java 2007-03-29 13:53:07 UTC (rev 14) @@ -0,0 +1,108 @@ +package org.binarytranslator.arch.arm.os.process; + +public final class ARM_Registers { + + /** + * The currently visible ARM general purpose registers. Register 15 also serves as the PC. + */ + private int regs[] = new int[16]; + + /** + * The ARM features a number of shadow registers, that are mapped into the register map + * depending on the operating mode. It contains + * 8 registers for fast IRQ handlers + * 3 registers for SWI handlers + * 3 registers for abort handlers + * 3 registers for irq handlers + * 3 registers for undefined instruction handlers + * 8 registers for temporarely storing the user mode registers during non-user modes + */ + private int shadowRegisters[] = new int[28]; + + /** + * The negative flag from the CPSR. + */ + private boolean flagNegative = false; + + /** + * The zero flag from the CPSR. + */ + private boolean flagZero = false; + + /** + * The carry flag from the CPSR. + */ + private boolean flagCarry = false; + + /** + * The overflow flag from the CPSR. + */ + private boolean flagOverflow = false; + + /** + * This flag from the CPSR denotes whether IRQs are currently accepted by the processor. + */ + private boolean flagIRQsDisabled = false; + + /** + * This flag from the CPSR denotes whether FIQs are currently accepted by the processor. + */ + private boolean flagFIQsDisabled = false; + + /** + * The operating mode from the CPSR register. Note that only the bottom five bits of this + * register may ever be set. + */ + private byte operatingMode = OPERATING_MODE_SVC; + + /** + * Definition of symbolic constants for all valid operating modes + */ + public final static byte OPERATING_MODE_USER = 0x10; + public final static byte OPERATING_MODE_FIQ = 0x11; + public final static byte OPERATING_MODE_IRQ = 0x12; + public final static byte OPERATING_MODE_SVC = 0x13; + public final static byte OPERATING_MODE_ABT = 0x17; + public final static byte OPERATING_MODE_UND = 0x1A; + + public ARM_Registers() { + } + + /** + * Sets the pc to a new value + */ + public void setPC(int pc) { + regs[15] = pc; + } + + /** + * Sets the pc to a new value + */ + public int getPC() { + return regs[15]; + } + + /** + * Returns the content of ARM's Current Program Status Register. + * @return + */ + public int getCPSR() { + return (flagNegative ? 1 << 31 : 0) | + (flagZero ? 1 << 30 : 0) | + (flagCarry ? 1 << 29 : 0) | + (flagOverflow ? 1 << 28 : 0) | + (flagIRQsDisabled ? 1 << 7 : 0) | + (flagFIQsDisabled ? 1 << 6 : 0) | + operatingMode; + } + + /** + * Restores the processor state to the state saved within the given CPSR. + * @param cpsr + * ARM CPSR register content + */ + private void setFlagsFromCPSR(int cpsr) { + throw new RuntimeException("Not yet implemented."); + } + +} Added: src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java (rev 0) +++ src/org/binarytranslator/arch/arm/os/process/linux/ARM_LinuxProcessSpace.java 2007-03-29 13:53:07 UTC (rev 14) @@ -0,0 +1,91 @@ +package org.binarytranslator.arch.arm.os.process.linux; + +import org.binarytranslator.DBT_Options; +import org.binarytranslator.arch.arm.os.abi.linux.ARM_LinuxSystemCalls; +import org.binarytranslator.arch.arm.os.process.ARM_ProcessSpace; +import org.binarytranslator.generic.os.abi.linux.LinuxStackInitializer; +import org.binarytranslator.generic.os.abi.linux.LinuxSystemCallGenerator; +import org.binarytranslator.generic.os.abi.linux.LinuxSystemCalls; +import org.binarytranslator.generic.os.loader.Loader; + +public class ARM_LinuxProcessSpace extends ARM_ProcessSpace implements LinuxSystemCallGenerator { + + /** + * A link to the current system call interface + */ + private final LinuxSystemCalls sysCalls; + + /** + * The top of the stack + */ + private static final int STACK_TOP = 0xC0000000; + + /** + * The top of the bss segment + */ + private int brk; + + public ARM_LinuxProcessSpace() { + sysCalls = new ARM_LinuxSystemCalls(this); + } + + @Override + public void doSysCall() { + sysCalls.doSysCall(); + } + + @Override + public void initialise(Loader loader, int pc, int brk, String[] args) { + registers.setPC(pc); + this.brk = brk; + + //initialize the stack + int[] auxVector = {LinuxStackInitializer.AuxiliaryVectorType.AT_SYSINFO, 0xffffe400, + LinuxStackInitializer.AuxiliaryVectorType.AT_SYSINFO_EHDR, 0xffffe000, + LinuxStackInitializer.AuxiliaryVectorType.AT_HWCAP, 0x78bfbff, + LinuxStackInitializer.AuxiliaryVectorType.AT_PAGESZ, 0x1000, + LinuxStackInitializer.AuxiliaryVectorType.AT_CLKTCK, 0x64, + LinuxStackInitializer.AuxiliaryVectorType.AT_PHDR, 0xBADADD8E, + LinuxStackInitializer.AuxiliaryVectorType.AT_PHNUM, 0xBAD2BAD2, + LinuxStackInitializer.AuxiliaryVectorType.AT_BASE, 0x0, + LinuxStackInitializer.AuxiliaryVectorType.AT_FLAGS, 0x0, + LinuxStackInitializer.AuxiliaryVectorType.AT_ENTRY, pc, + + LinuxStackInitializer.AuxiliaryVectorType.AT_UID, DBT_Options.UID, + LinuxStackInitializer.AuxiliaryVectorType.AT_EUID, DBT_Options.UID, + LinuxStackInitializer.AuxiliaryVectorType.AT_GID, DBT_Options.GID, + LinuxStackInitializer.AuxiliaryVectorType.AT_EGID, DBT_Options.GID, + + LinuxStackInitializer.AuxiliaryVectorType.AT_SECURE, 0, + LinuxStackInitializer.AuxiliaryVectorType.AT_NULL, 0x0}; + + LinuxStackInitializer.stackInit(memory, STACK_TOP, args, getEnvironmentVariables(), auxVector); + } + + public int getBrk() { + return brk; + } + + public int[] getSysCallArguments(int n) { + // TODO Auto-generated method stub + return null; + } + + public int getSysCallNumber() { + // TODO Auto-generated method stub + return 0; + } + + public void setBrk(int address) { + brk = address; + } + + public void setSysCallError(int r) { + // TODO Auto-generated method stub + } + + public void setSysCallReturn(int r) { + // TODO Auto-generated method stub + } + +} Modified: src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java =================================================================== --- src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java 2007-03-28 13:09:58 UTC (rev 13) +++ src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java 2007-03-29 13:53:07 UTC (rev 14) @@ -4623,6 +4623,7 @@ * Also modifies XER[CA]. */ protected int translateXO_FORM(PPC2IR ppc2ir, PPC_Laziness lazy, int pc, int inst, int opcode, int rD, int rA, int rB, int OE, int secondaryOpcode, int Rc) { + if (VM.VerifyAssertions) VM._assert(rB == 0); // Get rA & rD OPT_RegisterOperand reg_rA = ppc2ir.getGPRegister(rA); Modified: src/org/binarytranslator/generic/os/loader/Loader.java =================================================================== --- src/org/binarytranslator/generic/os/loader/Loader.java 2007-03-28 13:09:58 UTC (rev 13) +++ src/org/binarytranslator/generic/os/loader/Loader.java 2007-03-29 13:53:07 UTC (rev 14) @@ -65,6 +65,11 @@ * Is the binary for the Power PC ISA? */ abstract public boolean isPPC_ISA(); + + /** + * Is the binary for the ARM ISA? + */ + abstract public boolean isARM_ISA(); /** * Does this file support the SysV ABI? @@ -75,6 +80,11 @@ * Does this file support the Linux ABI? */ abstract public boolean isLinuxABI(); + + /** + * Does this file support the ARM ABI? + */ + abstract public boolean isARM_ABI(); /* * Static methods Modified: src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java =================================================================== --- src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java 2007-03-28 13:09:58 UTC (rev 13) +++ src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java 2007-03-29 13:53:07 UTC (rev 14) @@ -192,6 +192,13 @@ public boolean isPPC_ISA() { return elfHeader.isPPC_ISA(); } + + /** + * Is this binary for the ARM architecture? + */ + public boolean isARM_ISA() { + return elfHeader.isARM_ISA(); + } /** * Does this file support the SysV ABI? @@ -205,6 +212,14 @@ public boolean isLinuxABI() { return elfHeader.isLinuxABI(); } + + /** + * Does this file support the ARM ABI? + * @return + */ + public boolean isARM_ABI() { + return elfHeader.isARM_ABI(); + } /* * Local classes holding structures from the ELF file @@ -341,7 +356,13 @@ * Hewlett-Packard Non-Stop Kernel */ private static final byte ELFOSABI_NSK = 14; + /** + * ARM ABI, probably using the ARM AAPCS. + */ + private static final byte ELFOSABI_ARM = 97; + + /** * Return the application binary interface (ABI) supported by this file */ String getABIString() { @@ -359,6 +380,7 @@ case ELFOSABI_OPENBSD: return "OpenBSD"; case ELFOSABI_OPENVMS: return "OpenVMS"; case ELFOSABI_NSK: return "Hewlett-Packard Non-Stop Kernel"; + case ELFOSABI_ARM: return "ARM ABI"; default: return "Unknown ELF ABI: " + e_ident[EI_OSABI]; } @@ -375,6 +397,11 @@ boolean isLinuxABI() { return e_ident[EI_OSABI] == ELFOSABI_LINUX; } + + boolean isARM_ABI() { + return e_ident[EI_OSABI] == ELFOSABI_ARM; + } + /** * Location of OS ABI version data */ @@ -424,6 +451,13 @@ boolean isLinuxABI() { return identity.isLinuxABI(); } + + /** + * Does this file support the ARM ABI? + */ + boolean isARM_ABI() { + return identity.isARM_ABI(); + } /** * Object file type @@ -537,6 +571,13 @@ } /** + * Is the elf binary for an ARM architecture? + */ + boolean isARM_ISA() { + return e_machine == EM_ARM; + } + + /** * Return the architecture (ISA) supported by this file */ public String getArchitectureString() { Modified: src/org/binarytranslator/generic/os/process/ProcessSpace.java =================================================================== --- src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-03-28 13:09:58 UTC (rev 13) +++ src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-03-29 13:53:07 UTC (rev 14) @@ -26,436 +26,488 @@ import org.binarytranslator.generic.gdbstub.GDBStub; import org.binarytranslator.generic.os.loader.Loader; import org.binarytranslator.arch.x86.os.process.X86_ProcessSpace; +import org.binarytranslator.arch.arm.os.process.ARM_ProcessSpace; import org.binarytranslator.arch.ppc.os.process.PPC_ProcessSpace; /** - * A process space encapsulates a running process. This superclass - * contains non operating and architecture specific details of the - * process. + * 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 - */ + * Runtime information + */ /** - * A record of branches to guide translation - */ + * A record of branches to guide translation + */ public final BranchLogic branchInfo; /** - * A hashtable containing translated traces of code - */ + * A hashtable containing translated traces of code + */ protected final Hashtable codeHash = new Hashtable(); /** - * Has a system call been called to terminate the process - */ + * Has a system call been called to terminate the process + */ public boolean finished = false; /* - * Interface to memory - */ + * Interface to memory + */ /** - * The memory for the process. As this is user mode code, it is a - * virtual address space - */ + * The memory for the process. As this is user mode code, it is a virtual + * address space + */ public Memory memory; /** - * Load a 32bit value from memory - */ + * Load a 32bit value from memory + */ public int memoryLoad32(int wordAddr) { - return memory.load32(wordAddr); + return memory.load32(wordAddr); } + /** - * Store a 32bit value to memory - */ + * Store a 32bit value to memory + */ public void memoryStore32(int address, int data) { - memory.store32(address,data); + memory.store32(address, data); } - + /** - * Load a 16bit value from memory - */ + * Load a 16bit value from memory + */ public int memoryLoad16(int hwAddr) { - return memory.loadSigned16(hwAddr); + return memory.loadSigned16(hwAddr); } + /** - * Store a 16bit value to memory - */ + * Store a 16bit value to memory + */ public void memoryStore16(int hwAddr, int iValue) { - memory.store16(hwAddr,iValue); + memory.store16(hwAddr, iValue); } /** - * Load a 8bit value from memory - */ + * Load a 8bit value from memory + */ public byte memoryLoad8(int address) { - return (byte)memory.loadSigned8(address); + return (byte) memory.loadSigned8(address); } + /** - * Store a 8bit value to memory - */ + * Store a 8bit value to memory + */ public void memoryStore8(int address, byte data) { - memory.store8(address, data); + memory.store8(address, data); } /** - * Read an ASCIIZ string from the process' memory into a Java String - */ + * Read an ASCIIZ string from the process' memory into a Java String + */ public String memoryReadString(int address) { - StringBuffer str = new StringBuffer(); - char c; - - while( (c = (char)memoryLoad8(address++)) != 0 ) - str.append(c); - - return str.toString(); + StringBuffer str = new StringBuffer(); + char c; + + while ((c = (char) memoryLoad8(address++)) != 0) + str.append(c); + + return str.toString(); } /** - * Write a Java string (crudely) to an ASCIIZ string in the process' - * memory - */ + * Write a Java string (crudely) to an ASCIIZ string in the process' memory + */ public void memoryWriteString(int byteAddr, String value) { - if (value != null) { - for(int i=0; i < value.length(); i++) { - memoryStore8(byteAddr+i, (byte)value.charAt(i)); - } - memoryStore8(byteAddr+value.length(), (byte)0); - } + if (value != null) { + for (int i = 0; i < value.length(); i++) { + memoryStore8(byteAddr + i, (byte) value.charAt(i)); + } + memoryStore8(byteAddr + value.length(), (byte) 0); + } } /** * Map an anonymous page of memory - * @param addr the address to map or NULL if don't care - * @param len the amount of memory to map - * @param read is the page readable - * @param write is the page writable - * @param exec is the page executable + * + * @param addr + * the address to map or NULL if don't care + * @param len + * the amount of memory to map + * @param read + * is the page readable + * @param write + * is the page writable + * @param exec + * is the page executable */ - public int memoryMap(int addr, int len, boolean read, boolean write, boolean exec) throws MemoryMapException - { - return memory.map(addr, len, read, write, exec); + public int memoryMap(int addr, int len, boolean read, boolean write, + boolean exec) throws MemoryMapException { + return memory.map(addr, len, read, write, exec); } /** - * Simulate an munmap system call. - * @param start start of memory area to unmap. - * @param length length of area. - */ - public int munmap(int start, int length) - { - memory.unmap(start,length); - return 0; + * Simulate an munmap system call. + * + * @param start + * start of memory area to unmap. + * @param length + * length of area. + */ + public int munmap(int start, int length) { + memory.unmap(start, length); + return 0; } /* - * Utility functions - */ + * Utility functions + */ /** - * Debug information - * @param s string of debug information - */ - private static void report(String s){ - if (DBT_Options.debugLoader) { - System.out.print("ProcessSpace:"); - System.out.println(s); - } + * Debug information + * + * @param s + * string of debug information + */ + private static void report(String s) { + if (DBT_Options.debugLoader) { + System.out.print("ProcessSpace:"); + System.out.println(s); + } } /* - * Methods - */ + * Methods + */ /** - * Create an optimizing compiler HIR code generator suitable for a - * particular architecture - * @param context the generation context for the HIR generation - * @return a HIR generator - */ - public abstract OPT_HIRGenerator createHIRGenerator(OPT_GenerationContext context); + * Create an optimizing compiler HIR code generator suitable for a particular + * architecture + * + * @param context + * the generation context for the HIR generation + * @return a HIR generator + */ + public abstract OPT_HIRGenerator createHIRGenerator( + OPT_GenerationContext context); /** - * Given an ELF binary loader, create the appropriate process space - * @param elf the elf binary loader - * @return the appropriate process space - */ - public static ProcessSpace createProcessSpaceFromBinary (Loader loader) throws IOException { - ProcessSpace result; - if (loader.isX86_ISA()) { - report("X86 ELF Binary"); - result = X86_ProcessSpace.createProcessSpaceFromBinary(loader); - } - else if(loader.isPPC_ISA()){ - report("PPC ELF Binary"); - result = PPC_ProcessSpace.createProcessSpaceFromBinary(loader); - } - else { - throw new IOException("Binary of " + loader.getArchitectureString() + " architecture is unsupported"); - } - return result; + * Given an ELF binary loader, create the appropriate process space + * + * @param elf + * the elf binary loader + * @return the appropriate process space + */ + public static ProcessSpace createProcessSpaceFromBinary(Loader loader) + throws IOException { + ProcessSpace result; + if (loader.isX86_ISA()) { + report("X86 ELF Binary"); + result = X86_ProcessSpace.createProcessSpaceFromBinary(loader); + } else if (loader.isPPC_ISA()) { + report("PPC ELF Binary"); + result = PPC_ProcessSpace.createProcessSpaceFromBinary(loader); + } else if (loader.isARM_ISA()) { + report("ARM ELF Binary"); + result = ARM_ProcessSpace.createProcessSpaceFromBinary(loader); + } else { + throw new UnsupportedOperationException("Binary of " + loader.getArchitectureString() + + " architecture is unsupported"); + } + return result; } + /** - * Create a segment - * @param RandomAccessFile file to read segment data from if file size != 0 - * @param offset file offset - * @param address location of segment - * @param filesize size of segment in file - * @param memsize size of segment in memory - * @param read is segment readable - * @param write is segment writable - * @param exec is segment executable - */ - public void createSegment(RandomAccessFile file, - long offset, - int address, - int filesize, - int memsize, - boolean read, - boolean write, - boolean exec) throws MemoryMapException { - // Sanity check - if (memsize < filesize) { - throw new Error("Segment memory size (" + memsize + ")less than file size (" + filesize + ")"); - } - // Are we mapping anything from a file? - if(filesize == 0) { - // No: map anonymously - memory.map(address, memsize, read, write, exec); - } - else { - // align offset and address - int alignedAddress; - long alignedOffset; - int alignedFilesize; - if (memory.isPageAligned(address)) { - // memory and therefore offset should be aligned - alignedAddress = address; - alignedOffset = offset; - alignedFilesize = filesize; - } - else { - // Address not aligned - alignedAddress = memory.truncateToPage(address); - int delta = address - alignedAddress; - // adjust offset and length too - alignedOffset = offset - delta; - alignedFilesize = filesize + delta; - } - memory.map(file, alignedOffset, alignedAddress, alignedFilesize, read, write, exec); - // Do we need to map in some blank pages at the end of the segment? - if (filesize < memsize) { - alignedAddress = memory.truncateToNextPage(address + filesize); - memory.map(alignedAddress, memsize-filesize, read, write, exec); - } - } + * Create a segment + * + * @param RandomAccessFile + * file to read segment data from if file size != 0 + * @param offset + * file offset + * @param address + * location of segment + * @param filesize + * size of segment in file + * @param memsize + * size of segment in memory + * @param read + * is segment readable + * @param write + * is segment writable + * @param exec + * is segment executable + */ + public void createSegment(RandomAccessFile file, long offset, int address, + int filesize, int memsize, boolean read, boolean write, boolean exec) + throws MemoryMapException { + // Sanity check + if (memsize < filesize) { + throw new Error("Segment memory size (" + memsize + + ")less than file size (" + filesize + ")"); + } + // Are we mapping anything from a file? + if (filesize == 0) { + // No: map anonymously + memory.map(address, memsize, read, write, exec); + } else { + // align offset and address + int alignedAddress; + long alignedOffset; + int alignedFilesize; + if (memory.isPageAligned(address)) { + // memory and therefore offset should be aligned + alignedAddress = address; + alignedOffset = offset; + alignedFilesize = filesize; + } else { + // Address not aligned + alignedAddress = memory.truncateToPage(address); + int delta = address - alignedAddress; + // adjust offset and length too + alignedOffset = offset - delta; + alignedFilesize = filesize + delta; + } + memory.map(file, alignedOffset, alignedAddress, alignedFilesize, read, + write, exec); + // Do we need to map in some blank pages at the end of the segment? + if (filesize < memsize) { + alignedAddress = memory.truncateToNextPage(address + filesize); + memory.map(alignedAddress, memsize - filesize, read, write, exec); + } + } } /** - * Initialise the process space - * @param loader the loader that's created the process space - * @param pc the entry point - * @param brk the initial value for the top of BSS - * @param args command line arguments - */ + * Initialise the process space + * + * @param loader + * the loader that's created the process space + * @param pc + * the entry point + * @param brk + * the initial value for the top of BSS + * @param args + * command line arguments + */ public abstract void initialise(Loader loader, int pc, int brk, String args[]); /** - * Constructor - */ + * Constructor + */ protected ProcessSpace() { - branchInfo = new BranchLogic(); + branchInfo = new BranchLogic(); } /** - * Constructor - */ + * Constructor + */ public ProcessSpace(String[] args) throws IOException { - branchInfo = new BranchLogic(); + 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); + * 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; + 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(); + 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); + public void recordUncaughtBranch(int location, int destination, int code) { + branchInfo.registerBranch(location, destination, code); } /** - * Return as an integer the current instruction's address - */ + * Return as an integer the current instruction's address + */ public abstract int getCurrentInstructionAddress(); + /** - * Sets the current instruction's address - */ + * Sets the current instruction's address + */ public abstract void setCurrentInstructionAddress(int pc); + /** - * Return as an integer the current instruction's address - */ + * Return as an integer the current instruction's address + */ public abstract int getCurrentStackAddress(); + /** - * Print the stack - * @param words how many words to print from the stack - */ + * Print the stack + * + * @param words + * how many words to print from the stack + */ public void dumpStack(int words) { - int stackPtr = getCurrentStackAddress(); - for(int i=0; i < words; i++) { - if((i % 4) == 0) { - if(i != 0) { - System.out.println(); - } - System.out.print("0x" + Integer.toHexString(stackPtr)+":"); - } - String hexValue = Integer.toHexString(memory.load32(stackPtr)); - System.out.print(" 0x"); - for(int j=0; j < (8-hexValue.length()); j++) { - System.out.print("0"); - } - System.out.print(hexValue); - stackPtr+=4; - } - System.out.println(); + int stackPtr = getCurrentStackAddress(); + for (int i = 0; i < words; i++) { + if ((i % 4) == 0) { + if (i != 0) { + System.out.println(); + } + System.out.print("0x" + Integer.toHexString(stackPtr) + ":"); + } + String hexValue = Integer.toHexString(memory.load32(stackPtr)); + System.out.print(" 0x"); + for (int j = 0; j < (8 - hexValue.length()); j++) { + System.out.print("0"); + } + System.out.print(hexValue); + stackPtr += 4; + } + System.out.println(); } + /** - * Runtime loop, goes through the binary and looks in the Hashtable - * codeHash to see if we have already translated/compiled this piece - * of code, if not it is compiled. The compiled code is then run. + * Runtime loop, goes through the binary and looks in the Hashtable codeHash + * to see if we have already translated/compiled this piece of code, if not it + * is compiled. The compiled code is then run. */ public void run() { if (DBT_Options.debugRuntime) { System.out.println("Main: run"); } - - // The current block of compiled code. - VM_CodeArray code; - if(DBT_Options.debugPS) { + // The current block of compiled code. + VM_CodeArray code; + + if (DBT_Options.debugPS) { System.out.println("***** INITIAL PROCESS SPACE *****\n" + this); - System.out.println(this); - //dumpStack(20); + System.out.println(this); + // dumpStack(20); } - if(DBT_Options.gdbStub == false) { - try { - // interpretFrom(); // Interpreter - experimental - while(finished == false) { - // Get the compiled code - code = getCodeForPC(getCurrentInstructionAddress()); - // Run the compiled code. - setCurrentInstructionAddress(DynamicCodeRunner.invokeCode(code, this)); - } - } - catch(BadInstructionException e) { - System.out.println(e.toString()); - } - } - else { - GDBStub gdbStub = new GDBStub(DBT_Options.gdbStubPort, this); - gdbStub.run(); - } + if (DBT_Options.gdbStub == false) { + try { + // interpretFrom(); // Interpreter - experimental + while (finished == false) { + // Get the compiled code + code = getCodeForPC(getCurrentInstructionAddress()); + // Run the compiled code. + setCurrentInstructionAddress(DynamicCodeRunner.invokeCode(code, this)); + } + } catch (BadInstructionException e) { + System.out.println(e.toString()); + } + } else { + GDBStub gdbStub = new GDBStub(DBT_Options.gdbStubPort, this); + gdbStub.run(); + } } /** - * Entry point for system calls - */ + * Entry point for system calls + */ public abstract void doSysCall(); - private static final String[] env = {"HOSTNAME=softwood", "PVM_RSH=/usr/bin/rsh", - "HOST_JAVA_HOME=/home/amulocal/linux/appl/j2sdk1.4.2", "SHELL=/bin/bash", - "TERM=xterm", "HISTSIZE=1000", "SSH_CLIENT=130.88.194.110 8380 22", - "CVSROOT=/home/simgroup/cvsroot", "QTDIR=/usr/lib/qt-3.1", "SSH_TTY=/dev/pts/0", - "RVM_HOST_CONFIG=/home/matleyr/cvs/rvm/config/i686-pc-linux-gnu.ManCS", - "USER=matleyr", "LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:", "XENVIRONMENT=/home/matleyr/.Xdefaults", - "PVM_ROOT=/usr/share/pvm3", "CLASSPATH_ROOT=/home/matleyr/cvs/classpath", - "PATH=/home/matleyr/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/opt/lib/j2re1.3.1/bin:/home/matleyr/cvs/rvm/bin:/home/matleyr/bin", "MAIL=/var/spool/mail/matleyr", - "_=/bin/bash", "PWD=/home/matleyr/dhry", "INPUTRC=/etc/inputrc", - "LANG=en_GB.iso88591", "LAMHELPFILE=/etc/lam/lam-helpfile", - "SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass", - "CSHOME=ma...@an...:/home/M03/cc/matleyr", "HOME=/home/matleyr", - "SHLVL=1", "SIM=/home/simgroup/matleyr", "XPVM_ROOT=/usr/share/pvm3/xpvm", - "RVM_ROOT=/home/matleyr/cvs", "LOGNAME=matleyr", "PRINTER=happy_duplex", - "SSH_CONNECTION=130.88.194.110 2380 130.88.198.215 22", - "LESSOPEN=|/usr/bin/lesspipe.sh %s", "RVM_BUILD=/tmp/RVMbuild", - "DISPLAY=localhost:10.0", - "RVM_TARGET_CONFIG=/home/matleyr/cvs/rvm/config/i686-pc-linux-gnu.ManCS", - "G_BROKEN_FILENAMES=1"}; + private static final String[] env = { + "HOSTNAME=softwood", + "PVM_RSH=/usr/bin/rsh", + "HOST_JAVA_HOME=/home/amulocal/linux/appl/j2sdk1.4.2", + "SHELL=/bin/bash", + "TERM=xterm", + "HISTSIZE=1000", + "SSH_CLIENT=130.88.194.110 8380 22", + "CVSROOT=/home/simgroup/cvsroot", + "QTDIR=/usr/lib/qt-3.1", + "SSH_TTY=/dev/pts/0", + "RVM_HOST_CONFIG=/home/matleyr/cvs/rvm/config/i686-pc-linux-gnu.ManCS", + "USER=matleyr", + "LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:", + "XENVIRONMENT=/home/matleyr/.Xdefaults", + "PVM_ROOT=/usr/share/pvm3", + "CLASSPATH_ROOT=/home/matleyr/cvs/classpath", + "PATH=/home/matleyr/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/opt/lib/j2re1.3.1/bin:/home/matleyr/cvs/rvm/bin:/home/matleyr/bin", + "MAIL=/var/spool/mail/matleyr", "_=/bin/bash", "PWD=/home/matleyr/dhry", + "INPUTRC=/etc/inputrc", "LANG=en_GB.iso88591", + "LAMHELPFILE=/etc/lam/lam-helpfile", + "SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass", + "CSHOME=ma...@an...:/home/M03/cc/matleyr", + "HOME=/home/matleyr", "SHLVL=1", "SIM=/home/simgroup/matleyr", + "XPVM_ROOT=/usr/share/pvm3/xpvm", "RVM_ROOT=/home/matleyr/cvs", + "LOGNAME=matleyr", "PRINTER=happy_duplex", + "SSH_CONNECTION=130.88.194.110 2380 130.88.198.215 22", + "LESSOPEN=|/usr/bin/lesspipe.sh %s", "RVM_BUILD=/tmp/RVMbuild", + "DISPLAY=localhost:10.0", + "RVM_TARGET_CONFIG=/home/matleyr/cvs/rvm/config/i686-pc-linux-gnu.ManCS", + "G_BROKEN_FILENAMES=1" }; + /** - * Method to return environment variables - * @return an array of environment variable strings - */ + * Method to return environment variables + * + * @return an array of environment variable strings + */ protected String[] getEnvironmentVariables() { - /* Environment variables, exactly as on softwood. Not that the number 8380 in SSH_* varies. */ - return env; - /* - if (!DBT_Options.loadEnv) { - Process printenv = Runtime.exec("/usr/bin/printenv"); - InputStream variables = new DataInputStream(printenv.getInputStream()); - variables.readUTF(); - } - */ + /* + * Environment variables, exactly as on softwood. Not that the number 8380 + * in SSH_* varies. + */ + return env; + /* + * if (!DBT_Options.loadEnv) { Process printenv = + * Runtime.exec("/usr/bin/printenv"); InputStream variables = new + * DataInputStream(printenv.getInputStream()); variables.readUTF(); } + */ } /* GDB stub interface */ /** - * Read a register and turn into a byte array conforming to the - * endianness of the architecture - */ + * Read a register and turn into a byte array conforming to the endianness of + * the architecture + */ public abstract byte[] readRegisterGDB(int regNum); + /** - * Run a single instruction - */ + * Run a single instruction + */ public abstract void runOneInstruction() throws BadInstructionException; + /** - * Has frame base register? - */ + * Has frame base register? + */ public boolean hasFrameBaseRegister() { - return false; + return false; } + /** - * Get the value of the frame base register - */ + * Get the value of the frame base register + */ public int getGDBFrameBaseRegister() { - return -1; + return -1; } + /** - * Get the value of the frame base register - */ + * Get the value of the frame base register + */ public abstract int getGDBStackPointerRegister(); + /** - * Get the value of the frame base register - */ + * Get the value of the frame base register + */ public abstract int getGDBProgramCountRegister(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mic...@us...> - 2007-03-28 13:09:57
|
Revision: 13 http://svn.sourceforge.net/pearcolator/?rev=13&view=rev Author: michael_baer Date: 2007-03-28 06:09:58 -0700 (Wed, 28 Mar 2007) Log Message: ----------- Updates due to package renaming Modified Paths: -------------- ext/org/jikesrvm/VM_RuntimeCompiler.java ext/org/jikesrvm/classloader/VM_Method.java ext/org/jikesrvm/classloader/VM_NormalMethod.java ext/org/jikesrvm/opt/ir/OPT_BC2IR.java ext/org/jikesrvm/opt/ir/OPT_GenerationContext.java src/org/binarytranslator/generic/decoder/DecoderUtils.java src/org/binarytranslator/vmInterface/DBT_Trace.java src/org/binarytranslator/vmInterface/DynamicCodeRunner.java Modified: ext/org/jikesrvm/VM_RuntimeCompiler.java =================================================================== --- ext/org/jikesrvm/VM_RuntimeCompiler.java 2007-03-28 13:09:25 UTC (rev 12) +++ ext/org/jikesrvm/VM_RuntimeCompiler.java 2007-03-28 13:09:58 UTC (rev 13) @@ -12,6 +12,8 @@ import org.jikesrvm.opt.*; import org.jikesrvm.adaptive.*; import org.jikesrvm.ArchitectureSpecific.VM_JNICompiler; +import org.jikesrvm.runtime.VM_Time; +import org.jikesrvm.scheduler.VM_Thread; /** * Harness to select which compiler to dynamically Modified: ext/org/jikesrvm/classloader/VM_Method.java =================================================================== --- ext/org/jikesrvm/classloader/VM_Method.java 2007-03-28 13:09:25 UTC (rev 12) +++ ext/org/jikesrvm/classloader/VM_Method.java 2007-03-28 13:09:58 UTC (rev 13) @@ -11,6 +11,8 @@ import org.jikesrvm.*; import org.jikesrvm.ArchitectureSpecific.VM_CodeArray; import org.jikesrvm.ArchitectureSpecific.VM_LazyCompilationTrampolineGenerator; +import org.jikesrvm.runtime.VM_Statics; +import org.jikesrvm.runtime.VM_Entrypoints; import java.io.DataInputStream; import java.io.IOException; Modified: ext/org/jikesrvm/classloader/VM_NormalMethod.java =================================================================== --- ext/org/jikesrvm/classloader/VM_NormalMethod.java 2007-03-28 13:09:25 UTC (rev 12) +++ ext/org/jikesrvm/classloader/VM_NormalMethod.java 2007-03-28 13:09:58 UTC (rev 13) @@ -13,6 +13,7 @@ import org.jikesrvm.opt.ir.OPT_HIRGenerator; import org.jikesrvm.opt.ir.OPT_BC2IR; import org.jikesrvm.opt.ir.OPT_GenerationContext; +import org.jikesrvm.runtime.VM_DynamicLink; /** * A method of a java class that has bytecodes. Modified: ext/org/jikesrvm/opt/ir/OPT_BC2IR.java =================================================================== --- ext/org/jikesrvm/opt/ir/OPT_BC2IR.java 2007-03-28 13:09:25 UTC (rev 12) +++ ext/org/jikesrvm/opt/ir/OPT_BC2IR.java 2007-03-28 13:09:58 UTC (rev 13) @@ -18,7 +18,8 @@ import org.jikesrvm.ArchitectureSpecific.OPT_RegisterPool; import org.jikesrvm.adaptive.*; import java.util.ArrayList; - +import org.jikesrvm.runtime.VM_Magic; +import org.jikesrvm.runtime.VM_Entrypoints; import org.vmmagic.pragma.*; import org.vmmagic.unboxed.*; Modified: ext/org/jikesrvm/opt/ir/OPT_GenerationContext.java =================================================================== --- ext/org/jikesrvm/opt/ir/OPT_GenerationContext.java 2007-03-28 13:09:25 UTC (rev 12) +++ ext/org/jikesrvm/opt/ir/OPT_GenerationContext.java 2007-03-28 13:09:58 UTC (rev 13) @@ -10,6 +10,8 @@ import org.jikesrvm.*; import org.jikesrvm.ArchitectureSpecific.OPT_RegisterPool; +import org.jikesrvm.runtime.VM_Entrypoints; +import org.jikesrvm.runtime.VM_Statics; import org.jikesrvm.classloader.*; import org.jikesrvm.opt.*; import org.vmmagic.unboxed.Offset; Modified: src/org/binarytranslator/generic/decoder/DecoderUtils.java =================================================================== --- src/org/binarytranslator/generic/decoder/DecoderUtils.java 2007-03-28 13:09:25 UTC (rev 12) +++ src/org/binarytranslator/generic/decoder/DecoderUtils.java 2007-03-28 13:09:58 UTC (rev 13) @@ -172,6 +172,11 @@ protected int currentPC; /** + * The pc value of the first instruction in the trace + */ + protected int startingPC; + + /** * The OPT_BasicBlock which will contain the next translated instruction */ protected OPT_BasicBlock nextBlock; @@ -269,7 +274,8 @@ gc = context; ps = ((DBT_Trace)(gc.method)).ps; currentPC = ((DBT_Trace)(gc.method)).pc; - + startingPC = currentPC; + // Number of translated instructions numberOfInstructions = 0; @@ -539,7 +545,7 @@ // Intel can't distinguish branches within 16bytes, so neither // can we, the top bit is saved for distinguished addresses we // need to know to dynamically link things - i.bcIndex = (currentPC >> 4) & 0x7FFF; + i.bcIndex = ((currentPC-startingPC) >> 4) & 0x7FFF; } currentBlock.appendInstruction(i); } @@ -549,7 +555,7 @@ * @param likely does this branch have a likely hint */ public OPT_BranchProfileOperand getConditionalBranchProfileOperand(boolean likely) { - return gc.getConditionalBranchProfileOperand((currentPC >> 2) & 0xFFFF, likely); + return gc.getConditionalBranchProfileOperand(((currentPC-startingPC) >> 4) & 0x7FFF, likely); } Modified: src/org/binarytranslator/vmInterface/DBT_Trace.java =================================================================== --- src/org/binarytranslator/vmInterface/DBT_Trace.java 2007-03-28 13:09:25 UTC (rev 12) +++ src/org/binarytranslator/vmInterface/DBT_Trace.java 2007-03-28 13:09:58 UTC (rev 13) @@ -20,8 +20,8 @@ import org.jikesrvm.classloader.VM_MemberReference; import org.jikesrvm.classloader.VM_Atom; import org.jikesrvm.classloader.VM_BytecodeStream; -import org.jikesrvm.VM_Statics; -import org.jikesrvm.VM_DynamicLink; +import org.jikesrvm.runtime.VM_Statics; +import org.jikesrvm.runtime.VM_DynamicLink; import org.jikesrvm.opt.ir.OPT_GenerationContext; import org.jikesrvm.opt.ir.OPT_HIRGenerator; import org.vmmagic.pragma.Uninterruptible; Modified: src/org/binarytranslator/vmInterface/DynamicCodeRunner.java =================================================================== --- src/org/binarytranslator/vmInterface/DynamicCodeRunner.java 2007-03-28 13:09:25 UTC (rev 12) +++ src/org/binarytranslator/vmInterface/DynamicCodeRunner.java 2007-03-28 13:09:58 UTC (rev 13) @@ -9,7 +9,7 @@ package org.binarytranslator.vmInterface; import org.jikesrvm.VM; import org.jikesrvm.ArchitectureSpecific.VM_CodeArray; -import org.jikesrvm.VM_Magic; +import org.jikesrvm.runtime.VM_Magic; import org.vmmagic.pragma.DynamicBridge; import org.vmmagic.pragma.Uninterruptible; import org.vmmagic.pragma.NoInline; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mic...@us...> - 2007-03-28 13:09:25
|
Revision: 12 http://svn.sourceforge.net/pearcolator/?rev=12&view=rev Author: michael_baer Date: 2007-03-28 06:09:25 -0700 (Wed, 28 Mar 2007) Log Message: ----------- Updates due to package renaming Modified Paths: -------------- rvmroot.patch Modified: rvmroot.patch =================================================================== --- rvmroot.patch 2007-03-27 15:41:07 UTC (rev 11) +++ rvmroot.patch 2007-03-28 13:09:25 UTC (rev 12) @@ -96,6 +96,109 @@ # Load a singed byte # NOTE: Because of our strategy of using explict guard instructions, there is no # way in the HIR/LIR that the actual load instruction can except. +Index: rvm/src/org/jikesrvm/opt/ia32/OPT_ConvertALUOperators.java +=================================================================== +--- rvm/src/org/jikesrvm/opt/ia32/OPT_ConvertALUOperators.java (revision 11903) ++++ rvm/src/org/jikesrvm/opt/ia32/OPT_ConvertALUOperators.java (working copy) +@@ -152,6 +152,7 @@ + case REF_XOR_opcode: commutative(s, INT_XOR_ACC, ir); break; + case INT_XOR_opcode: commutative(s, INT_XOR_ACC, ir); break; + case INT_NEG_opcode: unary(s, INT_NEG_ACC, ir); break; ++ case REF_NEG_opcode: unary(s, INT_NEG_ACC, ir); break; + case REF_NOT_opcode: unary(s, INT_NOT_ACC, ir); break; + case INT_NOT_opcode: unary(s, INT_NOT_ACC, ir); break; + +Index: rvm/src/org/jikesrvm/opt/OPT_Simplifier.java +=================================================================== +--- rvm/src/org/jikesrvm/opt/OPT_Simplifier.java (revision 11903) ++++ rvm/src/org/jikesrvm/opt/OPT_Simplifier.java (working copy) +@@ -1476,6 +1476,11 @@ + return DefUseEffect.REDUCED; + } + } ++ else if (op1.isIntConstant() && (op1.asIntConstant().value == 0)) { ++ Unary.mutate(s, INT_NEG, Binary.getClearResult(s), ++ Binary.getClearVal2(s)); ++ return DefUseEffect.REDUCED; ++ } + } + return DefUseEffect.UNCHANGED; + } +@@ -1742,6 +1747,14 @@ + return DefUseEffect.REDUCED; + } + } ++ else if (op1.isConstant() && !op1.isObjectConstant()) { ++ Address val1 = getAddressValue(op1); ++ if (val1.EQ(Address.zero())) { ++ Unary.mutate(s, REF_NEG, Binary.getClearResult(s), ++ Binary.getClearVal2(s)); ++ return DefUseEffect.REDUCED; ++ } ++ } + } + return DefUseEffect.UNCHANGED; + } +@@ -2147,6 +2160,11 @@ + } + } + } ++ else if (op1.isLongConstant() && (op1.asLongConstant().value == 0)) { ++ Unary.mutate(s, LONG_NEG, Binary.getClearResult(s), ++ Binary.getClearVal2(s)); ++ return DefUseEffect.REDUCED; ++ } + } + return DefUseEffect.UNCHANGED; + } +@@ -2345,10 +2363,10 @@ + } + private static DefUseEffect floatSub(OPT_Instruction s) { + if (CF_FLOAT) { ++ OPT_Operand op1 = Binary.getVal1(s); + OPT_Operand op2 = Binary.getVal2(s); + if (op2.isFloatConstant()) { + float val2 = op2.asFloatConstant().value; +- OPT_Operand op1 = Binary.getVal1(s); + if (op1.isFloatConstant()) { + // BOTH CONSTANTS: FOLD + float val1 = op1.asFloatConstant().value; +@@ -2363,6 +2381,11 @@ + return DefUseEffect.MOVE_REDUCED; + } + } ++ else if (op1.isFloatConstant() && (op1.asFloatConstant().value == 0.0f)) { ++ Unary.mutate(s, FLOAT_NEG, Binary.getClearResult(s), ++ Binary.getClearVal2(s)); ++ return DefUseEffect.REDUCED; ++ } + } + return DefUseEffect.UNCHANGED; + } +@@ -2496,10 +2519,10 @@ + } + private static DefUseEffect doubleSub(OPT_Instruction s) { + if (CF_DOUBLE) { ++ OPT_Operand op1 = Binary.getVal1(s); + OPT_Operand op2 = Binary.getVal2(s); + if (op2.isDoubleConstant()) { + double val2 = op2.asDoubleConstant().value; +- OPT_Operand op1 = Binary.getVal1(s); + if (op1.isDoubleConstant()) { + // BOTH CONSTANTS: FOLD + double val1 = op1.asDoubleConstant().value; +@@ -2514,6 +2537,11 @@ + return DefUseEffect.MOVE_REDUCED; + } + } ++ else if (op1.isDoubleConstant() && (op1.asDoubleConstant().value == 0.0)) { ++ Unary.mutate(s, DOUBLE_NEG, Binary.getClearResult(s), ++ Binary.getClearVal2(s)); ++ return DefUseEffect.REDUCED; ++ } + } + return DefUseEffect.UNCHANGED; + } Index: rvm/src/org/jikesrvm/opt/VM_OptCompiledMethod.java =================================================================== --- rvm/src/org/jikesrvm/opt/VM_OptCompiledMethod.java (revision 11903) @@ -122,6 +225,1519 @@ VM_BytecodeStream bcodes = realMethod.getBytecodes(); bcodes.reset(bci); int opcode = bcodes.nextInstruction(); +Index: rvm/src/org/jikesrvm/opt/OPT_ExpressionFolding.java +=================================================================== +--- rvm/src/org/jikesrvm/opt/OPT_ExpressionFolding.java (revision 11903) ++++ rvm/src/org/jikesrvm/opt/OPT_ExpressionFolding.java (working copy) +@@ -15,35 +15,68 @@ + import java.util.HashSet; + import java.util.Iterator; + import org.vmmagic.unboxed.Address; +- ++import org.vmmagic.unboxed.Word; ++import static org.jikesrvm.opt.ir.OPT_IRTools.AC; ++import static org.jikesrvm.opt.ir.OPT_IRTools.DC; ++import static org.jikesrvm.opt.ir.OPT_IRTools.FC; ++import static org.jikesrvm.opt.ir.OPT_IRTools.IC; ++import static org.jikesrvm.opt.ir.OPT_IRTools.LC; + /** + * This class simplifies expressions in SSA form. + * + * @author Stephen Fink ++ * @author Ian Rogers ++ * @author Michael Baer + */ + class OPT_ExpressionFolding { + private static final boolean RESTRICT_TO_DEAD_EXPRESSIONS = true; + ++ /** ++ * Basic configuration options to enable/disable folding of certain instructions and operands. ++ */ ++ private final static boolean FOLD_INTS = true; ++ private final static boolean FOLD_REFS = true; ++ private final static boolean FOLD_LONGS = true; ++ private final static boolean FOLD_FLOATS = true; ++ private final static boolean FOLD_DOUBLES = true; ++ ++ private final static boolean FOLD_SUBS = true; ++ private final static boolean FOLD_ADDS = true; ++ private final static boolean FOLD_MULTS = true; ++ private final static boolean FOLD_SHIFTLS = true; ++ private final static boolean FOLD_SHIFTRS = true; ++ private final static boolean FOLD_CMPS = true; ++ private final static boolean FOLD_IFCMPS = true; ++ private final static boolean FOLD_XORS = true; ++ private final static boolean FOLD_ORS = true; ++ private final static boolean FOLD_ANDS = true; ++ private final static boolean FOLD_NEGS = true; ++ private final static boolean FOLD_NOTS = true; ++ private final static boolean FOLD_NEG_ADD = true; //fold NEG followed by ADD to a SUB? ++ private final static boolean FOLD_NEG_SUB = true; //fold NEG followed by SUB to a reversed SUB? ++ + /** + * Perform the transformation. + * + * If we have, in SSA form, + * <pre> +- * x = a + c1 +- * y = x + c2 ++ * x = a op1 c1 ++ * y = x op2 c2 + * </pre> + * where c1 and c2 are constants, replace the def of y by + * <pre> +- * y = a + (c1+c2) ++ * y = a op1 (c1 op3 c2) + * </pre> +- * Perform a similar transformation for subtraction. ++ * Where op1, op2 and op3 are add, subtract, multiply, and, or, xor and ++ * compare. Repeatedly apply transformation until all expressions are ++ * folded. + * + * <p> PRECONDITIONS: SSA form, register lists computed + * + * @param ir the governing IR + */ + public static void perform(OPT_IR ir) { +- ++ + // Create a set of potential computations to fold. + HashSet<OPT_Register> candidates = new HashSet<OPT_Register>(20); + +@@ -64,38 +97,101 @@ + boolean didSomething = true; + while (didSomething) { + didSomething = false; +- for (OPT_Register r : candidates) { ++ ++ for ( Iterator<OPT_Register> it = candidates.iterator(); it.hasNext();) { ++ OPT_Register r = it.next(); + OPT_Instruction s = r.getFirstDef(); +- OPT_Operand val1 = Binary.getVal1(s); ++ OPT_Operand val1; ++ ++ if (Binary.conforms(s)) ++ val1 = Binary.getVal1(s); ++ else if (Unary.conforms(s)) { ++ val1 = Unary.getVal(s); ++ } ++ else if (BooleanCmp.conforms(s)) { ++ val1 = BooleanCmp.getVal1(s); ++ } ++ else if (IfCmp.conforms(s)) { ++ val1 = IfCmp.getVal1(s); ++ } ++ else if (IfCmp2.conforms(s)) { ++ val1 = IfCmp2.getVal1(s); ++ } ++ else { ++ // we're not optimising any other instruction types ++ continue; ++ } ++ + if (VM.VerifyAssertions) { + if (!val1.isRegister()) + VM.sysWrite("Expression folding trouble AAA" + s); + VM._assert(val1.isRegister()); + } ++ //purely debug ++ if (val1.isConstant()) ++ { ++ OPT_Operand val2 = Binary.getVal2(s); ++ throw new RuntimeException("Constant?" + val2.isConstant() + " | val2 " + val2 + " | Val2 Type: " + val2.getClass().toString() + " | Instr: " + s.toString() + " | " + s.getClass().toString()); ++ } ++ + if (candidates.contains(val1.asRegister().register)) { + OPT_Instruction def = val1.asRegister().register.getFirstDef(); +- OPT_Operand def1 = Binary.getVal1(def); ++ ++ /* check if the defining instruction has not mutated yet*/ ++ if (isCandidateExpression(def) == null) ++ continue; ++ + if (VM.VerifyAssertions) { +- if (!def1.isRegister()) +- VM.sysWrite("Expression folding trouble BBB" + def); +- VM._assert(def1.isRegister()); ++ OPT_Operand def1; ++ if (Binary.conforms(def)) ++ def1 = Binary.getVal1(def); ++ else if (Unary.conforms(def)) { ++ def1 = Unary.getVal(def); ++ } ++ else { ++ def1 = null; ++ } ++ ++ if (def1 != null) { ++ if (!def1.isRegister()) ++ VM.sysWrite("Expression folding trouble BBB" + def); ++ VM._assert(def1.isRegister()); ++ } + } +- OPT_Operand def2 = Binary.getVal2(def); ++ + if (VM.VerifyAssertions) { +- if (!def2.isConstant()) +- VM.sysWrite("Expression folding trouble CCC" + def); +- VM._assert(def2.isConstant()); ++ OPT_Operand def2; ++ if (Binary.conforms(def)) ++ def2 = Binary.getVal1(def); ++ else if (Unary.conforms(def)) { ++ def2 = Unary.getVal(def); ++ } ++ else { ++ def2 = null; ++ } ++ ++ if (def2 != null) { ++ if (!def2.isRegister()) ++ VM.sysWrite("Expression folding trouble BBB" + def); ++ VM._assert(def2.isRegister()); ++ } + } + + OPT_Instruction newS = transform(s, def); +- s.insertAfter(newS); +- OPT_DefUse.updateDUForNewInstruction(newS); +- OPT_DefUse.removeInstructionAndUpdateDU(s); +- didSomething = true; ++ if (newS != null) { ++ /* check if this expression is still an optimisation candidate */ ++ if (isCandidateExpression(newS) == null) ++ it.remove(); ++ ++ s.insertAfter(newS); ++ OPT_DefUse.updateDUForNewInstruction(newS); ++ OPT_DefUse.removeInstructionAndUpdateDU(s); ++ didSomething = true; ++ } + } + } + } +- } ++ } + + /** + * Prune the candidate set; restrict candidates to only allow +@@ -105,7 +201,29 @@ + for (Iterator<OPT_Register> i = candidates.iterator(); i.hasNext(); ) { + OPT_Register r = i.next(); + OPT_Instruction s = r.getFirstDef(); +- OPT_Operand val1 = Binary.getVal1(s); ++ OPT_Operand val1; ++ if (Binary.conforms(s)) { ++ val1 = Binary.getVal1(s); ++ } ++ else if (Unary.conforms(s)) { ++ val1 = Unary.getVal(s); ++ } ++ else if (BooleanCmp.conforms(s)) { ++ val1 = BooleanCmp.getVal1(s); ++ } ++ else if (IfCmp.conforms(s)) { ++ val1 = IfCmp.getVal1(s); ++ } ++ else if (IfCmp2.conforms(s)) { ++ val1 = IfCmp2.getVal1(s); ++ } ++ else { ++ OPT_OptimizingCompilerException.UNREACHABLE(); ++ return; ++ } ++ ++ if (VM.VerifyAssertions) VM._assert(!val1.isConstant(), "Error with val1 of "+s); ++ + OPT_Register v1 = val1.asRegister().register; + if (candidates.contains(v1)) { + for (Enumeration<OPT_RegisterOperand> uses = OPT_DefUse.uses(v1); uses.hasMoreElements();) { +@@ -121,113 +239,965 @@ + } + + /** +- * Perform the transfomation on the instruction s = A +/- c +- * where def is the definition of A. ++ * Perform the transfomation on the instruction + * ++ * @param s the instruction to transform of the form y = x op c1 ++ * @param def the definition of x, the defining instruction is of ++ * the form x = a op c2 + * @return the new instruction to replace s; + */ + private static OPT_Instruction transform(OPT_Instruction s, +- OPT_Instruction def) { +- if (s.operator == INT_ADD || s.operator == INT_SUB) { +- return transformForInt(s,def); +- } else if (s.operator == REF_ADD || s.operator == REF_SUB) { +- return transformForWord(s,def); +- } else { +- return transformForLong(s,def); ++ OPT_Instruction def) { ++ // x = a op1 c1 ++ // y = x op2 c2 ++ OPT_RegisterOperand a; ++ OPT_RegisterOperand y; ++ if (Binary.conforms(def)) ++ a = Binary.getVal1(def).asRegister(); ++ else if (Unary.conforms(def)) ++ a = Unary.getVal(def).asRegister(); ++ else if (BooleanCmp.conforms(def) || IfCmp.conforms(def) || IfCmp2.conforms(def)) ++ // we don't fold in case of a Boolean/IfCmp coming before ++ // the instruction to be folded ++ return null; ++ else { ++ OPT_OptimizingCompilerException.UNREACHABLE(); ++ return null; + } +- } + +- private static int getIntValue(OPT_Operand op) { +- if (op instanceof OPT_NullConstantOperand) //is this still necessary? +- return 0; +- if (op instanceof OPT_IntConstantOperand) +- return op.asIntConstant().value; +- throw new OPT_OptimizingCompilerException("Cannot getIntValue from this operand " + op); +- } ++ if (Binary.conforms(s)) ++ y = Binary.getResult(s); ++ else if (Unary.conforms(s)) ++ y = Unary.getResult(s); ++ else if (BooleanCmp.conforms(s)) ++ y = BooleanCmp.getResult(s); ++ else if (IfCmp.conforms(s)) ++ y = IfCmp.getGuardResult(s); ++ else if (IfCmp2.conforms(s)) ++ y = IfCmp2.getGuardResult(s); ++ else { ++ OPT_OptimizingCompilerException.UNREACHABLE(); ++ return null; ++ } + +- private static Address getAddressValue(OPT_Operand op) { +- if (op instanceof OPT_NullConstantOperand) +- return Address.zero(); +- if (op instanceof OPT_AddressConstantOperand) +- return op.asAddressConstant().value; +- if (op instanceof OPT_IntConstantOperand) +- return Address.fromIntSignExtend(op.asIntConstant().value); +- if (VM.BuildFor64Addr && op instanceof OPT_LongConstantOperand) +- return Address.fromLong(op.asLongConstant().value); +- throw new OPT_OptimizingCompilerException("Cannot getWordValue from this operand " + op); +- } ++ switch(s.operator.opcode) { ++ // Foldable operators ++ case INT_ADD_opcode: { ++ if (FOLD_INTS && FOLD_ADDS) { ++ int c2 = getIntValue(Binary.getVal2(s)); ++ if (def.operator == INT_ADD) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a + c1; y = x + c2 ++ return Binary.create(INT_ADD, y.copyRO(), a.copyRO(), IC(c1+c2)); ++ } ++ else if (def.operator == INT_SUB) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a - c1; y = x + c2 ++ return Binary.create(INT_ADD, y.copyRO(), a.copyRO(), IC(c2-c1)); ++ } ++ else if (def.operator == INT_NEG && FOLD_NEG_ADD) { ++ // x = -a; y = x + c2; ++ return Binary.create(INT_SUB, y.copyRO(), IC(c2), a.copyRO()); ++ } ++ } ++ return null; ++ } ++ case REF_ADD_opcode: { ++ if (FOLD_REFS && FOLD_ADDS) { ++ Address c2 = getAddressValue(Binary.getVal2(s)); ++ if (def.operator == REF_ADD) { ++ Address c1 = getAddressValue(Binary.getVal2(def)); ++ // x = a + c1; y = x + c2 ++ return Binary.create(REF_ADD, y.copyRO(), a.copyRO(), AC(c1.toWord().plus(c2.toWord()).toAddress())); ++ } ++ else if (def.operator == REF_SUB) { ++ Address c1 = getAddressValue(Binary.getVal2(def)); ++ // x = a - c1; y = x + c2 ++ return Binary.create(REF_ADD, y.copyRO(), a.copyRO(), AC(c2.toWord().minus(c1.toWord()).toAddress())); ++ } ++ else if (def.operator == REF_NEG && FOLD_NEG_ADD) { ++ // x = -a; y = x + c2; ++ return Binary.create(REF_SUB, y.copyRO(), AC(c2), a.copyRO()); ++ } ++ } ++ return null; ++ } ++ case LONG_ADD_opcode: { ++ if (FOLD_LONGS && FOLD_ADDS) { ++ long c2 = getLongValue(Binary.getVal2(s)); ++ if (def.operator == LONG_ADD) { ++ long c1 = getLongValue(Binary.getVal2(def)); ++ // x = a + c1; y = x + c2 ++ return Binary.create(LONG_ADD, y.copyRO(), a.copyRO(), LC(c1+c2)); ++ } ++ else if (def.operator == LONG_SUB) { ++ long c1 = getLongValue(Binary.getVal2(def)); ++ // x = a - c1; y = x + c2 ++ return Binary.create(LONG_ADD, y.copyRO(), a.copyRO(), LC(c2-c1)); ++ } ++ else if (def.operator == LONG_NEG && FOLD_NEG_ADD) { ++ // x = -a; y = x + c2; ++ return Binary.create(LONG_SUB, y.copyRO(), LC(c2), a.copyRO()); ++ } ++ } ++ return null; ++ } ++ case FLOAT_ADD_opcode: { ++ if (FOLD_FLOATS && FOLD_ADDS) { ++ float c2 = getFloatValue(Binary.getVal2(s)); ++ if (def.operator == FLOAT_ADD) { ++ float c1 = getFloatValue(Binary.getVal2(def)); ++ // x = a + c1; y = x + c2 ++ return Binary.create(FLOAT_ADD, y.copyRO(), a.copyRO(), FC(c1+c2)); ++ } ++ else if (def.operator == FLOAT_SUB) { ++ float c1 = getFloatValue(Binary.getVal2(def)); ++ // x = a - c1; y = x + c2 ++ return Binary.create(FLOAT_ADD, y.copyRO(), a.copyRO(), FC(c2-c1)); ++ } ++ else if (def.operator == FLOAT_NEG && FOLD_NEG_ADD) { ++ // x = -a; y = x + c2; ++ return Binary.create(FLOAT_SUB, y.copyRO(), FC(c2), a.copyRO()); ++ } ++ } ++ return null; ++ } ++ case DOUBLE_ADD_opcode: { ++ if (FOLD_DOUBLES && FOLD_ADDS) { ++ double c2 = getDoubleValue(Binary.getVal2(s)); ++ if (def.operator == DOUBLE_ADD) { ++ double c1 = getDoubleValue(Binary.getVal2(def)); ++ // x = a + c1; y = x + c2 ++ return Binary.create(DOUBLE_ADD, y.copyRO(), a.copyRO(), DC(c1+c2)); ++ } ++ else if (def.operator == DOUBLE_SUB) { ++ double c1 = getDoubleValue(Binary.getVal2(def)); ++ // x = a - c1; y = x + c2 ++ return Binary.create(DOUBLE_ADD, y.copyRO(), a.copyRO(), DC(c2-c1)); ++ } ++ else if (def.operator == DOUBLE_NEG && FOLD_NEG_ADD) { ++ // x = -a; y = x + c2; ++ return Binary.create(DOUBLE_SUB, y.copyRO(), DC(c2), a.copyRO()); ++ } ++ } ++ return null; ++ } ++ case INT_SUB_opcode: { ++ if (FOLD_INTS && FOLD_SUBS) { ++ int c2 = getIntValue(Binary.getVal2(s)); ++ if (def.operator == INT_ADD) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a + c1; y = x - c2 ++ return Binary.create(INT_ADD, y.copyRO(), a.copyRO(), IC(c1-c2)); ++ } ++ else if (def.operator == INT_SUB) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a - c1; y = x - c2 ++ return Binary.create(INT_ADD, y.copyRO(), a.copyRO(), IC(-c1-c2)); ++ } ++ else if (def.operator == INT_NEG && FOLD_NEG_SUB) { ++ // x = -a; y = x - c2; ++ return Binary.create(INT_SUB, y.copyRO(), IC(-c2), a.copyRO()); ++ } ++ } ++ return null; ++ } ++ case REF_SUB_opcode: { ++ if (FOLD_REFS && FOLD_SUBS) { ++ Address c2 = getAddressValue(Binary.getVal2(s)); ++ if (def.operator == REF_ADD) { ++ Address c1 = getAddressValue(Binary.getVal2(def)); ++ // x = a + c1; y = x - c2 ++ return Binary.create(REF_ADD, y.copyRO(), a.copyRO(), AC(c1.toWord().minus(c2.toWord()).toAddress())); ++ } ++ else if (def.operator == REF_SUB) { ++ Address c1 = getAddressValue(Binary.getVal2(def)); ++ // x = a - c1; y = x - c2 ++ return Binary.create(REF_ADD, y.copyRO(), a.copyRO(), AC(Word.zero().minus(c1.toWord()).minus(c2.toWord()).toAddress())); ++ } ++ else if (def.operator == REF_NEG && FOLD_NEG_SUB) { ++ // x = -a; y = x - c2; ++ return Binary.create(REF_SUB, y.copyRO(), AC(Word.zero().minus(c2.toWord()).toAddress()), a.copyRO()); ++ } ++ } ++ return null; ++ } ++ case LONG_SUB_opcode: { ++ if (FOLD_LONGS && FOLD_SUBS) { ++ long c2 = getLongValue(Binary.getVal2(s)); ++ if (def.operator == LONG_ADD) { ++ long c1 = getLongValue(Binary.getVal2(def)); ++ // x = a + c1; y = x - c2 ++ return Binary.create(LONG_ADD, y.copyRO(), a.copyRO(), LC(c1-c2)); ++ } ++ else if (def.operator == LONG_SUB) { ++ long c1 = getLongValue(Binary.getVal2(def)); ++ // x = a - c1; y = x - c2 ++ return Binary.create(LONG_ADD, y.copyRO(), a.copyRO(), LC(-c1-c2)); ++ } ++ else if (def.operator == LONG_NEG && FOLD_NEG_SUB) { ++ // x = -a; y = x - c2; ++ return Binary.create(LONG_SUB, y.copyRO(), LC(-c2), a.copyRO()); ++ } ++ } ++ return null; ++ } ++ case FLOAT_SUB_opcode: { ++ if (FOLD_FLOATS && FOLD_SUBS) { ++ float c2 = getFloatValue(Binary.getVal2(s)); ++ if (def.operator == FLOAT_ADD) { ++ float c1 = getFloatValue(Binary.getVal2(def)); ++ // x = a + c1; y = x - c2 ++ return Binary.create(FLOAT_ADD, y.copyRO(), a.copyRO(), FC(c1-c2)); ++ } ++ else if (def.operator == FLOAT_SUB) { ++ float c1 = getFloatValue(Binary.getVal2(def)); ++ // x = a - c1; y = x - c2 ++ return Binary.create(FLOAT_ADD, y.copyRO(), a.copyRO(), FC(-c1-c2)); ++ } ++ else if (def.operator == FLOAT_NEG && FOLD_NEG_SUB) { ++ // x = -a; y = x - c2; ++ return Binary.create(FLOAT_SUB, y.copyRO(), FC(-c2), a.copyRO()); ++ } ++ } ++ return null; ++ } ++ case DOUBLE_SUB_opcode: { ++ if (FOLD_DOUBLES && FOLD_SUBS) { ++ double c2 = getDoubleValue(Binary.getVal2(s)); ++ if (def.operator == FLOAT_ADD) { ++ double c1 = getDoubleValue(Binary.getVal2(def)); ++ // x = a + c1; y = x - c2 ++ return Binary.create(DOUBLE_ADD, y.copyRO(), a.copyRO(), DC(c1-c2)); ++ } ++ else if (def.operator == DOUBLE_SUB) { ++ double c1 = getDoubleValue(Binary.getVal2(def)); ++ // x = a - c1; y = x + c2 ++ return Binary.create(DOUBLE_ADD, y.copyRO(), a.copyRO(), DC(-c1-c2)); ++ } ++ else if (def.operator == DOUBLE_NEG && FOLD_NEG_SUB) { ++ // x = -a; y = x - c2; ++ return Binary.create(DOUBLE_SUB, y.copyRO(), DC(-c2), a.copyRO()); ++ } ++ } ++ return null; ++ } ++ case INT_MUL_opcode: { ++ if (FOLD_INTS && FOLD_MULTS) { ++ int c2 = getIntValue(Binary.getVal2(s)); ++ if (def.operator == INT_MUL) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a * c1; y = x * c2 ++ return Binary.create(INT_MUL, y.copyRO(), a.copyRO(), IC(c1*c2)); ++ } ++ else if (def.operator == INT_NEG) { ++ // x = -a; y = x * c2; ++ return Binary.create(INT_MUL, y.copyRO(), a.copyRO(), IC(-c2)); ++ } ++ } ++ return null; ++ } ++ case LONG_MUL_opcode: { ++ if (FOLD_LONGS && FOLD_MULTS) { ++ long c2 = getLongValue(Binary.getVal2(s)); ++ if (def.operator == LONG_MUL) { ++ long c1 = getLongValue(Binary.getVal2(def)); ++ // x = a * c1; y = x * c2 ++ return Binary.create(LONG_MUL, y.copyRO(), a.copyRO(), LC(c1*c2)); ++ } ++ else if (def.operator == LONG_NEG) { ++ // x = -a; y = x * c2; ++ return Binary.create(LONG_MUL, y.copyRO(), a.copyRO(), LC(-c2)); ++ } ++ } ++ return null; ++ } ++ case FLOAT_MUL_opcode: { ++ if (FOLD_FLOATS && FOLD_MULTS) { ++ float c2 = getFloatValue(Binary.getVal2(s)); ++ if (def.operator == FLOAT_MUL) { ++ float c1 = getFloatValue(Binary.getVal2(def)); ++ // x = a * c1; y = x * c2 ++ return Binary.create(FLOAT_MUL, y.copyRO(), a.copyRO(), FC(c1*c2)); ++ } ++ else if (def.operator == FLOAT_NEG) { ++ // x = -a; y = x * c2; ++ return Binary.create(FLOAT_MUL, y.copyRO(), a.copyRO(), FC(-c2)); ++ } ++ } ++ return null; ++ } ++ case DOUBLE_MUL_opcode: { ++ if (FOLD_DOUBLES && FOLD_MULTS) { ++ double c2 = getDoubleValue(Binary.getVal2(s)); ++ if (def.operator == DOUBLE_MUL) { ++ double c1 = getDoubleValue(Binary.getVal2(def)); ++ // x = a * c1; y = x * c2 ++ return Binary.create(DOUBLE_MUL, y.copyRO(), a.copyRO(), DC(c1*c2)); ++ } ++ else if (def.operator == DOUBLE_NEG) { ++ // x = -a; y = x * c2; ++ return Binary.create(DOUBLE_MUL, y.copyRO(), a.copyRO(), DC(-c2)); ++ } ++ } ++ return null; ++ } ++ case INT_SHL_opcode: { ++ if (FOLD_INTS && FOLD_SHIFTLS) { ++ int c2 = getIntValue(Binary.getVal2(s)); ++ if (def.operator == INT_SHL) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a << c1; y = x << c2 ++ return Binary.create(INT_SHL, y.copyRO(), a.copyRO(), IC(c1+c2)); ++ } ++ } ++ return null; ++ } ++ case REF_SHL_opcode: { ++ if (FOLD_REFS && FOLD_SHIFTLS) { ++ int c2 = getIntValue(Binary.getVal2(s)); ++ if (def.operator == REF_SHL) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a << c1; y = x << c2 ++ return Binary.create(REF_SHL, y.copyRO(), a.copyRO(), IC(c1+c2)); ++ } ++ } ++ return null; ++ } ++ case LONG_SHL_opcode: { ++ if (FOLD_LONGS && FOLD_SHIFTLS) { ++ int c2 = getIntValue(Binary.getVal2(s)); ++ if (def.operator == LONG_SHL) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a << c1; y = x << c2 ++ return Binary.create(LONG_SHL, y.copyRO(), a.copyRO(), IC(c1+c2)); ++ } ++ } ++ return null; ++ } ++ case INT_SHR_opcode: { ++ if (FOLD_INTS && FOLD_SHIFTRS) { ++ int c2 = getIntValue(Binary.getVal2(s)); ++ if (def.operator == INT_SHR) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a >> c1; y = x >> c2 ++ return Binary.create(INT_SHR, y.copyRO(), a.copyRO(), IC(c1+c2)); ++ } ++ } ++ return null; ++ } ++ case REF_SHR_opcode: { ++ if (FOLD_REFS && FOLD_SHIFTRS) { ++ int c2 = getIntValue(Binary.getVal2(s)); ++ if (def.operator == REF_SHR) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a >> c1; y = x >> c2 ++ return Binary.create(REF_SHR, y.copyRO(), a.copyRO(), IC(c1+c2)); ++ } ++ } ++ return null; ++ } ++ case LONG_SHR_opcode: { ++ if (FOLD_LONGS && FOLD_SHIFTRS) { ++ int c2 = getIntValue(Binary.getVal2(s)); ++ if (def.operator == LONG_SHR) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a >> c1; y = x >> c2 ++ return Binary.create(LONG_SHR, y.copyRO(), a.copyRO(), IC(c1+c2)); ++ } ++ else { ++ return null; ++ } ++ } ++ else ++ return null; ++ } ++ case INT_USHR_opcode: { ++ if (FOLD_INTS && FOLD_SHIFTRS) { ++ int c2 = getIntValue(Binary.getVal2(s)); ++ if (def.operator == INT_USHR) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a >>> c1; y = x >>> c2 ++ return Binary.create(INT_USHR, y.copyRO(), a.copyRO(), IC(c1+c2)); ++ } ++ } ++ return null; ++ } ++ case REF_USHR_opcode: { ++ if (FOLD_REFS && FOLD_SHIFTRS) { ++ int c2 = getIntValue(Binary.getVal2(s)); ++ if (def.operator == REF_USHR) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a >>> c1; y = x >>> c2 ++ return Binary.create(REF_USHR, y.copyRO(), a.copyRO(), IC(c1+c2)); + +- private static OPT_AddressConstantOperand addConstantValues(boolean neg1, OPT_Operand op1, boolean neg2, OPT_Operand op2) { +- Address a = getAddressValue(op1); +- if (neg1) a = Address.zero().minus(a.toWord().toOffset()); //negate op1 +- if (neg2) a = a.minus(getAddressValue(op2).toWord().toOffset()); //sub op2 +- else a = a.plus(getAddressValue(op2).toWord().toOffset()); //add op2 +- return new OPT_AddressConstantOperand(a); +- } +- +- /** +- * Perform the transfomation on the instruction s = A +/- c +- * where def is the definition of A. +- * @return the new instruction to replace s; +- */ +- private static OPT_Instruction transformForInt(OPT_Instruction s, +- OPT_Instruction def) { +- // s is y = A + c +- OPT_RegisterOperand y = Binary.getResult(s); +- // OPT_RegisterOperand A = Binary.getVal1(s).asRegister(); - unused +- int c = getIntValue(Binary.getVal2(s)); +- if (s.operator == INT_SUB) c = -c; ++ } ++ } ++ return null; ++ } ++ case LONG_USHR_opcode: { ++ if (FOLD_LONGS && FOLD_SHIFTRS) { ++ int c2 = getIntValue(Binary.getVal2(s)); ++ if (def.operator == LONG_USHR) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a >>> c1; y = x >>> c2 ++ return Binary.create(LONG_USHR, y.copyRO(), a.copyRO(), IC(c1+c2)); ++ } ++ } ++ return null; ++ } ++ case INT_AND_opcode: { ++ if (FOLD_INTS && FOLD_ANDS) { ++ int c2 = getIntValue(Binary.getVal2(s)); ++ if (def.operator == INT_AND) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a & c1; y = x & c2 ++ return Binary.create(INT_AND, y.copyRO(), a.copyRO(), IC(c1&c2)); ++ } ++ else if (def.operator == INT_OR) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a | c1; y = x & c2 ++ if ((c1 & c2) == 0) { ++ return Binary.create(INT_AND, y.copyRO(), a.copyRO(), IC(c2)); ++ } ++ } ++ else if (def.operator == INT_XOR) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a ^ c1; y = x & c2 ++ if ((c1 & c2) == 0) { ++ return Binary.create(INT_AND, y.copyRO(), a.copyRO(), IC(c2)); ++ } ++ } ++ } ++ return null; ++ } ++ case REF_AND_opcode: { ++ if (FOLD_REFS && FOLD_ANDS) { ++ Address c2 = getAddressValue(Binary.getVal2(s)); ++ if (def.operator == REF_AND) { ++ Address c1 = getAddressValue(Binary.getVal2(def)); ++ // x = a & c1; y = x & c2 ++ return Binary.create(REF_AND, y.copyRO(), a.copyRO(), AC(c1.toWord().and(c2.toWord()).toAddress())); ++ } ++ else if (def.operator == REF_OR) { ++ Address c1 = getAddressValue(Binary.getVal2(def)); ++ // x = a | c1; y = x & c2 ++ if (c1.toWord().and(c2.toWord()).EQ(Word.zero())) { ++ return Binary.create(REF_AND, y.copyRO(), a.copyRO(), AC(c2)); ++ } ++ } ++ else if (def.operator == REF_XOR) { ++ Address c1 = getAddressValue(Binary.getVal2(def)); ++ // x = a ^ c1; y = x & c2 ++ if (c1.toWord().and(c2.toWord()).EQ(Word.zero())) { ++ return Binary.create(REF_AND, y.copyRO(), a.copyRO(), AC(c2)); ++ } ++ } ++ } ++ return null; ++ } ++ case LONG_AND_opcode: { ++ if (FOLD_LONGS && FOLD_ANDS) { ++ long c2 = getLongValue(Binary.getVal2(s)); ++ if (def.operator == LONG_AND) { ++ long c1 = getLongValue(Binary.getVal2(def)); ++ // x = a & c1; y = x & c2 ++ return Binary.create(LONG_AND, y.copyRO(), a.copyRO(), LC(c1&c2)); ++ } ++ else if (def.operator == LONG_OR) { ++ long c1 = getLongValue(Binary.getVal2(def)); ++ // x = a | c1; y = x & c2 ++ if ((c1 & c2) == 0) { ++ return Binary.create(LONG_AND, y.copyRO(), a.copyRO(), LC(c2)); ++ } ++ } ++ else if (def.operator == LONG_XOR) { ++ long c1 = getLongValue(Binary.getVal2(def)); ++ // x = a ^ c1; y = x & c2 ++ if ((c1 & c2) == 0) { ++ return Binary.create(LONG_AND, y.copyRO(), a.copyRO(), LC(c2)); ++ } ++ } ++ } ++ return null; ++ } ++ case INT_OR_opcode: { ++ if (FOLD_INTS && FOLD_ORS) { ++ int c2 = getIntValue(Binary.getVal2(s)); ++ if (def.operator == INT_OR) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a | c1; y = x | c2 ++ return Binary.create(INT_OR, y.copyRO(), a.copyRO(), IC(c1|c2)); ++ } ++ else if (def.operator == INT_AND) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a & c1; y = x | c2 ++ if ((~c1 | c2) == c2) { ++ return Binary.create(INT_OR, y.copyRO(), a.copyRO(), IC(c2)); ++ } ++ } ++ else if (def.operator == INT_XOR) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a ^ c1; y = x | c2 ++ if ((c1 | c2) == c2) { ++ return Binary.create(INT_OR, y.copyRO(), a.copyRO(), IC(c2)); ++ } ++ } ++ } ++ return null; ++ } ++ case REF_OR_opcode: { ++ if (FOLD_REFS && FOLD_ORS) { ++ Address c2 = getAddressValue(Binary.getVal2(s)); ++ if (def.operator == REF_OR) { ++ Address c1 = getAddressValue(Binary.getVal2(def)); ++ // x = a | c1; y = x | c2 ++ return Binary.create(REF_OR, y.copyRO(), a.copyRO(), AC(c1.toWord().or(c2.toWord()).toAddress())); ++ } ++ else if (def.operator == REF_AND) { ++ Address c1 = getAddressValue(Binary.getVal2(def)); ++ // x = a & c1; y = x | c2 ++ if (c1.toWord().not().or(c2.toWord()).EQ(c2.toWord())) { ++ return Binary.create(REF_OR, y.copyRO(), a.copyRO(), AC(c2)); ++ } ++ } ++ else if (def.operator == REF_XOR) { ++ Address c1 = getAddressValue(Binary.getVal2(def)); ++ // x = a ^ c1; y = x | c2 ++ if (c1.toWord().or(c2.toWord()).EQ(c2.toWord())) { ++ return Binary.create(REF_OR, y.copyRO(), a.copyRO(), AC(c2)); ++ } ++ } ++ } ++ return null; ++ } ++ case LONG_OR_opcode: { ++ if (FOLD_LONGS && FOLD_ORS) { ++ long c2 = getLongValue(Binary.getVal2(s)); ++ if (def.operator == LONG_OR) { ++ long c1 = getLongValue(Binary.getVal2(def)); ++ // x = a | c1; y = x | c2 ++ return Binary.create(LONG_OR, y.copyRO(), a.copyRO(), LC(c1|c2)); ++ } ++ else if (def.operator == LONG_AND) { ++ long c1 = getLongValue(Binary.getVal2(def)); ++ // x = a & c1; y = x | c2 ++ if ((~c1 | c2) == c2) { ++ return Binary.create(LONG_OR, y.copyRO(), a.copyRO(), LC(c2)); ++ } ++ } ++ else if (def.operator == LONG_XOR) { ++ long c1 = getLongValue(Binary.getVal2(def)); ++ // x = a ^ c1; y = x | c2 ++ if ((c1 | c2) == c2) { ++ return Binary.create(LONG_OR, y.copyRO(), a.copyRO(), LC(c2)); ++ } ++ } ++ } ++ return null; ++ } ++ case INT_XOR_opcode: { ++ if (FOLD_INTS && FOLD_XORS) { ++ int c2 = getIntValue(Binary.getVal2(s)); ++ if (def.operator == INT_XOR) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a ^ c1; y = x ^ c2 ++ return Binary.create(INT_XOR, y.copyRO(), a.copyRO(), IC(c1^c2)); ++ } ++ else ++ if (def.operator == INT_NOT) { ++ // x = ~a; y = x ^ c2 ++ return Binary.create(INT_XOR, y.copyRO(), a.copyRO(), IC(~c2)); ++ } ++ } ++ return null; ++ } ++ case REF_XOR_opcode: { ++ if (FOLD_REFS && FOLD_XORS) { ++ Address c2 = getAddressValue(Binary.getVal2(s)); ++ if (def.operator == REF_XOR) { ++ Address c1 = getAddressValue(Binary.getVal2(def)); ++ // x = a ^ c1; y = x ^ c2 ++ return Binary.create(REF_XOR, y.copyRO(), a.copyRO(), AC(c1.toWord().xor(c2.toWord()).toAddress())); ++ } ++ else ++ if (def.operator == REF_NOT) { ++ // x = ~a; y = x ^ c2 ++ return Binary.create(REF_XOR, y.copyRO(), a.copyRO(), AC(c2.toWord().not().toAddress())); ++ } ++ } ++ return null; ++ } ++ case LONG_XOR_opcode: { ++ if (FOLD_LONGS && FOLD_XORS) { ++ long c2 = getLongValue(Binary.getVal2(s)); ++ if (def.operator == LONG_XOR) { ++ long c1 = getLongValue(Binary.getVal2(def)); ++ // x = a ^ c1; y = x ^ c2 ++ return Binary.create(LONG_XOR, y.copyRO(), a.copyRO(), LC(c1^c2)); ++ } ++ else ++ if (def.operator == LONG_NOT) { ++ // x = ~a; y = x ^ c2 ++ return Binary.create(LONG_XOR, y.copyRO(), a.copyRO(), LC(~c2)); ++ } ++ } ++ return null; ++ } ++ case LONG_CMP_opcode: { ++ if (FOLD_LONGS && FOLD_CMPS) { ++ long c2 = getLongValue(Binary.getVal2(s)); ++ if (def.operator == LONG_ADD) { ++ long c1 = getLongValue(Binary.getVal2(def)); ++ // x = a + c1; y = x cmp c2 ++ return Binary.create(LONG_CMP, y.copyRO(), a.copyRO(), LC(c2-c1)); ++ } ++ else if (def.operator == LONG_SUB) { ++ long c1 = getLongValue(Binary.getVal2(def)); ++ // x = a - c1; y = x cmp c2 ++ return Binary.create(LONG_CMP, y.copyRO(), a.copyRO(), LC(c1+c2)); ++ } + +- // A = B + d +- OPT_RegisterOperand B = Binary.getVal1(def).asRegister(); +- int d = getIntValue(Binary.getVal2(def)); +- if (def.operator == INT_SUB) d = -d; ++ else if (def.operator == LONG_NEG) { ++ // x = -a; y = x cmp c2 ++ return Binary.create(LONG_CMP, y.copyRO(), LC(-c2), a.copyRO()); ++ } ++ } ++ return null; ++ } ++ case FLOAT_CMPL_opcode: ++ case FLOAT_CMPG_opcode: { ++ if (FOLD_FLOATS && FOLD_CMPS) { ++ float c2 = getFloatValue(Binary.getVal2(s)); ++ if (def.operator == FLOAT_ADD) { ++ float c1 = getFloatValue(Binary.getVal2(def)); ++ // x = a + c1; y = x cmp c2 ++ return Binary.create(s.operator, y.copyRO(), a.copyRO(), FC(c2-c1)); ++ } ++ else if (def.operator == FLOAT_SUB) { ++ float c1 = getFloatValue(Binary.getVal2(def)); ++ // x = a - c1; y = x cmp c2 ++ return Binary.create(s.operator, y.copyRO(), a.copyRO(), FC(c1+c2)); ++ } ++ else if (def.operator == FLOAT_NEG) { ++ // x = -a; y = x cmp c2 ++ return Binary.create(s.operator, y.copyRO(), FC(-c2), a.copyRO()); ++ } ++ } ++ return null; ++ } ++ case DOUBLE_CMPL_opcode: ++ case DOUBLE_CMPG_opcode: { ++ if (FOLD_DOUBLES && FOLD_CMPS) { ++ double c2 = getDoubleValue(Binary.getVal2(s)); ++ if (def.operator == DOUBLE_ADD) { ++ double c1 = getDoubleValue(Binary.getVal2(def)); ++ // x = a + c1; y = x cmp c2 ++ return Binary.create(s.operator, y.copyRO(), a.copyRO(), DC(c2-c1)); ++ } ++ else if (def.operator == DOUBLE_SUB) { ++ double c1 = getDoubleValue(Binary.getVal2(def)); ++ // x = a - c1; y = x cmp c2 ++ return Binary.create(s.operator, y.copyRO(), a.copyRO(), DC(c1+c2)); ++ } ++ else if (def.operator == DOUBLE_NEG) { ++ // x = -a; y = x cmp c2 ++ return Binary.create(s.operator, y.copyRO(), DC(-c2), a.copyRO()); ++ } ++ } ++ return null; ++ } ++ case BOOLEAN_CMP_INT_opcode: { ++ if (FOLD_INTS && FOLD_CMPS) { ++ int c2 = getIntValue(BooleanCmp.getVal2(s)); ++ OPT_ConditionOperand cond = (OPT_ConditionOperand)BooleanCmp.getCond(s).copy(); ++ OPT_BranchProfileOperand prof = (OPT_BranchProfileOperand)BooleanCmp.getBranchProfile(s).copy(); ++ if (def.operator == INT_ADD) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a + c1; y = x cmp c2 ++ return BooleanCmp.create(BOOLEAN_CMP_INT, y.copyRO(), a.copyRO(), IC(c2-c1), cond, prof); ++ } ++ else if (def.operator == INT_SUB) { ++ int c1 = getIntValue(Binary.getVal2(def)); ++ // x = a - c1; y = x cmp c2 ++ return BooleanCmp.create(BOOLEAN_CMP_INT, y.copyRO(), a.copyRO(), IC(c1+c2), cond, prof); ++ } ++ else if (def.operator == INT_NEG) { ++ // x = -a; y = x cmp c2 ++ return BooleanCmp.create(BOOLEAN_CMP_INT, y.copyRO(), a.copyRO(), IC(-c2), cond.flipOperands(), prof); ++ } ++ } ++ return null; ++ } ++ case BOOLEAN_CMP_LONG_opcode: { ++ if (FOLD_LONGS && FOLD_CMPS) { ++ long c2 = getLongValue(BooleanCmp.getVal2(s)); ++ OPT_ConditionOperand cond = (OPT_ConditionOperand)BooleanCmp.getCond(s).copy(); ++ OPT_BranchProfileOperand prof = (OPT_BranchProfileOperand)BooleanCmp.getBranchProfile(s).copy(); ++ if (def.operator == LONG_ADD) { ++ long c1 = getLongValue(Binary.getVal2(def)); ++ // x = a + c1; y = x cmp c2 ++ return BooleanCmp.create(BOOLEAN_CMP_LONG, y.copyRO(), a.copyRO(), LC(c2-c1), cond, prof); ++ } ++ else if (def.operator == LONG_SUB) { ++ long c1 = getLongValue(Binary.getVal2(def)); ++ // x = a - c1; y = x cmp c2 ++ return BooleanCmp.create(BOOLEAN_CMP_LONG, y.copyRO(), a.copyRO(), LC(c1+c2), cond, prof); ++ } ++ else if (def.operator == LONG_NEG) { ++ // x = -a; y = x cmp c2 ++ return BooleanCmp.create(BOOLEAN_CMP_INT, y.copyRO(), a.copyRO(), LC(-c2), cond.flipOperands(), prof); ++ } ++ } ++ return null; ++ } ++ case BOOLEAN_CMP_ADDR_opcode: { ++ if (FOLD_REFS && FOLD_CMPS) { ++ Address c2 = getAddressValue(BooleanCmp.getVal2(s)); ++ OPT_ConditionOperand cond = (OPT_ConditionOperand)BooleanCmp.getCond(s).copy(); ++ OPT_BranchProfileOperand prof = (OPT_BranchProfileOperand)BooleanCmp.getBranchProfile(s).copy(); ++ if (def.operator == REF_ADD) { ++ Address c1 = getAddressValue(BooleanCmp.getVal2(def)); ++ // x = a + c1; y = x cmp c2 ++ return BooleanCmp.create(BOOLEAN_CMP_ADDR, y.copyRO(), a.copyRO(), AC(c2.toWord().minus(c1.toWord()).toAddress()), cond, prof); ++ } ++ else if (def.operator == REF_SUB) { ++ Address c1 = getAddressValue(BooleanCmp.getVal2(def)); ++ // x = a - c1; y = x cmp c2 ++ return BooleanCmp.create(BOOLEAN_CMP_ADDR, y.copyRO(), a.copyRO(), AC(c1.toWord().plus(c2.toWord()).toAddress()), cond, prof); ++ } ++ else if (def.operator == REF_NEG) { ++ // x = -a; y = x cmp c2 ++ return BooleanCmp.create(BOOLEAN_CMP_ADDR, y.copyRO(), a.copyRO(), AC(Word.zero().minus(c2.toWord()).toAddress()), cond.flipOperands(), prof); ++ } ++ } ++ return null; ++ } ++ case INT_IFCMP_opcode: { ++ if (FOLD_INTS && FOLD_IFCMPS) { ++ int c2 = getIntValue(IfCmp.getVal2(s)); ++ OPT_ConditionOperand cond = (OPT_ConditionOperand)IfCmp.getCond(s).copy(); ++ OPT_BranchOperand target = (OPT_BranchOperand)IfCmp.getTarget(s).copy(); ++ OPT_BranchProfileOperand prof = (OPT_BranchProfileOperand)IfCmp.getBranchProfile(s).copy(); ++ if (def.operator == INT_ADD) { ++ int c1 = getIntValue(IfCmp.getVal2(def)); ++ // x = a + c1; y = x cmp c2 ++ return IfCmp.create(INT_IFCMP, y.copyRO(), a.copyRO(), IC(c2-c1), cond, target, prof); ++ } ++ else if (def.operator == INT_SUB) { ++ int c1 = getIntValue(IfCmp.getVal2(def)); ++ // x = a - c1; y = x cmp c2 ++ return IfCmp.create(INT_IFCMP, y.copyRO(), a.copyRO(), IC(c1+c2), cond, target, prof); ++ } ++ else if (def.operator == INT_NEG) { ++ // x = -a; y = x cmp c2 ++ return IfCmp.create(INT_IFCMP, y.copyRO(), a.copyRO(), IC(-c2), cond.flipOperands(), target, prof); ++ } ++ } ++ return null; ++ } ++ case LONG_IFCMP_opcode: { ++ if (FOLD_LONGS && FOLD_IFCMPS) { ++ long c2 = getLongValue(IfCmp.getVal2(s)); ++ OPT_ConditionOperand cond = (OPT_ConditionOperand)IfCmp.getCond(s).copy(); ++ OPT_BranchOperand target = (OPT_BranchOperand)IfCmp.getTarget(s).copy(); ++ OPT_BranchProfileOperand prof = (OPT_BranchProfileOperand)IfCmp.getBranchProfile(s).copy(); ++ if (def.operator == LONG_ADD) { ++ long c1 = getLongValue(IfCmp.getVal2(def)); ++ // x = a + c1; y = x cmp c2 ++ return IfCmp.create(LONG_IFCMP, y.copyRO(), a.copyRO(), LC(c2-c1), cond, target, prof); ++ } ++ else if (def.operator == LONG_SUB) { ++ long c1 = getLongValue(IfCmp.getVal2(def)); ++ // x = a - c1; y = x cmp c2 ++ return IfCmp.create(LONG_IFCMP, y.copyRO(), a.copyRO(), LC(c1+c2), cond, target, prof); ++ } ++ else if (def.operator == LONG_NEG) { ++ // x = -a; y = x cmp c2 ++ return IfCmp.create(LONG_IFCMP, y.copyRO(), a.copyRO(), LC(-c2), cond.flipOperands(), target, prof); ++ } ++ } ++ return null; ++ } ++ case FLOAT_IFCMP_opcode: { ++ if (FOLD_FLOATS && FOLD_IFCMPS) { ++ float c2 = getFloatValue(IfCmp.getVal2(s)); ++ OPT_ConditionOperand cond = (OPT_ConditionOperand)IfCmp.getCond(s).copy(); ++ OPT_BranchOperand target = (OPT_BranchOperand)IfCmp.getTarget(s).copy(); ++ OPT_BranchProfileOperand prof = (OPT_BranchProfileOperand)IfCmp.getBranchProfile(s).copy(); ++ if (def.operator == FLOAT_ADD) { ++ float c1 = getFloatValue(IfCmp.getVal2(def)); ++ // x = a + c1; y = x cmp c2 ++ return IfCmp.create(FLOAT_IFCMP, y.copyRO(), a.copyRO(), FC(c2-c1), cond, target, prof); ++ } ++ else if (def.operator == FLOAT_SUB) { ++ float c1 = getFloatValue(IfCmp.getVal2(def)); ++ // x = a - c1; y = x cmp c2 ++ return IfCmp.create(FLOAT_IFCMP, y.copyRO(), a.copyRO(), FC(c1+c2), cond, target, prof); ++ } ++ else if (def.operator == FLOAT_NEG) { ++ // x = -a; y = x cmp c2 ++ return IfCmp.create(FLOAT_IFCMP, y.copyRO(), a.copyRO(), FC(-c2), cond.flipOperands(), target, prof); ++ } ++ } ++ return null; ++ } ++ case DOUBLE_IFCMP_opcode: { ++ if (FOLD_DOUBLES && FOLD_IFCMPS) { ++ double c2 = getDoubleValue(IfCmp.getVal2(s)); ++ OPT_ConditionOperand cond = (OPT_ConditionOperand)IfCmp.getCond(s).copy(); ++ OPT_BranchOperand target = (OPT_BranchOperand)IfCmp.getTarget(s).copy(); ++ OPT_BranchProfileOperand prof = (OPT_BranchProfileOperand)IfCmp.getBranchProfile(s).copy(); ++ if (def.operator == DOUBLE_ADD) { ++ double c1 = getDoubleValue(IfCmp.getVal2(def)); ++ // x = a + c1; y = x cmp c2 ++ return IfCmp.create(DOUBLE_IFCMP, y.copyRO(), a.copyRO(), DC(c2-c1), cond, target, prof); ++ } ++ else if (def.operator == DOUBLE_SUB) { ++ double c1 = getDoubleValue(IfCmp.getVal2(def)); ++ // x = a - c1; y = x cmp c2 ++ return IfCmp.create(DOUBLE_IFCMP, y.copyRO(), a.copyRO(), DC(c1+c2), cond, target, prof); ++ } ++ else if (def.operator == DOUBLE_NEG) { ++ // x = -a; y = x cmp c2 ++ return IfCmp.create(DOUBLE_IFCMP, y.copyRO(), a.copyRO(), DC(-c2), cond.flipOperands(), target, prof); ++ } ++ } ++ return null; ++ } ++ case REF_IFCMP_opcode: { ++ if (FOLD_REFS && FOLD_IFCMPS) { ++ Address c2 = getAddressValue(IfCmp.getVal2(s)); ++ OPT_ConditionOperand cond = (OPT_ConditionOperand)IfCmp.getCond(s).copy(); ++ OPT_BranchOperand target = (OPT_BranchOperand)IfCmp.getTarget(s).copy(); ++ OPT_BranchProfileOperand prof = (OPT_BranchProfileOperand)IfCmp.getBranchProfile(s).copy(); ++ if (def.operator == REF_ADD) { ++ Address c1 = getAddressValue(IfCmp.getVal2(def)); ++ // x = a + c1; y = x cmp c2 ++ return IfCmp.create(REF_IFCMP, y.copyRO(), a.copyRO(), AC(c2.toWord().minus(c1.toWord()).toAddress()), cond, target, prof); ++ } ++ else if (def.operator == REF_SUB) { ++ Address c1 = getAddressValue(IfCmp.getVal2(def)); ++ // x = a - c1; y = x cmp c2 ++ return IfCmp.create(REF_IFCMP, y.copyRO(), a.copyRO(), AC(c1.toWord().plus(c2.toWord()).toAddress()), cond, target, prof); ++ } ++ else if (def.operator == REF_NEG) { ++ // x = -a; y = x cmp c2 ++ return IfCmp.create(REF_IFCMP, y.copyRO(), a.copyRO(), AC(Word.zero().minus(c2.toWord()).toAddress()), cond.flipOperands(), target, prof); ++ } ++ } ++ return null; ++ } ++ case INT_IFCMP2_opcode: { ++ if (FOLD_INTS && FOLD_IFCMPS) { ++ int c2 = getIntValue(IfCmp.getVal2(s)); ++ OPT_ConditionOperand cond1 = (OPT_ConditionOperand)IfCmp2.getCond1(s).copy(); ++ OPT_ConditionOperand cond2 = (OPT_ConditionOperand)IfCmp2.getCond2(s).copy(); ++ OPT_BranchOperand target1 = (OPT_BranchOperand)IfCmp2.getTarget1(s).copy(); ++ OPT_BranchOperand target2 = (OPT_BranchOperand)IfCmp2.getTarget2(s).copy(); ++ OPT_BranchProfileOperand prof1 = (OPT_BranchProfileOperand)IfCmp2.getBranchProfile1(s).copy(); ++ OPT_BranchProfileOperand prof2 = (OPT_BranchProfileOperand)IfCmp2.getBranchProfile2(s).copy(); ++ if (def.operator == INT_ADD) { ++ int c1 = getIntValue(IfCmp.getVal2(def)); ++ // x = a + c1; y = x cmp c2 ++ return IfCmp2.create(INT_IFCMP, y.copyRO(), a.copyRO(), IC(c2-c1), ++ cond1, target1, prof1, cond2, target2, prof2); ++ } ++ else if (def.operator == INT_SUB) { ++ int c1 = getIntValue(IfCmp.getVal2(def)); ++ // x = a - c1; y = x cmp c2 ++ return IfCmp2.create(INT_IFCMP, y.copyRO(), a.copyRO(), IC(c1+c2), ++ cond1, target1, prof1, cond2, target2, prof2); ++ } ++ } ++ return null; ++ } + +- // rewrite so y = B + (c+d) +- OPT_IntConstantOperand val2 = new OPT_IntConstantOperand(c+d); +- return Binary.create(INT_ADD,y.copyRO(),B.copy(),val2); +- } ++ case INT_NEG_opcode: { ++ if (FOLD_INTS && FOLD_NEGS) { ++ if (def.operator == INT_NEG) { ++ //x = -z; y = -x; ++ return Unary.create(INT_MOVE, y.copyRO(), Unary.getVal(def)); ++ } ++ } ++ return null; ++ } + +- /** +- * Perform the transfomation on the instruction s = A +/- c +- * where def is the definition of A. +- * @return the new instruction to replace s; +- */ +- private static OPT_Instruction transformForLong(OPT_Instruction s, +- OPT_Instruction def) { +- // s is y = A + c +- OPT_RegisterOperand y = Binary.getResult(s); +- // OPT_RegisterOperand A = Binary.getVal1(s).asRegister(); - unused +- long c = Binary.getVal2(s).asLongConstant().value; +- if (s.operator == LONG_SUB) c = -c; ++ case REF_NEG_opcode: { ++ if (FOLD_REFS && FOLD_NEGS) { ++ if (def.operator == REF_NEG) { ++ //x = -z; y = -x; ++ return Unary.create(REF_MOVE, y.copyRO(), Unary.getVal(def)); ++ } ++ } ++ return null; ++ } + +- // A = B + d +- OPT_RegisterOperand B = Binary.getVal1(def).asRegister(); +- long d = Binary.getVal2(def).asLongConstant().value; +- if (def.operator == LONG_SUB) d = -d; ++ case LONG_NEG_opcode: { ++ if (FOLD_LONGS && FOLD_NEGS) { ++ if (def.operator == LONG_NEG) { ++ //x = -z; y = -x; ++ return Unary.create(LONG_MOVE, y.copyRO(), Unary.getVal(def)); ++ } ++ } ++ return null; ++ } + +- // rewrite so y = B + (c+d) +- OPT_LongConstantOperand val2 = new OPT_LongConstantOperand(c+d); +- return Binary.create(LONG_ADD,y.copyRO(),B.copy(),val2); +- } ++ case FLOAT_NEG_opcode: { ++ if (FOLD_FLOATS && FOLD_NEGS) { ++ if (def.operator == FLOAT_NEG) { ++ //x = -z; y = -x; ++ return Unary.create(FLOAT_MOVE, y.copyRO(), Unary.getVal(def)); ++ } ++ } ++ return null; ++ } + +- /** +- * Perform the transfomation on the instruction s = A +/- c +- * where def is the definition of A. +- * @return the new instruction to replace s; +- */ +- private static OPT_Instruction transformForWord(OPT_Instruction s, +- OPT_Instruction def) { +- // s is y = A + c +- OPT_RegisterOperand y = Binary.getResult(s); +- // OPT_RegisterOperand A = Binary.getVal1(s).asRegister(); - unused ++ case DOUBLE_NEG_opcode: { ++ if (FOLD_DOUBLES && FOLD_NEGS) { ++ if (def.operator == DOUBLE_NEG) { ++ //x = -z; y = -x; ++ return Unary.create(DOUBLE_MOVE, y.copyRO(), Unary.getVal(def)); ++ } ++ } ++ return null; ++ } + +- // A = B + d +- OPT_RegisterOperand B = Binary.getVal1(def).asRegister(); ++ case INT_NOT_opcode: { ++ if (FOLD_INTS && FOLD_NOTS) { ++ if (def.operator == INT_NOT) { ++ //x = -1 ^ z; y = -1 ^ x; ++ return Unary.create(INT_MOVE, y.copyRO(), Unary.getVal(def)); ++ } ++ } ++ return null; ++ } + +- // rewrite so y = B + (c+d) +- OPT_AddressConstantOperand val2 = addConstantValues(s.operator == REF_SUB, Binary.getVal2(s), def.operator == REF_SUB, Binary.getVal2(def)); +- return Binary.create(REF_ADD,y.copyRO(),B.copy(),val2); ++ case REF_NOT_opcode: { ++ if (FOLD_REFS && FOLD_NOTS) { ++ if (def.operator == REF_NOT) { ++ //x = -1 ^ z; y = -1 ^ x; ++ return Unary.create(REF_MOVE, y.copyRO(), Unary.getVal(def)); ++ } ++ } ++ return null; ++ } ++ ++ ++ case LONG_NOT_opcode: { ++ if (FOLD_LONGS && FOLD_NOTS) { ++ if (def.operator == LONG_NOT) { ++ //x = -1 ^ z; y = -1 ^ x; ++ return Unary.create(LONG_MOVE, y.copyRO(), Unary.getVal(def)); ++ } ++ } ++ return null; ++ } ++ ++ default: ++ OPT_OptimizingCompilerException.UNREACHABLE(); ++ return null; ++ } + } + + /** +@@ -236,19 +1206,218 @@ + * @return the computed register, or null + */ + private static OPT_Register isCandidateExpression(OPT_Instruction s) { +- if (s.operator == INT_ADD || s.operator == LONG_ADD || +- s.operator == REF_ADD || s.operator == REF_SUB || +- s.operator == INT_SUB || s.operator == LONG_SUB ) { ++ ++ switch(s.operator.opcode) { ++ // Foldable operators ++ ++ case INT_NOT_opcode: ++ case REF_NOT_opcode: ++ case LONG_NOT_opcode: ++ ++ case INT_NEG_opcode: ++ case REF_NEG_opcode: ++ case LONG_NEG_opcode: ++ case FLOAT_NEG_opcode: ++ case DOUBLE_NEG_opcode: { ++ OPT_Operand val1 = Unary.getVal(s); ++ // if val1 is constant too, this should've been constant folded ++ // beforehand. Give up. ++ if (val1.isConstant()) return null; ++ return Unary.getResult(s).asRegister().register; ++ } ++ ++ case INT_ADD_opcode: ++ case REF_ADD_opcode: ++ case LONG_ADD_opcode: ++ case FLOAT_ADD_opcode: ++ case DOUBLE_ADD_opcode: ++ ++ case INT_SUB_opcode: ++ case REF_SUB_opcode: ++ case LONG_SUB_opcode: ++ case FLOAT_SUB_opcode: ++ case DOUBLE_SUB_opcode: ++ ++ case INT_MUL_opcode: ++ case LONG_MUL_opcode: ++ case FLOAT_MUL_opcode: ++ case DOUBLE_MUL_opcode: ++ ++ case INT_SHL_opcode: ++ case REF_SHL_opcode: ++ case LONG_SHL_opcode: ++ ++ case INT_SHR_opcode: ++ case REF_SHR_opcode: ++ case LONG_SHR_opcode: ++ ++ case INT_USHR_opcode: ++ case REF_USHR_opcode: ++ case LONG_USHR_opcode: ++ ++ case INT_AND_opcode: ++ case REF_AND_opcode: ++ case LONG_AND_opcode: ++ ++ case INT_OR_opcode: ++ case REF_OR_opcode: ++ case LONG_OR_opcode: ++ ++ case INT_XOR_opcode: ++ case REF_XOR_opcode: ++ case LONG_XOR_opcode: ++ ++ case LONG_CMP_opcode: ++ case FLOAT_CMPL_opcode: ++ case DOUBLE_CMPL_opcode: ++ case FLOAT_CMPG_opcode: ++ case DOUBLE_CMPG_opcode: { ++ + OPT_Operand val2 = Binary.getVal2(s); +- if (val2.isConstant()) { +- OPT_Operand val1 = Binary.getVal1(s); +- // if val1 is constant too, this should've been constant folded +- // beforehand. Give up. +- if (val1.isConstant()) return null; ++ if (!val2.isObjectConstant()) ++ { ++ if (val2.isConstant()) ++ { ++ OPT_Operand val1 = Binary.getVal1(s); ++ // if val1 is constant too, this should've been constant folded ++ // beforehand. Give up. ++ if (val1.isConstant()) ++ return null; + +- return Binary.getResult(s).asRegister().register; ++ return Binary.getResult(s).asRegister().register; ++ } ++ else ++ { ++ if (VM.VerifyAssertions) ++ VM._assert(val2.isRegister()); ++ ++ OPT_Operand val1 = Binary.getVal1(s); ++ if (s.operator.isCommutative() && val1.isConstant() ++ && !val1.isObjectConstant()) ++ { ++ Binary.setVal1(s, Binary.getClearVal2(s)); ++ Binary.setVal2(s, val1); ++ return Binary.getResult(s).asRegister().register; ++ } ++ } + } ++ return null; + } +- return null; ++ case BOOLEAN_CMP_INT_opcode: ++ case BOOLEAN_CMP_LONG_opcode: ++ case BOOLEAN_CMP_ADDR_opcode: { ++ OPT_Operand val2 = BooleanCmp.getVal2(s); ++ if (!val2.isObjectConstant()) { ++ if (val2.isConstant()) { ++ OPT_Operand val1 = Binary.getVal1(s); ++ // if val1 is constant too, this should've been constant folded ++ // beforehand. Give up. ++ if (val1.isConstant()) return null; ++ ++ return BooleanCmp.getResult(s).asRegister().register; ++ } else { ++ if (VM.VerifyAssertions) VM._assert(val2.isRegister()); ++ OPT_Operand val1 = BooleanCmp.getVal1(s); ++ if (val1.isConstant() && !val1.isObjectConstant()) { ++ BooleanCmp.setVal1(s, BooleanCmp.getClearVal2(s)); ++ BooleanCmp.setVal2(s, val1); ++ BooleanCmp.getCond(s).flipOperands(); ++ return BooleanCmp.getResult(s).asRegister().register; ++ } ++ } ++ } ++ return null; ++ } ++ case INT_IFCMP_opcode: ++ case LONG_IFCMP_opcode: ++ case FLOAT_IFCMP_opcode: ++ case DOUBLE_IFCMP_opcode: ++ case REF_IFCMP_opcode: { ++ OPT... [truncated message content] |
From: <cap...@us...> - 2007-03-27 15:41:15
|
Revision: 11 http://svn.sourceforge.net/pearcolator/?rev=11&view=rev Author: captain5050 Date: 2007-03-27 08:41:07 -0700 (Tue, 27 Mar 2007) Log Message: ----------- Minor changes to build in RVM Modified Paths: -------------- rvmroot.patch Modified: rvmroot.patch =================================================================== --- rvmroot.patch 2007-03-24 23:14:38 UTC (rev 10) +++ rvmroot.patch 2007-03-27 15:41:07 UTC (rev 11) @@ -1,6 +1,6 @@ Index: build.xml =================================================================== ---- build.xml (revision 11878) +--- build.xml (revision 11903) +++ build.xml (working copy) @@ -792,7 +792,7 @@ </condition> @@ -11,6 +11,17 @@ here. We will also be able to compile ALL classes in one sweep. --> <delete dir="${build.classes}"/> +@@ -802,8 +802,8 @@ + debugLevel="lines,source" + source="1.5" + target="1.5" +- srcdir="${main.java}:${classlib.library-interface.common.java}:${classlib.library-interface.cpl.java}:${classlib.library-interface.non-cpl.java}" +- sourcepath="${mmtk.java}:${generated.java}:${generated.config.java}:${generated.arch.java}:${generated.java}:${main.java}:${mmtk-rvm.java}"> ++ srcdir="projects/dbt/ext:${main.java}:${classlib.library-interface.common.java}:${classlib.library-interface.cpl.java}:${classlib.library-interface.non-cpl.java}" ++ sourcepath="${mmtk.java}:${generated.java}:${generated.config.java}:${generated.arch.java}:${generated.java}:projects/dbt/ext:${main.java}:${mmtk-rvm.java}"> + <bootclasspath> + <pathelement location="${classpath.lib.dir}/classpath.jar"/> + </bootclasspath> @@ -862,7 +862,7 @@ </javac> </target> @@ -43,7 +54,7 @@ <!-- * Section for building the boot image * --> Index: rvm/src-generated/opt-ir/InstructionFormatList.dat =================================================================== ---- rvm/src-generated/opt-ir/InstructionFormatList.dat (revision 11878) +--- rvm/src-generated/opt-ir/InstructionFormatList.dat (revision 11903) +++ rvm/src-generated/opt-ir/InstructionFormatList.dat (working copy) @@ -149,6 +149,14 @@ "U Cond OPT_ConditionOperand" "U BranchProfile OPT_BranchProfileOperand" @@ -62,7 +73,7 @@ "D Result OPT_RegisterOperand" "U Val1 OPT_Operand" "U Val2 OPT_Operand" \ Index: rvm/src-generated/opt-ir/OperatorList.dat =================================================================== ---- rvm/src-generated/opt-ir/OperatorList.dat (revision 11878) +--- rvm/src-generated/opt-ir/OperatorList.dat (revision 11903) +++ rvm/src-generated/opt-ir/OperatorList.dat (working copy) @@ -1255,6 +1255,20 @@ @@ -85,9 +96,74 @@ # Load a singed byte # NOTE: Because of our strategy of using explict guard instructions, there is no # way in the HIR/LIR that the actual load instruction can except. +Index: rvm/src/org/jikesrvm/opt/VM_OptCompiledMethod.java +=================================================================== +--- rvm/src/org/jikesrvm/opt/VM_OptCompiledMethod.java (revision 11903) ++++ rvm/src/org/jikesrvm/opt/VM_OptCompiledMethod.java (working copy) +@@ -90,7 +90,7 @@ + int bci = _mcMap.getBytecodeIndexForMCOffset(instructionOffset); + VM_NormalMethod realMethod = _mcMap.getMethodForMCOffset(instructionOffset); + if (bci == -1 || realMethod == null) +- VM.sysFail( "Mapping to source code location not available at Dynamic Linking point\n"); ++ VM.sysFail( "Mapping to source code location not available at Dynamic Linking point\n" + bci + " " + realMethod + " " + instructionOffset.toInt()); + realMethod.getDynamicLink(dynamicLink, bci); + } + +Index: rvm/src/org/jikesrvm/opt/VM_OptLinker.java +=================================================================== +--- rvm/src/org/jikesrvm/opt/VM_OptLinker.java (revision 11903) ++++ rvm/src/org/jikesrvm/opt/VM_OptLinker.java (working copy) +@@ -41,7 +41,7 @@ + int bci = map.getBytecodeIndexForMCOffset(offset); + VM_NormalMethod realMethod = map.getMethodForMCOffset(offset); + if (bci == -1 || realMethod == null) +- VM.sysFail("Mapping to source code location not available at Dynamic Linking point\n"); ++ VM.sysFail( "Mapping to source code location not available at Dynamic Linking point\n" + bci + " " + realMethod); + VM_BytecodeStream bcodes = realMethod.getBytecodes(); + bcodes.reset(bci); + int opcode = bcodes.nextInstruction(); +Index: rvm/src/org/jikesrvm/opt/ir/OPT_CallSiteTreeNode.java +=================================================================== +--- rvm/src/org/jikesrvm/opt/ir/OPT_CallSiteTreeNode.java (revision 11903) ++++ rvm/src/org/jikesrvm/opt/ir/OPT_CallSiteTreeNode.java (working copy) +@@ -29,11 +29,11 @@ + /** + * The call site represented by this tree node + */ +- public OPT_InlineSequence callSite; ++ public final OPT_InlineSequence callSite; + + /** + * The position of this call site in the binary encoding. It is set +- * when by VM_OptEncodedCallSiteTree.getEncoding. ++ * by VM_OptEncodedCallSiteTree.getEncoding. + * + * @see VM_OptEncodedCallSiteTree#getEncoding + */ +Index: rvm/src/org/jikesrvm/VM_RuntimeCompiler.java +=================================================================== +--- rvm/src/org/jikesrvm/VM_RuntimeCompiler.java (revision 11903) ++++ rvm/src/org/jikesrvm/VM_RuntimeCompiler.java (working copy) +@@ -94,7 +94,7 @@ + + // Cache objects needed to cons up compilation plans + // TODO: cutting link to opt compiler by declaring type as object. +- public static Object /* OPT_Options */ options; ++ public static final Object /* OPT_Options */ options = VM.BuildForAdaptiveSystem ? new OPT_Options() : null; + public static Object /* OPT_OptimizationPlanElement[] */ optimizationPlan; + + /** +@@ -567,7 +567,6 @@ + VM_Callbacks.addExitMonitor(new VM_RuntimeCompiler()); + } + if (VM.BuildForAdaptiveSystem) { +- options = new OPT_Options(); + optimizationPlan = OPT_OptimizationPlanner.createOptimizationPlan((OPT_Options)options); + if (VM.MeasureCompilation) { + OPT_OptimizationPlanner.initializeMeasureCompilation(); Index: rvm/src/OptDummy.java =================================================================== ---- rvm/src/OptDummy.java (revision 11878) +--- rvm/src/OptDummy.java (revision 11903) +++ rvm/src/OptDummy.java (working copy) @@ -20,4 +20,5 @@ static org.jikesrvm.opt.OPT_Compiler a; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cap...@us...> - 2007-03-24 23:14:37
|
Revision: 10 http://svn.sourceforge.net/pearcolator/?rev=10&view=rev Author: captain5050 Date: 2007-03-24 16:14:38 -0700 (Sat, 24 Mar 2007) Log Message: ----------- Fix dynamic linking, fix for lazy keys, branch code tidy up, try to spread the use of final fields. Modified Paths: -------------- src/org/binarytranslator/DBT_Options.java src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java src/org/binarytranslator/arch/ppc/decoder/PPC_Laziness.java src/org/binarytranslator/arch/x86/decoder/X86_Laziness.java src/org/binarytranslator/generic/branch/BranchLogic.java src/org/binarytranslator/generic/decoder/DecoderUtils.java src/org/binarytranslator/generic/decoder/Laziness.java src/org/binarytranslator/generic/memory/ByteAddressedByteSwapMemory.java src/org/binarytranslator/generic/memory/ByteAddressedMemory.java src/org/binarytranslator/generic/memory/CallBasedMemory.java src/org/binarytranslator/generic/memory/IntAddressedByteSwapMemory.java src/org/binarytranslator/generic/memory/IntAddressedMemory.java src/org/binarytranslator/generic/memory/IntAddressedPreSwappedMemory.java src/org/binarytranslator/generic/memory/IntAddressedReversedMemory.java src/org/binarytranslator/generic/memory/Memory.java src/org/binarytranslator/generic/os/process/ProcessSpace.java src/org/binarytranslator/vmInterface/DBT_Trace.java src/org/binarytranslator/vmInterface/DynamicCodeRunner.java Modified: src/org/binarytranslator/DBT_Options.java =================================================================== --- src/org/binarytranslator/DBT_Options.java 2007-03-21 15:20:26 UTC (rev 9) +++ src/org/binarytranslator/DBT_Options.java 2007-03-24 23:14:38 UTC (rev 10) @@ -54,16 +54,11 @@ public final static boolean optimizeBackwardBranches = true; /** - * Set this to true to record uncaught bclr instructions + * Set this to true to record uncaught branch instructions */ - public static boolean plantUncaughtBclrWatcher = false; + public static boolean plantUncaughtBranchWatcher = false; /** - * Set this to true to record uncaught bcctr instructions - */ - public static boolean plantUncaughtBcctrWatcher = true; - - /** * Should all branches (excluding to lr and ctr) be resolved in one * big go or one at at a time */ Modified: src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java =================================================================== --- src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java 2007-03-21 15:20:26 UTC (rev 9) +++ src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java 2007-03-24 23:14:38 UTC (rev 10) @@ -125,17 +125,9 @@ /** Reference to PPC process space pc field */ private static final VM_FieldReference pcFieldRef; - /** Reference to PPC process space recordUncaughtBclr method */ - private static final VM_MethodReference recordUncaughtBclrMethRef; - - /** Reference to PPC process space recordUncaughtBcctr method */ - private static final VM_MethodReference recordUncaughtBcctrMethRef; - /* Static initializer */ static { - psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); + psTref = VM_TypeReference.findOrCreate(PPC_ProcessSpace.class); gprFieldRefs = new VM_FieldReference[32]; fprFieldRefs = new VM_FieldReference[32]; final VM_Atom intAtom = VM_Atom.findOrCreateAsciiAtom("I"); @@ -189,12 +181,6 @@ pcFieldRef = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("pc"), intAtom ).asFieldReference(); - recordUncaughtBclrMethRef = (VM_MethodReference)VM_MemberReference.findOrCreate(psTref, - VM_Atom.findOrCreateAsciiAtom("recordUncaughtBclr"), - VM_Atom.findOrCreateAsciiAtom("(II)V")); - recordUncaughtBcctrMethRef = (VM_MethodReference)VM_MemberReference.findOrCreate(psTref, - VM_Atom.findOrCreateAsciiAtom("recordUncaughtBcctr"), - VM_Atom.findOrCreateAsciiAtom("(II)V")); } // -oO PPC register to HIR register mappings Oo- @@ -1018,58 +1004,6 @@ registerBranchAndLink(pc, pc+4, dest); } - // -oO Trace helping methods Oo- - - /** - * Plant a record bclr call. NB register state won't get resolved for call - * @param pc the address of the bclr instruction - * @param lr the link register value - */ - public void plantRecordUncaughtBclr(int pc, OPT_RegisterOperand lr) { - // Is it sensible to record this information? - if((gc.options.getOptLevel() > 0) && (DBT_Options.plantUncaughtBclrWatcher)) { - // Plant call - OPT_Instruction s = Call.create(CALL, null, null, null, null, 3); - VM_Method method = recordUncaughtBclrMethRef.resolve(); - OPT_MethodOperand methOp = OPT_MethodOperand.VIRTUAL(recordUncaughtBclrMethRef, method); - - OPT_Operand psRef = gc.makeLocal(1,psTref); - Call.setParam(s, 0, psRef); // Reference to ps, sets 'this' pointer - Call.setParam(s, 1, new OPT_IntConstantOperand(pc)); // Address of bclr instruction - Call.setParam(s, 2, lr); // Link register value - Call.setGuard(s, new OPT_TrueGuardOperand()); - Call.setMethod(s, methOp); - Call.setAddress(s, new OPT_AddressConstantOperand(recordUncaughtBclrMethRef.peekResolvedMethod().getOffset())); - s.position = gc.inlineSequence; - s.bcIndex = 7; - appendInstructionToCurrentBlock(s); - } - } - - /** - * Plant a record bcctr call. NB register state won't get resolved for call - * @param pc the address of the bclr instruction - * @param ctr the count register value - */ - public void plantRecordUncaughtBcctr(int pc, OPT_RegisterOperand ctr) { - if(DBT_Options.plantUncaughtBcctrWatcher) { - // Plant call - OPT_Instruction s = Call.create(CALL, null, null, null, null, 3); - VM_Method method = recordUncaughtBcctrMethRef.resolve(); - OPT_MethodOperand methOp = OPT_MethodOperand.VIRTUAL(recordUncaughtBcctrMethRef, method); - OPT_Operand psRef = gc.makeLocal(1,psTref); - Call.setParam(s, 0, psRef); // Reference to ps, sets 'this' pointer - Call.setParam(s, 1, new OPT_IntConstantOperand(pc)); // Address of bcctr instruction - Call.setParam(s, 2, ctr); // Count register value - Call.setGuard(s, new OPT_TrueGuardOperand()); - Call.setMethod(s, methOp); - Call.setAddress(s, new OPT_AddressConstantOperand(recordUncaughtBcctrMethRef.peekResolvedMethod().getOffset())); - s.position = gc.inlineSequence; - s.bcIndex = 13; - appendInstructionToCurrentBlock(s); - } - } - // -oO Optimisations on the generated HIR Oo- /** Modified: src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java =================================================================== --- src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java 2007-03-21 15:20:26 UTC (rev 9) +++ src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java 2007-03-24 23:14:38 UTC (rev 10) @@ -13,6 +13,7 @@ import org.binarytranslator.arch.ppc.os.process.PPC_ProcessSpace; import org.binarytranslator.generic.fault.BadInstructionException; import org.binarytranslator.generic.decoder.InstructionDecoder; +import org.binarytranslator.generic.branch.BranchLogic; import org.jikesrvm.opt.ir.*; import org.jikesrvm.*; @@ -3338,7 +3339,7 @@ ppc2ir.appendInstructionToCurrentBlock(lookupswitch_instr); ppc2ir.registerLookupSwitchForReturnUnresolved(lookupswitch_instr, pc, (PPC_Laziness)lazy.clone()); ppc2ir.setCurrentBlock(fallThrough); - ppc2ir.plantRecordUncaughtBclr(pc, branchAddress.copyRO()); + ppc2ir.plantRecordUncaughtBranch(pc, branchAddress.copyRO(), BranchLogic.RETURN); ppc2ir.setReturnValueResolveLazinessAndBranchToFinish((PPC_Laziness)lazy.clone(), branchAddress.copyRO()); // stop translation on branch always @@ -3981,7 +3982,7 @@ ppc2ir.appendInstructionToCurrentBlock(lookupswitch_instr); ppc2ir.registerLookupSwitchForSwitchUnresolved(lookupswitch_instr, pc, (PPC_Laziness)lazy.clone(), lk != 0); ppc2ir.setCurrentBlock(fallThrough); - ppc2ir.plantRecordUncaughtBcctr(pc, branchAddress.copyRO()); + ppc2ir.plantRecordUncaughtBranch(pc, branchAddress.copyRO(), BranchLogic.INDIRECT_BRANCH); ppc2ir.setReturnValueResolveLazinessAndBranchToFinish((PPC_Laziness)lazy.clone(), branchAddress.copyRO()); // stop translation on branch always Modified: src/org/binarytranslator/arch/ppc/decoder/PPC_Laziness.java =================================================================== --- src/org/binarytranslator/arch/ppc/decoder/PPC_Laziness.java 2007-03-21 15:20:26 UTC (rev 9) +++ src/org/binarytranslator/arch/ppc/decoder/PPC_Laziness.java 2007-03-24 23:14:38 UTC (rev 10) @@ -17,6 +17,25 @@ */ public final class PPC_Laziness extends Laziness { /** + * Key for when laziness is stored in a hash table along with a PC + */ + class PPC_LazinessKey extends Key { + int pc; + public int hashCode() { + return pc; + } + public boolean equals(Object o) { + return ((o instanceof PPC_LazinessKey) && ((PPC_LazinessKey)o).pc == pc); + } + PPC_LazinessKey (int pc) { + this.pc = pc; + } + public String toString() { + return "0x" + Integer.toHexString(pc); + } + } + + /** * Default constructor - nothing is lazy */ PPC_Laziness() { @@ -39,23 +58,8 @@ * Generate a key value encoding this laziness and a PC value * @parm pc the PC value we're trying to make a key for */ - public Object makeKey(int pc) { - class Key { - int pc; - public int hashCode() { - return pc; - } - public boolean equals(Object o) { - return ((o instanceof Key) && ((Key)o).pc == pc); - } - Key (int pc) { - this.pc = pc; - } - public String toString() { - return "0x" + Integer.toHexString(pc); - } - } - return new Key(pc); + public Key makeKey(int pc) { + return new PPC_LazinessKey(pc); } /** Modified: src/org/binarytranslator/arch/x86/decoder/X86_Laziness.java =================================================================== --- src/org/binarytranslator/arch/x86/decoder/X86_Laziness.java 2007-03-21 15:20:26 UTC (rev 9) +++ src/org/binarytranslator/arch/x86/decoder/X86_Laziness.java 2007-03-24 23:14:38 UTC (rev 10) @@ -14,6 +14,32 @@ * Capture lazy information for X86 */ public class X86_Laziness extends Laziness { + /** + * Key for when laziness is stored in a hash table along with a PC + */ + static class X86_LazinessKey extends Key { + private final int mangledRegisterState; + private final int pc; + X86_LazinessKey(int mangledRegisterState, int pc) { + this.mangledRegisterState = mangledRegisterState; + this.pc = pc; + } + public boolean equals(Object o) { + if (o instanceof X86_LazinessKey) { + X86_LazinessKey other = (X86_LazinessKey)o; + return (other.pc == pc) && (other.mangledRegisterState == mangledRegisterState); + } else { + return false; + } + } + public int hashCode() { + return mangledRegisterState ^ pc; + } + public String toString() { + return "0x" + Integer.toHexString(pc) + ".0x" + Integer.toHexString(mangledRegisterState); + } + } + /** * In this state, is the 32bit register valid? (default) */ @@ -69,8 +95,8 @@ * Given the current program position make a key object that will * allow */ - public Object makeKey(int pc) { - return new Long(((long)mangledRegisterState << 32) | pc); + public Key makeKey(int pc) { + return new X86_LazinessKey(mangledRegisterState, pc); } /** Modified: src/org/binarytranslator/generic/branch/BranchLogic.java =================================================================== --- src/org/binarytranslator/generic/branch/BranchLogic.java 2007-03-21 15:20:26 UTC (rev 9) +++ src/org/binarytranslator/generic/branch/BranchLogic.java 2007-03-24 23:14:38 UTC (rev 10) @@ -22,15 +22,21 @@ * terminating on branches whose destinations aren't known */ public class BranchLogic { + /** Code to indicate branch was an indirect branch */ + public static final int INDIRECT_BRANCH=0; + + /** Code to indicate branch was a return */ + public static final int RETURN=1; + /** * A set of procedure information */ - private SortedMap procedures; + private final SortedMap procedures; /** * A set of switch like branchs sites and their destinations */ - private SortedMap branchSitesAndDestinations; + private final SortedMap branchSitesAndDestinations; /** * Global branch information @@ -61,13 +67,13 @@ * @param dest the destination of the branch instruction */ public void registerCall(int pc, int ret, int dest) { - ProcedureInformation procedure = (ProcedureInformation)procedures.get(new Integer(dest)); + ProcedureInformation procedure = (ProcedureInformation)procedures.get(Integer.valueOf(dest)); if (procedure != null) { procedure.registerCall(pc, ret); } else { procedure = new ProcedureInformation(pc, ret, dest); - procedures.put(new Integer(dest), procedure); + procedures.put(Integer.valueOf(dest), procedure); } } @@ -90,7 +96,7 @@ */ private ProcedureInformation getLikelyProcedure(int pc) { if (procedures.size() > 0) { - SortedMap priorProcedures = procedures.headMap(new Integer(pc)); + SortedMap priorProcedures = procedures.headMap(Integer.valueOf(pc)); if (priorProcedures.size() > 0) { Integer procedureEntry = (Integer)priorProcedures.lastKey(); return (ProcedureInformation)procedures.get(procedureEntry); @@ -104,19 +110,19 @@ * @param pc the address of the branch instruction * @param lr the value of the link register */ - public void registerBranch(int pc, int ctr) { - Set dests = (Set)branchSitesAndDestinations.get(new Integer(pc)); + public void registerBranch(int pc, int ctr, int type) { + Set dests = (Set)branchSitesAndDestinations.get(Integer.valueOf(pc)); if (dests != null) { - if (dests.contains(new Integer(ctr))) { + if (dests.contains(Integer.valueOf(ctr))) { // This ctr address is already registered return; } } else { dests = new HashSet(); - branchSitesAndDestinations.put(new Integer(pc), dests); + branchSitesAndDestinations.put(Integer.valueOf(pc), dests); } - dests.add(new Integer(ctr)); + dests.add(Integer.valueOf(ctr)); } } Modified: src/org/binarytranslator/generic/decoder/DecoderUtils.java =================================================================== --- src/org/binarytranslator/generic/decoder/DecoderUtils.java 2007-03-21 15:20:26 UTC (rev 9) +++ src/org/binarytranslator/generic/decoder/DecoderUtils.java 2007-03-24 23:14:38 UTC (rev 10) @@ -18,6 +18,7 @@ import org.binarytranslator.vmInterface.DBT_Trace; import org.binarytranslator.vmInterface.TranslationHelper; import org.binarytranslator.generic.os.process.ProcessSpace; +import org.binarytranslator.generic.fault.BadInstructionException; import org.binarytranslator.DBT_Options; import org.jikesrvm.VM; @@ -84,7 +85,174 @@ * </dl> */ public abstract class DecoderUtils implements OPT_Constants, OPT_Operators, TranslationHelper { + // -oO Constants Oo- + + /** + * VM_TypeReference of + * org.binarytranslator.generic.os.process.ProcessSpace + */ + private static final VM_TypeReference psTref; + + /** + * Method ProcessSpace.doSysCall + */ + public static final VM_Method sysCallMethod; + + /** + * VM_TypeReference of + * org.binarytranslator.generic.fault.BadInstructionException + */ + private static final VM_Class badInstrKlass; + + /** + * Method BadInstructionException.<init> + */ + public static final VM_Method badInstrKlassInitMethod; + + /** + * Method ProcessSpace.recordUncaughtBranchBadInstructionException.<init> + */ + public static final VM_Method recordUncaughtBranchMethod; + + static { + psTref = java.lang.JikesRVMSupport.getTypeForClass(ProcessSpace.class).getTypeRef(); + VM_MethodReference sysCallMethRef = (VM_MethodReference) + VM_MemberReference.findOrCreate(psTref, + VM_Atom.findOrCreateAsciiAtom("doSysCall"), + VM_Atom.findOrCreateAsciiAtom("()V")); + sysCallMethod = sysCallMethRef.resolveInvokeSpecial(); + + badInstrKlass = java.lang.JikesRVMSupport.getTypeForClass(BadInstructionException.class).asClass(); + + VM_MethodReference badInstrKlassInitMethRef = (VM_MethodReference) + VM_MemberReference.findOrCreate(badInstrKlass.getTypeRef(), + VM_Atom.findOrCreateAsciiAtom("<init>"), + VM_Atom.findOrCreateAsciiAtom("(I" + + psTref.getName() + + ")V")); + badInstrKlassInitMethod = badInstrKlassInitMethRef.resolveInvokeSpecial(); + + VM_MethodReference recordUncaughtBranchMethRef = (VM_MethodReference) + VM_MemberReference.findOrCreate(psTref, + VM_Atom.findOrCreateAsciiAtom("recordUncaughtBranch"), + VM_Atom.findOrCreateAsciiAtom("(III)V")); + recordUncaughtBranchMethod = recordUncaughtBranchMethRef.resolveInvokeSpecial(); + } + + + // -oO Global IR Oo- + + /** + * Number of translated instructions + */ + public int numberOfInstructions; + + /** + * The process space object used by the running PPC binary. + */ + public ProcessSpace ps; + + /** + * The generation context. + */ + protected OPT_GenerationContext gc; + + // -oO Global HIR basic blocks Oo- + + /** + * The OPT_BasicBlock in which instructions are currently being + * inserted + */ + protected OPT_BasicBlock currentBlock; + + /** + * The pc value corresponding to the instruction currently being + * translated + */ + protected int currentPC; + + /** + * The OPT_BasicBlock which will contain the next translated instruction + */ + protected OPT_BasicBlock nextBlock; + + /** + * The basic block is used by finish trace to hold all the code that + * must be executed before returning to the main run loop + */ + protected OPT_BasicBlock finishBlock; + + /** + * This block gets instructions to pre-fill registers inserted into + * it. + */ + protected OPT_BasicBlock preFillBlock; + + /** + * Map to locate HIR basic blocks to re-use translation within a + * trace + */ + protected final HashMap<Laziness.Key,OPT_BasicBlock> blockMap; + + /** + * List of unresolved Goto instructions + */ + protected final ArrayList<OPT_Instruction> unresolvedGoto; + + /** + * List of where unresolved Goto instructions are trying to go + */ + protected final ArrayList<Integer> unresolvedGoto_PC; + /** + * List of what the unresolved Goto instruction's target laziness should be + */ + protected final ArrayList<Laziness> unresolvedGoto_Laziness; + + /** + * List of unresolved IfCmp instructions + */ + protected final ArrayList<OPT_Instruction> unresolvedIfCmp; + /** + * List of where unresolved IfCmp instructions are trying to go + */ + protected final ArrayList<Integer> unresolvedIfCmp_PC; + /** + * List of what the unresolved IfCmp instruction's target laziness should be + */ + protected final ArrayList<Laziness> unresolvedIfCmp_Laziness; + + /** + * List of unresolved LookupSwitch instructions used for branching to the link register + */ + protected final ArrayList<OPT_Instruction> unresolvedLookupSwitchForReturns; + /** + * List of where unresolved Goto instructions are trying to go + */ + protected final ArrayList<Integer> unresolvedLookupSwitchForReturns_PC; + /** + * List of what the unresolved Goto instruction's target laziness should be + */ + protected final ArrayList<Laziness> unresolvedLookupSwitchForReturns_Laziness; + + /** + * List of unresolved LookupSwitch instructions used for branching to the count register + */ + protected final ArrayList<OPT_Instruction> unresolvedLookupSwitchForSwitches; + /** + * List of where unresolved LookupSwitch instructions are branching from + */ + protected final ArrayList<Integer> unresolvedLookupSwitchForSwitches_PC; + /** + * List of what the unresolved LookupSwitch instruction's target laziness should be + */ + protected final ArrayList<Laziness> unresolvedLookupSwitchForSwitches_Laziness; + /** + * List of whether the unresolved LookupSwitch instruction's was a call + */ + protected final ArrayList<Boolean> unresolvedLookupSwitchForSwitches_WasCall; + // -oO Debug Oo- + /** * Report some debug output */ @@ -117,22 +285,22 @@ finishBlock = createBlockAfterCurrent(); // Fix up stores - unresolvedGoto = new ArrayList(); - unresolvedGoto_PC = new ArrayList(); - unresolvedGoto_Laziness = new ArrayList(); + unresolvedGoto = new ArrayList<OPT_Instruction>(); + unresolvedGoto_PC = new ArrayList<Integer>(); + unresolvedGoto_Laziness = new ArrayList<Laziness>(); - unresolvedIfCmp = new ArrayList(); - unresolvedIfCmp_PC = new ArrayList(); - unresolvedIfCmp_Laziness = new ArrayList(); + unresolvedIfCmp = new ArrayList<OPT_Instruction>(); + unresolvedIfCmp_PC = new ArrayList<Integer>(); + unresolvedIfCmp_Laziness = new ArrayList<Laziness>(); - unresolvedLookupSwitchForReturns = new ArrayList(); - unresolvedLookupSwitchForReturns_PC = new ArrayList(); - unresolvedLookupSwitchForReturns_Laziness = new ArrayList(); + unresolvedLookupSwitchForReturns = new ArrayList<OPT_Instruction>(); + unresolvedLookupSwitchForReturns_PC = new ArrayList<Integer>(); + unresolvedLookupSwitchForReturns_Laziness = new ArrayList<Laziness>(); - unresolvedLookupSwitchForSwitches = new ArrayList(); - unresolvedLookupSwitchForSwitches_PC = new ArrayList(); - unresolvedLookupSwitchForSwitches_Laziness = new ArrayList(); - unresolvedLookupSwitchForSwitches_WasCall = new ArrayList(); + unresolvedLookupSwitchForSwitches = new ArrayList<OPT_Instruction>(); + unresolvedLookupSwitchForSwitches_PC = new ArrayList<Integer>(); + unresolvedLookupSwitchForSwitches_Laziness = new ArrayList<Laziness>(); + unresolvedLookupSwitchForSwitches_WasCall = new ArrayList<Boolean>(); } /** @@ -253,62 +421,7 @@ */ protected abstract int translateInstruction(Laziness lazy, int pc); - // -oO Global IR Oo- - /** - * Number of translated instructions - */ - public int numberOfInstructions; - - /** - * The process space object used by the running PPC binary. - */ - public ProcessSpace ps; - - /** - * The generation context. - */ - protected OPT_GenerationContext gc; - - /** - * Get the generation context. - */ - public OPT_GenerationContext getGenerationContext() { - return gc; - } - - // -oO Global HIR basic blocks Oo- - - /** - * The OPT_BasicBlock in which instructions are currently being - * inserted - */ - protected OPT_BasicBlock currentBlock; - - /** - * The pc value corresponding to the instruction currently being - * translated - */ - protected int currentPC; - - /** - * The OPT_BasicBlock which will contain the next translated instruction - */ - protected OPT_BasicBlock nextBlock; - - /** - * The basic block is used by finish trace to hold all the code that - * must be executed before returning to the main run loop - */ - protected OPT_BasicBlock finishBlock; - - /** - * This block gets instructions to pre-fill registers inserted into - * it. - */ - protected OPT_BasicBlock preFillBlock; - - /** * Get the block which is currently having instructions inserted * into it * @return the current block @@ -421,7 +534,12 @@ public void appendInstructionToCurrentBlock(OPT_Instruction i) { if(i.bcIndex == UNKNOWN_BCI) { i.position = gc.inlineSequence; - i.bcIndex = (currentPC >> 2) & 0xFFFF; + // we only have 16bits to distinguish instructions (the bcIndex + // is effective 16bit when stored in the machine code map), + // Intel can't distinguish branches within 16bytes, so neither + // can we, the top bit is saved for distinguished addresses we + // need to know to dynamically link things + i.bcIndex = (currentPC >> 4) & 0x7FFF; } currentBlock.appendInstruction(i); } @@ -447,71 +565,16 @@ spillAllRegisters(); } - // -oO Laziness Oo- - - /** - * Map to locate HIR basic blocks to re-use translation within a - * trace - */ - protected HashMap blockMap; - /** - * List of unresolved Goto instructions + * Get the generation context. */ - protected ArrayList unresolvedGoto; - /** - * List of where unresolved Goto instructions are trying to go - */ - protected ArrayList unresolvedGoto_PC; - /** - * List of what the unresolved Goto instruction's target laziness should be - */ - protected ArrayList unresolvedGoto_Laziness; + public OPT_GenerationContext getGenerationContext() { + return gc; + } - /** - * List of unresolved IfCmp instructions - */ - protected ArrayList unresolvedIfCmp; - /** - * List of where unresolved IfCmp instructions are trying to go - */ - protected ArrayList unresolvedIfCmp_PC; - /** - * List of what the unresolved IfCmp instruction's target laziness should be - */ - protected ArrayList unresolvedIfCmp_Laziness; + // -oO Laziness Oo- /** - * List of unresolved LookupSwitch instructions used for branching to the link register - */ - protected ArrayList unresolvedLookupSwitchForReturns; - /** - * List of where unresolved Goto instructions are trying to go - */ - protected ArrayList unresolvedLookupSwitchForReturns_PC; - /** - * List of what the unresolved Goto instruction's target laziness should be - */ - protected ArrayList unresolvedLookupSwitchForReturns_Laziness; - - /** - * List of unresolved LookupSwitch instructions used for branching to the count register - */ - protected ArrayList unresolvedLookupSwitchForSwitches; - /** - * List of where unresolved LookupSwitch instructions are branching from - */ - protected ArrayList unresolvedLookupSwitchForSwitches_PC; - /** - * List of what the unresolved LookupSwitch instruction's target laziness should be - */ - protected ArrayList unresolvedLookupSwitchForSwitches_Laziness; - /** - * List of whether the unresolved LookupSwitch instruction's was a call - */ - protected ArrayList unresolvedLookupSwitchForSwitches_WasCall; - - /** * Create the initial object for capturing lazy information */ protected abstract Laziness createInitialLaziness(); @@ -538,7 +601,7 @@ * @return basic block or null if no translation exists */ public OPT_BasicBlock findMapping(int pc, Laziness lazy) { - return (OPT_BasicBlock)blockMap.get(lazy.makeKey(pc)); + return blockMap.get(lazy.makeKey(pc)); } /** @@ -549,7 +612,7 @@ */ public void registerIfCmpTargetUnresolved(OPT_Instruction ifcmp_instr, int targetPC, Laziness targetLaziness){ unresolvedIfCmp.add(ifcmp_instr); - unresolvedIfCmp_PC.add(new Integer(targetPC)); + unresolvedIfCmp_PC.add(targetPC); unresolvedIfCmp_Laziness.add(targetLaziness); } @@ -596,7 +659,7 @@ */ public void registerGotoTargetUnresolved(OPT_Instruction goto_instr, int targetPC, Laziness targetLaziness){ unresolvedGoto.add(goto_instr); - unresolvedGoto_PC.add(new Integer(targetPC)); + unresolvedGoto_PC.add(targetPC); unresolvedGoto_Laziness.add(targetLaziness); } @@ -662,7 +725,7 @@ */ public void registerLookupSwitchForReturnUnresolved(OPT_Instruction lookupswitch_instr, int pc, Laziness targetLaziness){ unresolvedLookupSwitchForReturns.add(lookupswitch_instr); - unresolvedLookupSwitchForReturns_PC.add(new Integer(pc)); + unresolvedLookupSwitchForReturns_PC.add(pc); unresolvedLookupSwitchForReturns_Laziness.add(targetLaziness); } /** @@ -769,9 +832,9 @@ */ public void registerLookupSwitchForSwitchUnresolved(OPT_Instruction lookupswitch_instr, int pc, Laziness targetLaziness, boolean link){ unresolvedLookupSwitchForSwitches.add(lookupswitch_instr); - unresolvedLookupSwitchForSwitches_PC.add(new Integer(pc)); + unresolvedLookupSwitchForSwitches_PC.add(pc); unresolvedLookupSwitchForSwitches_Laziness.add(targetLaziness); - unresolvedLookupSwitchForSwitches_WasCall.add(Boolean.valueOf(link)); + unresolvedLookupSwitchForSwitches_WasCall.add(link); } /** * Are all LookupSwitch instructions for branches to CTR ready to be @@ -1024,25 +1087,19 @@ // Plant call OPT_Instruction s = Call.create(CALL, null, null, null, null, 1); - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - VM_MethodReference methRef = (VM_MethodReference)VM_MemberReference.findOrCreate(psTref, - VM_Atom.findOrCreateAsciiAtom("doSysCall"), - VM_Atom.findOrCreateAsciiAtom("()V")); - VM_Method method = methRef.resolveInvokeSpecial(); // VM_CompiledMethod cm = method.getCurrentCompiledMethod(); // OPT_MethodOperand methOp = OPT_MethodOperand.COMPILED(method, cm.getOsrJTOCoffset()); - OPT_MethodOperand methOp = OPT_MethodOperand.VIRTUAL(methRef, method); + OPT_MethodOperand methOp = OPT_MethodOperand.VIRTUAL(sysCallMethod.getMemberRef().asMethodReference(), + sysCallMethod); OPT_Operand psRef = gc.makeLocal(1,psTref); Call.setParam(s, 0, psRef); // Reference to ps, sets 'this' pointer for doSysCall Call.setGuard(s, new OPT_TrueGuardOperand()); Call.setMethod(s, methOp); - Call.setAddress(s, new OPT_AddressConstantOperand(methRef.peekResolvedMethod().getOffset())); + Call.setAddress(s, new OPT_AddressConstantOperand(sysCallMethod.getOffset())); s.position = gc.inlineSequence; - s.bcIndex = 7; + s.bcIndex = DBT_Trace.DO_SYSCALL; appendInstructionToCurrentBlock(s); // Fill all registers again following system call @@ -1065,52 +1122,40 @@ resolveLaziness(lazy); spillAllRegisters(); - VM_TypeReference eTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/generic/os/fault/BadInstructionException;") - ); - VM_Class badInstrKlass = (VM_Class)eTref.peekResolvedType(); OPT_Operator newOperator; - OPT_TypeOperand typeOperand; + OPT_TypeOperand typeOperand = new OPT_TypeOperand(badInstrKlass); + VM_TypeReference eTref = badInstrKlass.getTypeRef(); - if ((badInstrKlass != null) && (badInstrKlass.isInitialized() || badInstrKlass.isInBootImage())) { + if (badInstrKlass.isInitialized() || badInstrKlass.isInBootImage()) { newOperator = NEW; - typeOperand = new OPT_TypeOperand(badInstrKlass); - } - else { + } else { newOperator = NEW_UNRESOLVED; - typeOperand = new OPT_TypeOperand(eTref); } OPT_RegisterOperand eRef = gc.temps.makeTemp(eTref); OPT_Instruction n = New.create(newOperator,eRef, typeOperand); n.position = gc.inlineSequence; - n.bcIndex = 0; + n.bcIndex = DBT_Trace.BAD_INSTRUCTION_NEW; - VM_MemberReference methRef = VM_MemberReference.findOrCreate(eTref, VM_Atom.findOrCreateAsciiAtom("<init>"), - VM_Atom.findOrCreateAsciiAtom("(ILorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;)V")); - VM_Method method = ((VM_MethodReference)methRef).resolveInvokeSpecial(); - OPT_MethodOperand methOp = OPT_MethodOperand.VIRTUAL((VM_MethodReference)methRef, method); - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - OPT_Operand psRef = gc.makeLocal(1,psTref); OPT_Instruction c = Call.create(CALL, null, null, null, null, 3); + OPT_MethodOperand methOp = OPT_MethodOperand.VIRTUAL(badInstrKlassInitMethod.getMemberRef().asMethodReference(), + badInstrKlassInitMethod); Call.setParam(c, 0, eRef.copy()); // 'this' pointer in BadInstructionException.init Call.setParam(c, 1, new OPT_IntConstantOperand(pc)); Call.setParam(c, 2, psRef); Call.setGuard(c, new OPT_TrueGuardOperand()); Call.setMethod(c, methOp); - Call.setAddress(c, new OPT_AddressConstantOperand(((VM_MethodReference)methRef).peekResolvedMethod().getOffset())); + Call.setAddress(c, new OPT_AddressConstantOperand(badInstrKlassInitMethod.getOffset())); c.position = gc.inlineSequence; - c.bcIndex = 21; + c.bcIndex = DBT_Trace.BAD_INSTRUCTION_INIT; OPT_Instruction t = Athrow.create(ATHROW, eRef.copyRO()); t.position = gc.inlineSequence; - t.bcIndex = 0; + t.bcIndex = DBT_Trace.BAD_INSTRUCTION_THROW; appendInstructionToCurrentBlock(n); @@ -1122,6 +1167,35 @@ } } + // -oO Trace helping methods Oo- + + /** + * Plant a record uncaught branch call. NB register state won't get resolved for call + * @param pc the address of the branch instruction + * @param destination the register operand holding the destination + * @param code a code that can be a hint of the branch type + */ + public void plantRecordUncaughtBranch(int pc, OPT_RegisterOperand destination, int code) { + // Is it sensible to record this information? + if((gc.options.getOptLevel() > 0) && (DBT_Options.plantUncaughtBranchWatcher)) { + // Plant call + OPT_Instruction s = Call.create(CALL, null, null, null, null, 4); + OPT_MethodOperand methOp = OPT_MethodOperand.VIRTUAL(recordUncaughtBranchMethod.getMemberRef().asMethodReference(), + recordUncaughtBranchMethod); + OPT_Operand psRef = gc.makeLocal(1,psTref); + Call.setParam(s, 0, psRef); // Reference to ps, sets 'this' pointer + Call.setParam(s, 1, new OPT_IntConstantOperand(pc)); // Address of branch instruction + Call.setParam(s, 2, destination); // Destination of branch value + Call.setParam(s, 3, new OPT_IntConstantOperand(code)); // Branch code value + Call.setGuard(s, new OPT_TrueGuardOperand()); + Call.setMethod(s, methOp); + Call.setAddress(s, new OPT_AddressConstantOperand(recordUncaughtBranchMethod.getOffset())); + s.position = gc.inlineSequence; + s.bcIndex = DBT_Trace.RECORD_BRANCH; + appendInstructionToCurrentBlock(s); + } + } + // -oO Temporaries used during translation Oo- /** @@ -1274,8 +1348,8 @@ /** * Get the method */ - public VM_Method getMethod() { - return gc.method; + public DBT_Trace getMethod() { + return (DBT_Trace)gc.method; } /** * Make a temporary register Modified: src/org/binarytranslator/generic/decoder/Laziness.java =================================================================== --- src/org/binarytranslator/generic/decoder/Laziness.java 2007-03-21 15:20:26 UTC (rev 9) +++ src/org/binarytranslator/generic/decoder/Laziness.java 2007-03-24 23:14:38 UTC (rev 10) @@ -20,6 +20,12 @@ * elimination will suffice. */ public abstract class Laziness { + /** + * A Key class used when making a key from the laziness and PC + * value combined + */ + public static class Key {} + /** * Constructor */ @@ -35,7 +41,7 @@ * Given the current program position make a key object that will * allow */ - public abstract Object makeKey(int pc); + public abstract Key makeKey(int pc); /** * Create a copy of this lazy state - usually to record where one Modified: src/org/binarytranslator/generic/memory/ByteAddressedByteSwapMemory.java =================================================================== --- src/org/binarytranslator/generic/memory/ByteAddressedByteSwapMemory.java 2007-03-21 15:20:26 UTC (rev 9) +++ src/org/binarytranslator/generic/memory/ByteAddressedByteSwapMemory.java 2007-03-24 23:14:38 UTC (rev 10) @@ -35,7 +35,7 @@ * Constructor - used when this is the instatiated class */ public ByteAddressedByteSwapMemory() { - super("org/binarytranslator/generic/memory/ByteAddressedByteSwapMemory"); + super(ByteAddressedByteSwapMemory.class); } /** * Perform a 16bit load where the sign extended result fills the Modified: src/org/binarytranslator/generic/memory/ByteAddressedMemory.java =================================================================== --- src/org/binarytranslator/generic/memory/ByteAddressedMemory.java 2007-03-21 15:20:26 UTC (rev 9) +++ src/org/binarytranslator/generic/memory/ByteAddressedMemory.java 2007-03-24 23:14:38 UTC (rev 10) @@ -63,17 +63,17 @@ * Constructor - used when this is the instatiated class */ public ByteAddressedMemory() { - super("org/binarytranslator/generic/memory/ByteAddressedMemory"); + super(ByteAddressedMemory.class); readableMemory = new byte[NUM_PAGES][]; writableMemory = new byte[NUM_PAGES][]; executableMemory = new byte[NUM_PAGES][]; } /** * Constructor - used when deriving a class - * @param className the name of the over-riding class + * @param classType the name of the over-riding class */ - protected ByteAddressedMemory(String className) { - super(className); + protected ByteAddressedMemory(Class classType) { + super(classType); readableMemory = new byte[NUM_PAGES][]; writableMemory = new byte[NUM_PAGES][]; executableMemory = new byte[NUM_PAGES][]; Modified: src/org/binarytranslator/generic/memory/CallBasedMemory.java =================================================================== --- src/org/binarytranslator/generic/memory/CallBasedMemory.java 2007-03-21 15:20:26 UTC (rev 9) +++ src/org/binarytranslator/generic/memory/CallBasedMemory.java 2007-03-24 23:14:38 UTC (rev 10) @@ -29,6 +29,8 @@ import org.jikesrvm.opt.ir.OPT_RegisterOperand; import org.jikesrvm.opt.ir.OPT_TrueGuardOperand; import org.binarytranslator.vmInterface.TranslationHelper; +import org.binarytranslator.vmInterface.DBT_Trace; +import org.binarytranslator.generic.os.process.ProcessSpace; /** * CallBasedMemory abstraction: @@ -37,23 +39,59 @@ * which are still abstract, ie there's no memory backing store yet */ public abstract class CallBasedMemory extends Memory implements OPT_Operators { + /** - * The name of the class we are to plant calls to + * The process space type reference */ - private final VM_Atom memoryClassName; + private static final VM_TypeReference psTref; /** - * The name of the store methods + * Field reference to ps.memory */ - private final VM_Atom store8, store16, store32; + private static final VM_FieldReference psMemoryRef; + + static { + psTref = VM_TypeReference.findOrCreate(ProcessSpace.class); + psMemoryRef = VM_MemberReference.findOrCreate(psTref, + VM_Atom.findOrCreateAsciiAtom("memory"), + VM_Atom.findOrCreateAsciiAtom + ("Lorg/binarytranslator/generic/memory/Memory;") + ).asFieldReference(); + } /** - * The name of the load methods + * The store 8 method */ - private final VM_Atom loadS8, loadU8, loadS16, loadU16, load32; + private final VM_Method store8; /** - * Descriptors for the methods + * The store 16 method */ - private final VM_Atom storeDescriptor, loadDescriptor; + private final VM_Method store16; /** + * The store 32 method + */ + private final VM_Method store32; + + /** + * The load signed 8 method + */ + private final VM_Method loadS8; + /** + * The load unsigned 8 method + */ + private final VM_Method loadU8; + /** + * The load signed 8 method + */ + private final VM_Method loadS16; + /** + * The load unsigned 8 method + */ + private final VM_Method loadU16; + /** + * The load 32 method + */ + private final VM_Method load32; + + /** * Type of underlying memory */ final VM_TypeReference memoryType; @@ -74,20 +112,44 @@ * Constructor * @param className the name of the over-riding class */ - protected CallBasedMemory(String className) { - this.memoryClassName = VM_Atom.findOrCreateAsciiAtom("L"+className+";"); - store8 = VM_Atom.findOrCreateAsciiAtom("store8"); - store16 = VM_Atom.findOrCreateAsciiAtom("store16"); - store32 = VM_Atom.findOrCreateAsciiAtom("store32"); - storeDescriptor = VM_Atom.findOrCreateAsciiAtom("(II)V"); - loadS8 = VM_Atom.findOrCreateAsciiAtom("loadSigned8"); - loadU8 = VM_Atom.findOrCreateAsciiAtom("loadUnsigned8"); - loadS16 = VM_Atom.findOrCreateAsciiAtom("loadSigned16"); - loadU16 = VM_Atom.findOrCreateAsciiAtom("loadUnsigned16"); - load32 = VM_Atom.findOrCreateAsciiAtom("load32"); - loadDescriptor = VM_Atom.findOrCreateAsciiAtom("(I)I"); - memoryType = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - memoryClassName); + protected CallBasedMemory(Class memoryClass) { + memoryType = VM_TypeReference.findOrCreate(memoryClass); + + VM_Atom storeDescriptor = VM_Atom.findOrCreateAsciiAtom("(II)V"); + store8 = VM_MemberReference.findOrCreate(memoryType, + VM_Atom.findOrCreateAsciiAtom("store8"), + storeDescriptor + ).asMethodReference().resolve(); + store16 = VM_MemberReference.findOrCreate(memoryType, + VM_Atom.findOrCreateAsciiAtom("store16"), + storeDescriptor + ).asMethodReference().resolve(); + store32 = VM_MemberReference.findOrCreate(memoryType, + VM_Atom.findOrCreateAsciiAtom("store32"), + storeDescriptor + ).asMethodReference().resolve(); + + VM_Atom loadDescriptor = VM_Atom.findOrCreateAsciiAtom("(I)I"); + loadS8 = VM_MemberReference.findOrCreate(memoryType, + VM_Atom.findOrCreateAsciiAtom("loadSigned8"), + loadDescriptor + ).asMethodReference().resolve(); + loadU8 = VM_MemberReference.findOrCreate(memoryType, + VM_Atom.findOrCreateAsciiAtom("loadUnsigned8"), + loadDescriptor + ).asMethodReference().resolve(); + loadS16 = VM_MemberReference.findOrCreate(memoryType, + VM_Atom.findOrCreateAsciiAtom("loadSigned16"), + loadDescriptor + ).asMethodReference().resolve(); + loadU16 = VM_MemberReference.findOrCreate(memoryType, + VM_Atom.findOrCreateAsciiAtom("loadUnsigned16"), + loadDescriptor + ).asMethodReference().resolve(); + load32 = VM_MemberReference.findOrCreate(memoryType, + VM_Atom.findOrCreateAsciiAtom("load32"), + loadDescriptor + ).asMethodReference().resolve(); } /** * Generate memory prologue,... for the beignning of a @@ -96,55 +158,35 @@ public void initTranslate(TranslationHelper helper) { this.helper = helper; this.gc = helper.getGenerationContext(); - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/generic/os/process/ProcessSpace;") - ); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref, VM_Atom.findOrCreateAsciiAtom("memory"), - VM_Atom.findOrCreateAsciiAtom - ("Lorg/binarytranslator/generic/memory/Memory;") - ).asFieldReference(); OPT_RegisterOperand memoryOp = helper.makeTemp(memoryType); helper.appendInstructionToCurrentBlock(GetField.create(GETFIELD, memoryOp, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(psMemoryRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(psMemoryRef), new OPT_TrueGuardOperand())); memory = memoryOp.register; } /** * Generate the IR code for the specified load - * @param loadType the atom name of the type of load + * @param loadMethod the load method to create * @param bcIndex the bytecode index in * DummyDynamicCodeRunner.invokeCode of this method call - required * for lazy method resolution. * @param dest the register to hold the result * @param addr the address of the value to load */ - private void translateLoad(VM_Atom loadType, int bcIndex, OPT_RegisterOperand addr, OPT_RegisterOperand dest) { + private void translateLoad(VM_Method loadMethod, int bcIndex, OPT_RegisterOperand addr, OPT_RegisterOperand dest) { OPT_Instruction s = Call.create(CALL, dest, null, null, null, - 2); - VM_MemberReference methRef = VM_MemberReference.findOrCreate(memoryType, - loadType, - loadDescriptor - ); - boolean unresolved = methRef.needsDynamicLink(helper.getMethod()); - VM_Method method = ((VM_MethodReference)methRef).resolveInvokeSpecial(); - OPT_MethodOperand methOp = OPT_MethodOperand.VIRTUAL((VM_MethodReference)methRef, method); + 2); + VM_MethodReference loadMethRef = loadMethod.getMemberRef().asMethodReference(); + + OPT_MethodOperand methOp = OPT_MethodOperand.VIRTUAL(loadMethRef, loadMethod); OPT_RegisterOperand memoryOp = new OPT_RegisterOperand(memory, memoryType); Call.setParam(s, 0, memoryOp); // Sets 'this' pointer Call.setParam(s, 1, addr); Call.setGuard(s, new OPT_TrueGuardOperand()); Call.setMethod(s, methOp); - if (unresolved) { - OPT_RegisterOperand offsetrop = gc.temps.makeTempOffset(); - helper.appendInstructionToCurrentBlock(Unary.create(RESOLVE_MEMBER, offsetrop, - Call.getMethod(s).copy())); - Call.setAddress(s, offsetrop.copyRO()); - } - else { - Call.setAddress(s, new OPT_AddressConstantOperand - (((VM_MethodReference)methRef).peekResolvedMethod().getOffset())); - } + Call.setAddress(s, new OPT_AddressConstantOperand(loadMethod.getOffset())); s.position = gc.inlineSequence; s.bcIndex = bcIndex; helper.appendInstructionToCurrentBlock(s); @@ -156,7 +198,7 @@ * @param addr the address of the value to load */ public void translateLoadSigned8(OPT_RegisterOperand addr, OPT_RegisterOperand dest) { - translateLoad(loadS8, 56, addr, dest); + translateLoad(loadS8, DBT_Trace.MEMORY_LOAD8, addr, dest); } /** * Generate the IR code for a byte load where the zero extended @@ -165,7 +207,7 @@ * @param addr the address of the value to load */ public void translateLoadUnsigned8(OPT_RegisterOperand addr, OPT_RegisterOperand dest) { - translateLoad(loadU8, 65, addr, dest); + translateLoad(loadU8, DBT_Trace.MEMORY_ULOAD8, addr, dest); } /** * Generate the IR code for a 16bit load where the sign extended @@ -174,7 +216,7 @@ * @param addr the address of the value to load */ public void translateLoadSigned16(OPT_RegisterOperand addr, OPT_RegisterOperand dest) { - translateLoad(loadS16, 74, addr, dest); + translateLoad(loadS16, DBT_Trace.MEMORY_LOAD16, addr, dest); } /** * Generate the IR code for a 16bit load where the zero extended @@ -183,7 +225,7 @@ * @param addr the address of the value to load */ public void translateLoadUnsigned16(OPT_RegisterOperand addr, OPT_RegisterOperand dest) { - translateLoad(loadU16, 83, addr, dest); + translateLoad(loadU16, DBT_Trace.MEMORY_ULOAD16, addr, dest); } /** * Generate the IR code for a 32bit load @@ -191,7 +233,7 @@ * @param addr the address of the value to load */ public void translateLoad32(OPT_RegisterOperand addr, OPT_RegisterOperand dest) { - translateLoad(load32, 92, addr, dest); + translateLoad(load32, DBT_Trace.MEMORY_LOAD32, addr, dest); } /** * Generate the IR code for a 16bit load where the sign extended @@ -200,7 +242,7 @@ * @param addr the address of the value to load */ protected void translateCallBasedLoadSigned16(OPT_RegisterOperand addr, OPT_RegisterOperand dest) { - translateLoad(loadS16, 74, addr, dest); + translateLoad(loadS16, DBT_Trace.MEMORY_LOAD16, addr, dest); } /** * Generate the IR code for a 16bit load where the zero extended @@ -209,7 +251,7 @@ * @param addr the address of the value to load */ protected void translateCallBasedLoadUnsigned16(OPT_RegisterOperand addr, OPT_RegisterOperand dest) { - translateLoad(loadU16, 83, addr, dest); + translateLoad(loadU16, DBT_Trace.MEMORY_ULOAD16, addr, dest); } /** * Generate the IR code for a 32bit load @@ -217,42 +259,28 @@ * @param addr the address of the value to load */ protected void translateCallBasedLoad32(OPT_RegisterOperand addr, OPT_RegisterOperand dest) { - translateLoad(load32, 92, addr, dest); + translateLoad(load32, DBT_Trace.MEMORY_LOAD32, addr, dest); } /** * Generate the IR code for the specified store - * @param storeType the atom name of the type of store + * @param storeMethod the store method to call * @param bcIndex the bytecode index in * DummyDynamicCodeRunner.invokeCode of this method call - required * for lazy method resolution. * @param src the register that holds the value to store * @param addr the address of the value to store */ - private void translateStore(VM_Atom storeType, int bcIndex, OPT_RegisterOperand addr, OPT_RegisterOperand src) { + private void translateStore(VM_Method storeMethod, int bcIndex, OPT_RegisterOperand addr, OPT_RegisterOperand src) { OPT_Instruction s = Call.create(CALL, null, null, null, null, 3); - VM_MemberReference methRef = VM_MemberReference.findOrCreate(memoryType, - storeType, - storeDescriptor - ); - boolean unresolved = methRef.needsDynamicLink(helper.getMethod()); - VM_Method method = ((VM_MethodReference)methRef).resolveInvokeSpecial(); - OPT_MethodOperand methOp = OPT_MethodOperand.VIRTUAL((VM_MethodReference)methRef, method); + VM_MethodReference storeMethRef = storeMethod.getMemberRef().asMethodReference(); + OPT_MethodOperand methOp = OPT_MethodOperand.VIRTUAL(storeMethRef, storeMethod); OPT_RegisterOperand memoryOp = new OPT_RegisterOperand(memory, memoryType); Call.setParam(s, 0, memoryOp); // Sets 'this' pointer Call.setParam(s, 1, addr); Call.setParam(s, 2, src); Call.setGuard(s, new OPT_TrueGuardOperand()); Call.setMethod(s, methOp); - if (unresolved) { - OPT_RegisterOperand offsetrop = gc.temps.makeTempOffset(); - helper.appendInstructionToCurrentBlock(Unary.create(RESOLVE_MEMBER, offsetrop, - Call.getMethod(s).copy())); - Call.setAddress(s, offsetrop.copyRO()); - } - else { - Call.setAddress(s, new OPT_AddressConstantOperand - (((VM_MethodReference)methRef).peekResolvedMethod().getOffset())); - } + Call.setAddress(s, new OPT_AddressConstantOperand(storeMethod.getOffset())); s.position = gc.inlineSequence; s.bcIndex = bcIndex; helper.appendInstructionToCurrentBlock(s); @@ -263,7 +291,7 @@ * @param addr the address of the value to store */ public void translateStore8(OPT_RegisterOperand addr, OPT_RegisterOperand src) { - translateStore(store8, 30, addr, src); + translateStore(store8, DBT_Trace.MEMORY_STORE8, addr, src); } /** * Generate the IR code for a 16bit store @@ -271,7 +299,7 @@ * @param addr the address of the value to store */ public void translateStore16(OPT_RegisterOperand addr, OPT_RegisterOperand src) { - translateStore(store16, 39, addr, src); + translateStore(store16, DBT_Trace.MEMORY_STORE16, addr, src); } /** * Generate the IR code for a 32bit store @@ -279,7 +307,7 @@ * @param addr the address of the value to store */ public void translateStore32(OPT_RegisterOperand addr, OPT_RegisterOperand src) { - translateStore(store32, 48, addr, src); + translateStore(store32, DBT_Trace.MEMORY_STORE32, addr, src); } /** * Generate the IR code for a byte store @@ -287,7 +315,7 @@ * @param addr the address of the value to store */ public void translateCallBasedStore8(OPT_RegisterOperand addr, OPT_RegisterOperand src) { - translateStore(store8, 30, addr, src); + translateStore(store8, DBT_Trace.MEMORY_STORE8, addr, src); } /** * Generate the IR code for a 16bit store @@ -295,7 +323,7 @@ * @param addr the address of the value to store */ public void translateCallBasedStore16(OPT_RegisterOperand addr, OPT_RegisterOperand src) { - translateStore(store16, 39, addr, src); + translateStore(store16, DBT_Trace.MEMORY_STORE16, addr, src); } /** * Generate the IR code for a 32bit store @@ -303,6 +331,32 @@ * @param addr the address of the value to store */ public void translateCallBasedStore32(OPT_RegisterOperand addr, OPT_RegisterOperand src) { - translateStore(store32, 48, addr, src); + translateStore(store32, DBT_Trace.MEMORY_STORE32, addr, src); } + /** + * Get method reference if linking a call + * @param callAddress the address associated with this call + */ + public VM_MethodReference getMethodRef(int callAddress) { + switch (callAddress) { + case DBT_Trace.MEMORY_STORE8: + return store8.getMemberRef().asMethodReference(); + case DBT_Trace.MEMORY_STORE16: + return store16.getMemberRef().asMethodReference(); + case DBT_Trace.MEMORY_STORE32: + return store32.getMemberRef().asMethodReference(); + case DBT_Trace.MEMORY_LOAD8: + return loadS8.getMemberRef().asMethodReference(); + case DBT_Trace.MEMORY_ULOAD8: + return loadU8.getMemberRef().asMethodReference(); + case DBT_Trace.MEMORY_LOAD16: + return loadS16.getMemberRef().asMethodReference(); + case DBT_Trace.MEMORY_ULOAD16: + return loadU16.getMemberRef().asMethodReference(); + case DBT_Trace.MEMORY_LOAD32: + return load32.getMemberRef().asMethodReference(); + default: + throw new Error("Error linking method at " + callAddress + " for memory model " + this.getClass()); + } + } } Modified: src/org/binarytranslator/generic/memory/IntAddressedByteSwapMemory.java =================================================================== --- src/org/binarytranslator/generic/memory/IntAddressedByteSwapMemory.java 2007-03-21 15:20:26 UTC (rev 9) +++ src/org/binarytranslator/generic/memory/IntAddressedByteSwapMemory.java 2007-03-24 23:14:38 UTC (rev 10) @@ -31,7 +31,7 @@ * Constructor - used when this is the instatiated class */ public IntAddressedByteSwapMemory() { - super("org/binarytranslator/IntAddressedByteSwapMemory"); + super(IntAddressedByteSwapMemory.class); } /** * Perform a 16bit load where the sign extended result fills the Modified: src/org/binarytranslator/generic/memory/IntAddressedMemory.java =================================================================== --- src/org/binarytranslator/generic/memory/IntAddressedMemory.java 2007-03-21 15:20:26 UTC (rev 9) +++ src/org/binarytranslator/generic/memory/IntAddressedMemory.java 2007-03-24 23:14:38 UTC (rev 10) @@ -58,17 +58,17 @@ * Constructor - used when this is the instatiated class */ public IntAddressedMemory() { - super("org/binarytranslator/IntAddressedMemory"); + super(IntAddressedMemory.class); readableMemory = new int[NUM_PAGES][]; writableMemory = new int[NUM_PAGES][]; executableMemory = new int[NUM_PAGES][]; } /** * Constructor - used when deriving a class - * @param className the name of the over-riding class + * @param classType the type of the over-riding class */ - protected IntAddressedMemory(String className) { - super(className); + protected IntAddressedMemory(Class classType) { + super(classType); readableMemory = new int[NUM_PAGES][]; writableMemory = new int[NUM_PAGES][]; executableMemory = new int[NUM_PAGES][]; Modified: src/org/binarytranslator/generic/memory/IntAddressedPreSwappedMemory.java =================================================================== --- src/org/binarytranslator/generic/memory/IntAddressedPreSwappedMemory.java 2007-03-21 15:20:26 UTC (rev 9) +++ src/org/binarytranslator/generic/memory/IntAddressedPreSwappedMemory.java 2007-03-24 23:14:38 UTC (rev 10) @@ -54,13 +54,13 @@ * Constructor */ public IntAddressedPreSwappedMemory() { - super("org/binarytranslator/IntAddressedPreSwappedMemory"); + super(IntAddressedPreSwappedMemory.class); } /** * Constructor */ - protected IntAddressedPreSwappedMemory(String className) { - super(className); + protected IntAddressedPreSwappedMemory(Class classType) { + super(classType); } /** * Read an int from RandomAccessFile ensuring that a byte swap is performed Modified: src/org/binarytranslator/generic/memory/IntAddressedReversedMemory.java =================================================================== --- src/org/binarytranslator/generic/memory/IntAddressedReversedMemory.java 2007-03-21 15:20:26 UTC (rev 9) +++ src/org/binarytranslator/generic/memory/IntAddressedReversedMemory.java 2007-03-24 23:14:38 UTC (rev 10) @@ -33,7 +33,7 @@ * Constructor */ public IntAddressedReversedMemory() { - super("org/binarytranslator/IntAddressedReversedMemory"); + super(IntAddressedReversedMemory.class); } /** * Return the offset part of the address Modified: src/org/binarytranslator/generic/memory/Memory.java =================================================================== --- src/org/binarytranslator/generic/memory/Memory.java 2007-03-21 15:20:26 UTC (rev 9) +++ src/org/binarytranslator/generic/memory/Memory.java 2007-03-24 23:14:38 UTC (rev 10) @@ -9,6 +9,7 @@ package org.binarytranslator.generic.memory; import org.jikesrvm.opt.ir.OPT_RegisterOperand; +import org.jikesrvm.classloader.VM_MethodReference; import org.binarytranslator.vmInterface.TranslationHelper; import java.io.RandomAccessFile; @@ -182,4 +183,11 @@ * @param addr the address of the value to store */ public abstract void translateStore32(OPT_RegisterOperand addr, OPT_RegisterOperand src); + /** + * Get method reference if linking a call + * @param callAddress the address associated with this call + *... [truncated message content] |
From: <cap...@us...> - 2007-03-21 15:20:25
|
Revision: 9 http://svn.sourceforge.net/pearcolator/?rev=9&view=rev Author: captain5050 Date: 2007-03-21 08:20:26 -0700 (Wed, 21 Mar 2007) Log Message: ----------- Fix to PowerPC stack initialization, still need to make a generic stack initializer Modified Paths: -------------- src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java src/org/binarytranslator/generic/os/process/ProcessSpace.java Modified: src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java 2007-03-21 15:19:39 UTC (rev 8) +++ src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java 2007-03-21 15:20:26 UTC (rev 9) @@ -32,6 +32,11 @@ private int brk; /** + * The top of the stack + */ + private static final int STACK_TOP = 0xC0000000; + + /** * Constructor */ public X86_LinuxProcessSpace(Loader loader) { @@ -72,34 +77,10 @@ LinuxStackInitializer.AuxiliaryVectorType.AT_EGID, DBT_Options.GID, LinuxStackInitializer.AuxiliaryVectorType.AT_SECURE, 0, - // LinuxStackInitializer.AuxiliaryVectorType.AT_PLATFORM, LinuxStackInitializer.AuxiliaryVectorType.STACK_TOP - getPlatformString().length, + //LinuxStackInitializer.AuxiliaryVectorType.AT_PLATFORM, LinuxStackInitializer.AuxiliaryVectorType.STACK_TOP - getPlatformString().length, LinuxStackInitializer.AuxiliaryVectorType.AT_NULL, 0x0}; - /* The cache sizes and flags are as for a test program running on - the iBook, softwood. AT_BASE will need to be changed for dynamically linked binaries. */ - - /* Environment variables, exactly as on softwood. Not that the number 8380 in SSH_* varies. */ - String[] env = {"HOSTNAME=softwood", "PVM_RSH=/usr/bin/rsh", - "HOST_JAVA_HOME=/home/amulocal/linux/appl/j2sdk1.4.2", "SHELL=/bin/bash", - "TERM=xterm", "HISTSIZE=1000", "SSH_CLIENT=130.88.194.110 8380 22", - "CVSROOT=/home/simgroup/cvsroot", "QTDIR=/usr/lib/qt-3.1", "SSH_TTY=/dev/pts/0", - "RVM_HOST_CONFIG=/home/matleyr/cvs/rvm/config/i686-pc-linux-gnu.ManCS", - "USER=matleyr", "LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:", "XENVIRONMENT=/home/matleyr/.Xdefaults", - "PVM_ROOT=/usr/share/pvm3", "CLASSPATH_ROOT=/home/matleyr/cvs/classpath", - "PATH=/home/matleyr/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/opt/lib/j2re1.3.1/bin:/home/matleyr/cvs/rvm/bin:/home/matleyr/bin", "MAIL=/var/spool/mail/matleyr", - "_=/bin/bash", "PWD=/home/matleyr/dhry", "INPUTRC=/etc/inputrc", - "LANG=en_GB.iso88591", "LAMHELPFILE=/etc/lam/lam-helpfile", - "SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass", - "CSHOME=ma...@an...:/home/M03/cc/matleyr", "HOME=/home/matleyr", - "SHLVL=1", "SIM=/home/simgroup/matleyr", "XPVM_ROOT=/usr/share/pvm3/xpvm", - "RVM_ROOT=/home/matleyr/cvs", "LOGNAME=matleyr", "PRINTER=happy_duplex", - "SSH_CONNECTION=130.88.194.110 2380 130.88.198.215 22", - "LESSOPEN=|/usr/bin/lesspipe.sh %s", "RVM_BUILD=/tmp/RVMbuild", - "DISPLAY=localhost:10.0", - "RVM_TARGET_CONFIG=/home/matleyr/cvs/rvm/config/i686-pc-linux-gnu.ManCS", - "G_BROKEN_FILENAMES=1"}; - - return LinuxStackInitializer.stackInit(memory, 0xC0000000, args, env, auxVector); + return LinuxStackInitializer.stackInit(memory, STACK_TOP, args, getEnvironmentVariables(), auxVector); } /** Modified: src/org/binarytranslator/generic/os/process/ProcessSpace.java =================================================================== --- src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-03-21 15:19:39 UTC (rev 8) +++ src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-03-21 15:20:26 UTC (rev 9) @@ -393,12 +393,32 @@ */ public abstract void doSysCall(); + private static final String[] env = {"HOSTNAME=softwood", "PVM_RSH=/usr/bin/rsh", + "HOST_JAVA_HOME=/home/amulocal/linux/appl/j2sdk1.4.2", "SHELL=/bin/bash", + "TERM=xterm", "HISTSIZE=1000", "SSH_CLIENT=130.88.194.110 8380 22", + "CVSROOT=/home/simgroup/cvsroot", "QTDIR=/usr/lib/qt-3.1", "SSH_TTY=/dev/pts/0", + "RVM_HOST_CONFIG=/home/matleyr/cvs/rvm/config/i686-pc-linux-gnu.ManCS", + "USER=matleyr", "LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:", "XENVIRONMENT=/home/matleyr/.Xdefaults", + "PVM_ROOT=/usr/share/pvm3", "CLASSPATH_ROOT=/home/matleyr/cvs/classpath", + "PATH=/home/matleyr/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/opt/lib/j2re1.3.1/bin:/home/matleyr/cvs/rvm/bin:/home/matleyr/bin", "MAIL=/var/spool/mail/matleyr", + "_=/bin/bash", "PWD=/home/matleyr/dhry", "INPUTRC=/etc/inputrc", + "LANG=en_GB.iso88591", "LAMHELPFILE=/etc/lam/lam-helpfile", + "SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass", + "CSHOME=ma...@an...:/home/M03/cc/matleyr", "HOME=/home/matleyr", + "SHLVL=1", "SIM=/home/simgroup/matleyr", "XPVM_ROOT=/usr/share/pvm3/xpvm", + "RVM_ROOT=/home/matleyr/cvs", "LOGNAME=matleyr", "PRINTER=happy_duplex", + "SSH_CONNECTION=130.88.194.110 2380 130.88.198.215 22", + "LESSOPEN=|/usr/bin/lesspipe.sh %s", "RVM_BUILD=/tmp/RVMbuild", + "DISPLAY=localhost:10.0", + "RVM_TARGET_CONFIG=/home/matleyr/cvs/rvm/config/i686-pc-linux-gnu.ManCS", + "G_BROKEN_FILENAMES=1"}; /** * Method to return environment variables * @return an array of environment variable strings */ protected String[] getEnvironmentVariables() { - throw new Error("TODO!"); + /* Environment variables, exactly as on softwood. Not that the number 8380 in SSH_* varies. */ + return env; /* if (!DBT_Options.loadEnv) { Process printenv = Runtime.exec("/usr/bin/printenv"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cap...@us...> - 2007-03-21 15:19:48
|
Revision: 8 http://svn.sourceforge.net/pearcolator/?rev=8&view=rev Author: captain5050 Date: 2007-03-21 08:19:39 -0700 (Wed, 21 Mar 2007) Log Message: ----------- Fixes to get DBT_Trace(s) compiled properly by the runtime compiler Modified Paths: -------------- build.xml ext/DBT_Dummy.java src/org/binarytranslator/vmInterface/DBT_Trace.java Added Paths: ----------- ext/org/jikesrvm/VM_RuntimeCompiler.java ext/org/jikesrvm/opt/ir/OPT_ConvertBCtoHIR.java Modified: build.xml =================================================================== --- build.xml 2007-03-21 15:14:00 UTC (rev 7) +++ build.xml 2007-03-21 15:19:39 UTC (rev 8) @@ -18,6 +18,7 @@ <delete verbose="true"> <fileset dir="${build.classes}"> <include name="org/jikesrvm/opt/ir/ia32/OPT_IA32ConditionOperand.class" /> + <include name="org/jikesrvm/opt/ir/OPT_ConvertBCtoHIR.class" /> <include name="org/jikesrvm/opt/ir/OPT_HIRGenerator.class" /> <include name="org/jikesrvm/opt/ir/OPT_GenerationContext.class" /> <include name="org/jikesrvm/opt/ir/OPT_ConditionOperand.class" /> @@ -27,6 +28,7 @@ <include name="org/jikesrvm/ppc/PPC_Disassembler.class" /> <include name="org/jikesrvm/ppc/opcode_tab.class" /> <include name="org/jikesrvm/ppc/opcodeXX.class" /> + <include name="org/jikesrvm/VM_RuntimeCompiler.class" /> <include name="org/jikesrvm/classloader/VM_Method.class" /> <include name="org/jikesrvm/classloader/VM_Member.class" /> <include name="org/jikesrvm/classloader/VM_NormalMethod.class" /> Modified: ext/DBT_Dummy.java =================================================================== --- ext/DBT_Dummy.java 2007-03-21 15:14:00 UTC (rev 7) +++ ext/DBT_Dummy.java 2007-03-21 15:19:39 UTC (rev 8) @@ -22,4 +22,6 @@ static org.jikesrvm.classloader.VM_Method j; static org.jikesrvm.classloader.VM_Member k; static org.jikesrvm.classloader.VM_NormalMethod l; + static org.jikesrvm.VM_RuntimeCompiler m; + static org.jikesrvm.opt.ir.OPT_ConvertBCtoHIR n; } Added: ext/org/jikesrvm/VM_RuntimeCompiler.java =================================================================== --- ext/org/jikesrvm/VM_RuntimeCompiler.java (rev 0) +++ ext/org/jikesrvm/VM_RuntimeCompiler.java 2007-03-21 15:19:39 UTC (rev 8) @@ -0,0 +1,773 @@ +/* + * This file is part of Jikes RVM (http://jikesrvm.sourceforge.net). + * The Jikes RVM 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 IBM Corp. 2001, 2005 + */ +package org.jikesrvm; + +import org.jikesrvm.classloader.*; +import org.jikesrvm.opt.*; +import org.jikesrvm.adaptive.*; +import org.jikesrvm.ArchitectureSpecific.VM_JNICompiler; + +/** + * Harness to select which compiler to dynamically + * compile a method in first invocation. + * + * A place to put code common to all runtime compilers. + * This includes instrumentation code to get equivalent data for + * each of the runtime compilers. + * <p> + * We collect the following data for each compiler + * <ol> + * <li> + * total number of methods complied by the compiler + * <li> + * total compilation time in milliseconds. + * <li> + * total number of bytes of bytecodes compiled by the compiler + * (under the assumption that there is no padding in the bytecode + * array and thus VM_Method.getBytecodes().length is the number bytes + * of bytecode for a method) + * <li> + * total number of machine code insructions generated by the compiler + * (under the assumption that there is no (excessive) padding in the + * machine code array and thus VM_CompiledMethod.numberOfInsturctions() + * is a close enough approximation of the number of machinecodes generated) + * </ol> + * Note that even if 3. & 4. are inflated due to padding, the numbers will + * still be an accurate measure of the space costs of the compile-only + * approach. + * + * @author Matthew Arnold + * @author Dave Grove + * @author Michael Hind + */ +public class VM_RuntimeCompiler implements VM_Constants, + VM_Callbacks.ExitMonitor { + + // Use these to encode the compiler for record() + public static final byte JNI_COMPILER = 0; + public static final byte BASELINE_COMPILER = 1; + public static final byte OPT_COMPILER = 2; + + // Data accumulators + private static final String[] name = {"JNI\t","Base\t","Opt\t"}; // Output names + private static int[] totalMethods = {0,0,0}; + private static double[] totalCompTime = {0,0,0}; + private static int[] totalBCLength = {0,0,0}; + private static int[] totalMCLength = {0,0,0}; + + // running sum of the natural logs of the rates, + // used for geometric mean, the product of rates is too big for doubles + // so we use the principle of logs to help us + // We compute e ** ((log a + log b + ... + log n) / n ) + private static double[] totalLogOfRates = {0,0,0}; + + // We can't record values until Math.log is loaded, so we miss the first few + private static int[] totalLogValueMethods = {0,0,0}; + + private static String[] earlyOptArgs = new String[0]; + + // is the opt compiler usable? + protected static boolean compilerEnabled; + + // is opt compiler currently in use? + // This flag is used to detect/avoid recursive opt compilation. + // (ie when opt compilation causes a method to be compiled). + // We also make all public entrypoints static synchronized methods + // because the opt compiler is not reentrant. + // When we actually fix defect 2912, we'll have to implement a different + // scheme that can distinguish between recursive opt compilation by the same + // thread (always bad) and parallel opt compilation (currently bad, future ok). + // NOTE: This code can be quite subtle, so please be absolutely sure + // you know what you're doing before modifying it!!! + protected static boolean compilationInProgress; + + // One time check to optionally preload and compile a specified class + protected static boolean preloadChecked = false; + + // Cache objects needed to cons up compilation plans + // TODO: cutting link to opt compiler by declaring type as object. + public static Object /* OPT_Options */ options; + public static Object /* OPT_OptimizationPlanElement[] */ optimizationPlan; + + /** + * To be called when the VM is about to exit. + * @param value the exit value + */ + public void notifyExit(int value) { + report(false); + } + + /** + * This method records the time and sizes (bytecode and machine code) for + * a compilation. + * @param compiler the compiler used + * @param method the resulting VM_Method + * @param compiledMethod the resulting compiled method + */ + public static void record(byte compiler, + VM_NormalMethod method, + VM_CompiledMethod compiledMethod) { + + recordCompilation(compiler, method.getBytecodeLength(), + compiledMethod.numberOfInstructions(), + compiledMethod.getCompilationTime()); + + if (VM.BuildForAdaptiveSystem) { + if (VM_AOSLogging.booted()) { + VM_AOSLogging.recordUpdatedCompilationRates(compiler, + method, + method.getBytecodeLength(), + totalBCLength[compiler], + compiledMethod.numberOfInstructions(), + totalMCLength[compiler], + compiledMethod.getCompilationTime(), + totalCompTime[compiler], + totalLogOfRates[compiler], + totalLogValueMethods[compiler], + totalMethods[compiler]); + } + } + } + + /** + * This method records the time and sizes (bytecode and machine code) for + * a compilation + * @param compiler the compiler used + * @param method the resulting VM_Method + * @param compiledMethod the resulting compiled method + */ + public static void record(byte compiler, + VM_NativeMethod method, + VM_CompiledMethod compiledMethod) { + + + recordCompilation(compiler, + 0, // don't have any bytecode info, its native + compiledMethod.numberOfInstructions(), + compiledMethod.getCompilationTime()); + } + + /** + * This method does the actual recording + * @param compiler the compiler used + * @param BCLength the number of bytecodes in method source + * @param MCLength the length of the generated machine code + * @param compTime the compilation time in ms + */ + private static void recordCompilation(byte compiler, + int BCLength, + int MCLength, + double compTime) { + + totalMethods[compiler]++; + totalMCLength[compiler] += MCLength; + totalCompTime[compiler] += compTime; + + // Comp rate not useful for JNI compiler because there is no bytecode! + if (compiler != JNI_COMPILER) { + totalBCLength[compiler] += BCLength; + double rate = BCLength / compTime; + + // need to be fully booted before calling log + if (VM.fullyBooted) { + // we want the geometric mean, but the product of rates is too big + // for doubles, so we use the principle of logs to help us + // We compute e ** ((log a + log b + ... + log n) / n ) + totalLogOfRates[compiler] += Math.log(rate); + totalLogValueMethods[compiler]++; + } + } + } + + /** + * This method produces a summary report of compilation activities + * @param explain Explains the metrics used in the report + */ + public static void report (boolean explain) { + VM.sysWrite("\n\t\tCompilation Subsystem Report\n"); + VM.sysWrite("Comp\t#Meths\tTime\tbcb/ms\tmcb/bcb\tMCKB\tBCKB\n"); + for (int i=0; i<=name.length-1; i++) { + if (totalMethods[i]>0) { + VM.sysWrite(name[i]); + // Number of methods + VM.sysWrite(totalMethods[i]); + VM.sysWrite("\t"); + // Compilation time + VM.sysWrite(totalCompTime[i]); + VM.sysWrite("\t"); + + if (i == JNI_COMPILER) { + VM.sysWrite("NA"); + } else { + // Bytecode bytes per millisecond, + // use unweighted geomean + VM.sysWrite(Math.exp(totalLogOfRates[i] / totalLogValueMethods[i]), 2); + } + VM.sysWrite("\t"); + // Ratio of machine code bytes to bytecode bytes + if (i != JNI_COMPILER) { + VM.sysWrite((double)(totalMCLength[i] << ArchitectureSpecific.VM_RegisterConstants.LG_INSTRUCTION_WIDTH)/(double)totalBCLength[i], 2); + } else { + VM.sysWrite("NA"); + } + VM.sysWrite("\t"); + // Generated machine code Kbytes + VM.sysWrite((double)(totalMCLength[i] << ArchitectureSpecific.VM_RegisterConstants.LG_INSTRUCTION_WIDTH)/1024, 1); + VM.sysWrite("\t"); + // Compiled bytecode Kbytes + if (i != JNI_COMPILER) { + VM.sysWrite((double)totalBCLength[i]/1024, 1); + } else { + VM.sysWrite("NA"); + } + VM.sysWrite("\n"); + } + } + if (explain) { + // Generate an explanation of the metrics reported + VM.sysWrite("\t\t\tExplanation of Metrics\n"); + VM.sysWrite("#Meths:\t\tTotal number of methods compiled by the compiler\n"); + VM.sysWrite("Time:\t\tTotal compilation time in milliseconds\n"); + VM.sysWrite("bcb/ms:\t\tNumber of bytecode bytes complied per millisecond\n"); + VM.sysWrite("mcb/bcb:\tRatio of machine code bytes to bytecode bytes\n"); + VM.sysWrite("MCKB:\t\tTotal number of machine code bytes generated in kilobytes\n"); + VM.sysWrite("BCKB:\t\tTotal number of bytecode bytes compiled in kilobytes\n"); + } + + VM_BaselineCompiler.generateBaselineCompilerSubsystemReport(explain); + + if (VM.BuildForAdaptiveSystem) { + // Get the opt's report + VM_TypeReference theTypeRef = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), + VM_Atom.findOrCreateAsciiAtom("Lorg/jikesrvm/opt/OPT_OptimizationPlanner;")); + VM_Type theType = theTypeRef.peekResolvedType(); + if (theType != null && theType.asClass().isInitialized()) { + OPT_OptimizationPlanner.generateOptimizingCompilerSubsystemReport(explain); + } else { + VM.sysWrite("\n\tNot generating Optimizing Compiler SubSystem Report because \n"); + VM.sysWrite("\tthe opt compiler was never invoked.\n\n"); + } + } + } + + /** + * Return the current estimate of basline-compiler rate, in bcb/msec + */ + public static double getBaselineRate() { + return Math.exp(totalLogOfRates[BASELINE_COMPILER] / totalLogValueMethods[BASELINE_COMPILER]); + } + + /** + * This method will compile the passed method using the baseline compiler. + * @param method the method to compile + */ + public static VM_CompiledMethod baselineCompile(VM_NormalMethod method) { + VM_Callbacks.notifyMethodCompile(method, VM_CompiledMethod.BASELINE); + long start = 0; + if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { + start = VM_Thread.getCurrentThread().accumulateCycles(); + } + + VM_CompiledMethod cm = VM_BaselineCompiler.compile(method); + + if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { + long end = VM_Thread.getCurrentThread().accumulateCycles(); + double compileTime = VM_Time.cyclesToMillis(end - start); + cm.setCompilationTime(compileTime); + record(BASELINE_COMPILER, method, cm); + } + + return cm; + } + + /** + * Process command line argument destined for the opt compiler + */ + public static void processOptCommandLineArg(String prefix, String arg) { + if (VM.BuildForAdaptiveSystem) { + if (compilerEnabled) { + if (((OPT_Options)options).processAsOption(prefix, arg)) { + // update the optimization plan to reflect the new command line argument + optimizationPlan = OPT_OptimizationPlanner.createOptimizationPlan((OPT_Options)options); + } else { + VM.sysWrite("Unrecognized opt compiler argument \""+arg+"\""); + VM.sysExit(VM.EXIT_STATUS_BOGUS_COMMAND_LINE_ARG); + } + } else { + String[] tmp = new String[earlyOptArgs.length+2]; + for (int i=0; i<earlyOptArgs.length; i++) { + tmp[i] = earlyOptArgs[i]; + } + earlyOptArgs = tmp; + earlyOptArgs[earlyOptArgs.length-2] = prefix; + earlyOptArgs[earlyOptArgs.length-1] = arg; + } + } else { + if (VM.VerifyAssertions) VM._assert(NOT_REACHED); + } + } + + /** + * attempt to compile the passed method with the OPT_Compiler. + * Don't handle OPT_OptimizingCompilerExceptions + * (leave it up to caller to decide what to do) + * Precondition: compilationInProgress "lock" has been acquired + * @param method the method to compile + * @param plan the plan to use for compiling the method + */ + private static VM_CompiledMethod optCompile(VM_NormalMethod method, + OPT_CompilationPlan plan) + throws OPT_OptimizingCompilerException { + if (VM.BuildForOptCompiler) { + if (VM.VerifyAssertions) { + VM._assert(compilationInProgress, "Failed to acquire compilationInProgress \"lock\""); + } + + VM_Callbacks.notifyMethodCompile(method, VM_CompiledMethod.JNI); + long start = 0; + if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { + start = VM_Thread.getCurrentThread().accumulateCycles(); + } + + VM_CompiledMethod cm = OPT_Compiler.compile(plan); + + if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { + long end = VM_Thread.getCurrentThread().accumulateCycles(); + double compileTime = VM_Time.cyclesToMillis(end - start); + cm.setCompilationTime(compileTime); + record(OPT_COMPILER, method, cm); + } + + return cm; + } else { + if (VM.VerifyAssertions) VM._assert(false); + return null; + } + } + + + // These methods are safe to invoke from VM_RuntimeCompiler.compile + + /** + * This method tries to compile the passed method with the OPT_Compiler, + * using the default compilation plan. If + * this fails we will use the quicker compiler (baseline for now) + * The following is carefully crafted to avoid (infinte) recursive opt + * compilation for all combinations of bootimages & lazy/eager compilation. + * Be absolutely sure you know what you're doing before changing it !!! + * @param method the method to compile + */ + public static synchronized VM_CompiledMethod optCompileWithFallBack(VM_NormalMethod method) { + if (VM.BuildForOptCompiler) { + if (compilationInProgress) { + return fallback(method); + } else { + try { + compilationInProgress = true; + OPT_CompilationPlan plan = new OPT_CompilationPlan(method, (OPT_OptimizationPlanElement[])optimizationPlan, null, (OPT_Options)options); + return optCompileWithFallBackInternal(method, plan); + } finally { + compilationInProgress = false; + } + } + } else { + if (VM.VerifyAssertions) VM._assert(false); + return null; + } + } + + /** + * This method tries to compile the passed method with the OPT_Compiler + * with the passed compilation plan. If + * this fails we will use the quicker compiler (baseline for now) + * The following is carefully crafted to avoid (infinte) recursive opt + * compilation for all combinations of bootimages & lazy/eager compilation. + * Be absolutely sure you know what you're doing before changing it !!! + * @param method the method to compile + * @param plan the compilation plan to use for the compile + */ + public static synchronized VM_CompiledMethod optCompileWithFallBack(VM_NormalMethod method, + OPT_CompilationPlan plan) { + if (VM.BuildForOptCompiler) { + if (compilationInProgress) { + return fallback(method); + } else { + try { + compilationInProgress = true; + return optCompileWithFallBackInternal(method, plan); + } finally { + compilationInProgress = false; + } + } + } else { + if (VM.VerifyAssertions) VM._assert(false); + return null; + } + } + + /** + * This real method that performs the opt compilation. + * @param method the method to compile + * @param plan the compilation plan to use + */ + private static VM_CompiledMethod optCompileWithFallBackInternal(VM_NormalMethod method, + OPT_CompilationPlan plan) { + if (VM.BuildForOptCompiler) { + if (method.hasNoOptCompileAnnotation()) return fallback(method); + try { + return optCompile(method, plan); + } catch (OPT_OptimizingCompilerException e) { + String msg = "VM_RuntimeCompiler: can't optimize \"" + method + "\" (error was: " + e + "): reverting to baseline compiler\n"; + if (e.isFatal && VM.ErrorsFatal) { + e.printStackTrace(); + VM.sysFail(msg); + } else { + boolean printMsg = true; + if (e instanceof OPT_MagicNotImplementedException) { + printMsg = !((OPT_MagicNotImplementedException)e).isExpected; + } + if (printMsg) VM.sysWrite(msg); + } + return fallback(method); + } + } else { + if (VM.VerifyAssertions) VM._assert(false); + return null; + } + } + + + /* recompile the specialized method with OPT_Compiler. */ + public static VM_CompiledMethod recompileWithOptOnStackSpecialization(OPT_CompilationPlan plan) { + if (VM.BuildForOptCompiler) { + if (VM.VerifyAssertions) { VM._assert(plan.method.isForOsrSpecialization());} + if (compilationInProgress) { + return null; + } + + try { + compilationInProgress = true; + + // the compiler will check if isForOsrSpecialization of the method + VM_CompiledMethod cm = optCompile(plan.method, plan); + + // we donot replace the compiledMethod of original method, + // because it is temporary method + return cm; + } catch (OPT_OptimizingCompilerException e) { + e.printStackTrace(); + String msg = "Optimizing compiler " + +"(via recompileWithOptOnStackSpecialization): " + +"can't optimize \"" + plan.method + "\" (error was: " + e + ")\n"; + + if (e.isFatal && VM.ErrorsFatal) { + VM.sysFail(msg); + } else { + VM.sysWrite(msg); + } + return null; + } finally { + compilationInProgress = false; + } + } else { + if (VM.VerifyAssertions) VM._assert(false); + return null; + } + } + + /** + * This method tries to compile the passed method with the OPT_Compiler. + * It will install the new compiled method in the VM, if sucessful. + * NOTE: the recompile method should never be invoked via + * VM_RuntimeCompiler.compile; + * it does not have sufficient guards against recursive recompilation. + * @param plan the compilation plan to use + * @return the CMID of the new method if successful, -1 if the + * recompilation failed. + * + **/ + public static synchronized int recompileWithOpt(OPT_CompilationPlan plan) { + if (VM.BuildForOptCompiler) { + if (compilationInProgress) { + return -1; + } else { + try { + compilationInProgress = true; + VM_CompiledMethod cm = optCompile(plan.method, plan); + try { + plan.method.replaceCompiledMethod(cm); + } catch (Throwable e) { + String msg = "Failure in VM_Method.replaceCompiledMethod (via recompileWithOpt): while replacing \"" + plan.method + "\" (error was: " + e + ")\n"; + if (VM.ErrorsFatal) { + e.printStackTrace(); + VM.sysFail(msg); + } else { + VM.sysWrite(msg); + } + return -1; + } + return cm.getId(); + } catch (OPT_OptimizingCompilerException e) { + String msg = "Optimizing compiler (via recompileWithOpt): can't optimize \"" + plan.method + "\" (error was: " + e + ")\n"; + if (e.isFatal && VM.ErrorsFatal) { + e.printStackTrace(); + VM.sysFail(msg); + } else { + // VM.sysWrite(msg); + } + return -1; + } finally { + compilationInProgress = false; + } + } + } else { + if (VM.VerifyAssertions) VM._assert(false); + return -1; + } + } + + /** + * A wrapper method for those callers who don't want to make + * optimization plans + * @param method the method to recompile + */ + public static int recompileWithOpt(VM_NormalMethod method) { + if (VM.BuildForOptCompiler) { + OPT_CompilationPlan plan = new OPT_CompilationPlan(method, + (OPT_OptimizationPlanElement[])optimizationPlan, + null, + (OPT_Options)options); + return recompileWithOpt(plan); + } else { + if (VM.VerifyAssertions) VM._assert(false); + return -1; + } + } + + /** + * This method uses the default compiler (baseline) to compile a method + * It is typically called when a more aggressive compilation fails. + * This method is safe to invoke from VM_RuntimeCompiler.compile + */ + protected static VM_CompiledMethod fallback(VM_NormalMethod method) { + // call the inherited method "baselineCompile" + return baselineCompile(method); + } + + public static void boot() { + if (VM.MeasureCompilation) { + VM_Callbacks.addExitMonitor(new VM_RuntimeCompiler()); + } + if (VM.BuildForAdaptiveSystem) { + options = new OPT_Options(); + optimizationPlan = OPT_OptimizationPlanner.createOptimizationPlan((OPT_Options)options); + if (VM.MeasureCompilation) { + OPT_OptimizationPlanner.initializeMeasureCompilation(); + } + + OPT_Compiler.init((OPT_Options)options); + + VM_PreCompile.init(); + // when we reach here the OPT compiler is enabled. + compilerEnabled = true; + + for (int i=0; i<earlyOptArgs.length; i+=2) { + processOptCommandLineArg(earlyOptArgs[i], earlyOptArgs[i+1]); + } + } + } + + public static void processCommandLineArg(String prefix, String arg) { + if (VM.BuildForAdaptiveSystem) { + if (VM_Controller.options !=null && VM_Controller.options.optIRC()) { + processOptCommandLineArg(prefix, arg); + } else { + VM_BaselineCompiler.processCommandLineArg(prefix, arg); + } + } else { + VM_BaselineCompiler.processCommandLineArg(prefix, arg); + } + } + + /** + * Compile a Java method when it is first invoked. + * @param method the method to compile + * @return its compiled method. + */ + public static VM_CompiledMethod compile(VM_NormalMethod method) { + if (VM.BuildForAdaptiveSystem) { + VM_CompiledMethod cm; + if (!VM_Controller.enabled) { + // System still early in boot process; compile with baseline compiler + cm = baselineCompile(method); + VM_ControllerMemory.incrementNumBase(); + } else { + if (!preloadChecked) { + preloadChecked = true; // prevent subsequent calls + // N.B. This will use irc options + if (VM_BaselineCompiler.options.PRELOAD_CLASS != null) { + compilationInProgress = true; // use baseline during preload + // Other than when boot options are requested (processed during preloadSpecialClass + // It is hard to communicate options for these special compilations. Use the + // default options and at least pick up the verbose if requested for base/irc + OPT_Options tmpoptions = (OPT_Options)((OPT_Options)options).clone(); + tmpoptions.PRELOAD_CLASS = VM_BaselineCompiler.options.PRELOAD_CLASS; + tmpoptions.PRELOAD_AS_BOOT = VM_BaselineCompiler.options.PRELOAD_AS_BOOT; + if (VM_BaselineCompiler.options.PRINT_METHOD) { + tmpoptions.PRINT_METHOD = true; + } else { + tmpoptions = (OPT_Options)options; + } + OPT_Compiler.preloadSpecialClass(tmpoptions); + compilationInProgress = false; + } + } + if (VM_Controller.options.optIRC() || method.optCompileOnly()) { + if (// will only run once: don't bother optimizing + method.isClassInitializer() || + // exception in progress. can't use opt compiler: + // it uses exceptions and runtime doesn't support + // multiple pending (undelivered) exceptions [--DL] + VM_Thread.getCurrentThread().hardwareExceptionRegisters.inuse) { + // compile with baseline compiler + cm = baselineCompile(method); + VM_ControllerMemory.incrementNumBase(); + } else { // compile with opt compiler + VM_AOSInstrumentationPlan instrumentationPlan = + new VM_AOSInstrumentationPlan(VM_Controller.options, method); + OPT_CompilationPlan compPlan = + new OPT_CompilationPlan(method, (OPT_OptimizationPlanElement[])optimizationPlan, + instrumentationPlan, (OPT_Options)options); + if(!method.optCompileOnly()) { + cm = optCompileWithFallBack(method, compPlan); + } + else { + compilationInProgress = true; + try { + cm = optCompile(method, compPlan); + } catch (OPT_OptimizingCompilerException e) { + String msg = "Optimizing compiler " + +"(on method that can only be optimizing compiler compiled): " + +"can't optimize \"" + method + "\""; + throw new Error(msg, e); + } finally { + compilationInProgress = false; + } + } + } + } else { + if ((VM_Controller.options.BACKGROUND_RECOMPILATION + && (!VM_Controller.options.ENABLE_REPLAY_COMPILE) + && (!VM_Controller.options.ENABLE_PRECOMPILE)) + ) { + // must be an inital compilation: compile with baseline compiler + // or if recompilation with OSR. + cm = baselineCompile(method); + VM_ControllerMemory.incrementNumBase(); + } else { + if (VM_CompilerAdviceAttribute.hasAdvice()) { + VM_CompilerAdviceAttribute attr = + VM_CompilerAdviceAttribute.getCompilerAdviceInfo(method); + if (attr.getCompiler() != VM_CompiledMethod.OPT) { + cm=fallback(method); + VM_AOSLogging.recordCompileTime(cm, 0.0); + return cm; + } + int newCMID = -2; + OPT_CompilationPlan compPlan; + if (VM_Controller.options.counters()) { + // for invocation counter, we only use one optimization level + compPlan = VM_InvocationCounts.createCompilationPlan(method); + } else { + // for now there is not two options for sampling, so + // we don't have to use: if (VM_Controller.options.sampling()) + compPlan = VM_Controller.recompilationStrategy.createCompilationPlan(method, attr.getOptLevel(), null); + } + VM_AOSLogging.recompilationStarted(compPlan); + newCMID = recompileWithOpt(compPlan); + cm = newCMID == -1 ? null : VM_CompiledMethods.getCompiledMethod(newCMID); + if (newCMID == -1) { + VM_AOSLogging.recompilationAborted(compPlan); + } else if (newCMID > 0) { + VM_AOSLogging.recompilationCompleted(compPlan); + } + if (cm == null) { // if recompilation is aborted + cm = baselineCompile(method); + VM_ControllerMemory.incrementNumBase(); + } + } else { + // check to see if there is a compilation plan for this method. + VM_ControllerPlan plan = VM_ControllerMemory.findLatestPlan(method); + if (plan == null || plan.getStatus() != VM_ControllerPlan.IN_PROGRESS) { + // initial compilation or some other funny state: compile with baseline compiler + cm = baselineCompile(method); + VM_ControllerMemory.incrementNumBase(); + } else { + cm = plan.doRecompile(); + if (cm == null) { + // opt compilation aborted for some reason. + cm = baselineCompile(method); + } + } + } + } + } + } + if ((VM_Controller.options.ENABLE_ADVICE_GENERATION) + && (cm.getCompilerType() == VM_CompiledMethod.BASELINE) + && VM_Controller.enabled) { + VM_AOSGenerator.baseCompilationCompleted(cm); + } + VM_AOSLogging.recordCompileTime(cm, 0.0); + return cm; + } else { + return baselineCompile(method); + } + } + + /** + * Compile the stub for a native method when it is first invoked. + * @param method the method to compile + * @return its compiled method. + */ + public static VM_CompiledMethod compile(VM_NativeMethod method) { + VM_Callbacks.notifyMethodCompile(method, VM_CompiledMethod.JNI); + long start = 0; + if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { + start = VM_Thread.getCurrentThread().accumulateCycles(); + } + + VM_CompiledMethod cm = VM_JNICompiler.compile(method); + if (VM.verboseJNI) { + VM.sysWriteln("[Dynamic-linking native method " + + method.getDeclaringClass() + "." + method.getName() + + " "+method.getDescriptor()); + } + + if (VM.MeasureCompilation || VM.BuildForAdaptiveSystem) { + long end = VM_Thread.getCurrentThread().accumulateCycles(); + double compileTime = VM_Time.cyclesToMillis(end - start); + cm.setCompilationTime(compileTime); + record(JNI_COMPILER, method, cm); + } + + return cm; + } + + /** + * returns the string version of compiler number, using the naming scheme + * in this file + * @param compiler the compiler of interest + * @return the string version of compiler number + */ + public static String getCompilerName(byte compiler) { + return name[compiler]; + } + +} Added: ext/org/jikesrvm/opt/ir/OPT_ConvertBCtoHIR.java =================================================================== --- ext/org/jikesrvm/opt/ir/OPT_ConvertBCtoHIR.java (rev 0) +++ ext/org/jikesrvm/opt/ir/OPT_ConvertBCtoHIR.java 2007-03-21 15:19:39 UTC (rev 8) @@ -0,0 +1,54 @@ +/* + * This file is part of Jikes RVM (http://jikesrvm.sourceforge.net). + * The Jikes RVM 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 IBM Corp. 2001 + */ +package org.jikesrvm.opt.ir; + +import org.jikesrvm.opt.*; + +/** + * Translate from bytecodes to HIR + * + * @author Dave Grove + */ +public final class OPT_ConvertBCtoHIR extends OPT_CompilerPhase { + + public String getName () { + return "Generate HIR"; + } + + /** + * Generate HIR for ir.method into ir + * + * @param ir The IR to generate HIR into + */ + public void perform (OPT_IR ir) { + // Generate the cfg into gc + OPT_GenerationContext gc = + new OPT_GenerationContext(ir.method, ir.compiledMethod, + ir.options, ir.inlinePlan); + ir.method.createHIRGenerator(gc).generateHIR(); + // Transfer HIR and misc state from gc to the ir object + ir.gc = gc; + ir.cfg = gc.cfg; + ir.regpool = gc.temps; + if (gc.allocFrame) { + ir.stackManager.forceFrameAllocation(); + } + // ir now contains well formed HIR. + ir.IRStage = OPT_IR.HIR; + ir.HIRInfo = new OPT_HIRInfo(ir); + if (OPT_IR.SANITY_CHECK) { + ir.verify("Initial HIR", true); + } + } + + // This phase contains no instance fields. + public OPT_CompilerPhase newExecution (OPT_IR ir) { + return this; + } +} Modified: src/org/binarytranslator/vmInterface/DBT_Trace.java =================================================================== --- src/org/binarytranslator/vmInterface/DBT_Trace.java 2007-03-21 15:14:00 UTC (rev 7) +++ src/org/binarytranslator/vmInterface/DBT_Trace.java 2007-03-21 15:19:39 UTC (rev 8) @@ -161,4 +161,10 @@ VM_CompiledMethods.setCompiledMethodObsolete(oldCompiledMethod); } } + /** + * Map bytecode index to java source line number + */ + public int getLineNumberForBCIndex(int bci) { + return bci; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cap...@us...> - 2007-03-21 15:14:09
|
Revision: 7 http://svn.sourceforge.net/pearcolator/?rev=7&view=rev Author: captain5050 Date: 2007-03-21 08:14:00 -0700 (Wed, 21 Mar 2007) Log Message: ----------- Patch required to main rvmroot to build this project Added Paths: ----------- rvmroot.patch Added: rvmroot.patch =================================================================== --- rvmroot.patch (rev 0) +++ rvmroot.patch 2007-03-21 15:14:00 UTC (rev 7) @@ -0,0 +1,97 @@ +Index: build.xml +=================================================================== +--- build.xml (revision 11878) ++++ build.xml (working copy) +@@ -792,7 +792,7 @@ + </condition> + + <!-- +- FIXME: When we can capture the primordials based on reacability we will not need to delete class dir ++ FIXME: When we can capture the primordials based on reachability we will not need to delete class dir + here. We will also be able to compile ALL classes in one sweep. + --> + <delete dir="${build.classes}"/> +@@ -862,7 +862,7 @@ + </javac> + </target> + +- <target name="package" depends="compile,compile-vmmagic"> ++ <target name="package" depends="compile,compile-vmmagic,compile-projects"> + <!-- create a rt.jar for the RVM --> + <copy file="${classpath.lib.dir}/classpath.jar" tofile="${build.rt.jar}"/> + <zip destfile="${build.rt.jar}" update="true" basedir="${build.classes}"> +@@ -881,7 +881,20 @@ + </jar> + </target> + ++ <!-- **************************************************************************** --> ++ <!-- * * --> ++ <!-- * Section for compiling and packaging external projects * --> ++ <!-- * * --> ++ <!-- **************************************************************************** --> + ++ <target name="compile-projects" ++ depends="compile" ++ description="Build any projects included with the RVM"> ++ <subant target="" inheritall="true"> ++ <fileset dir="projects" includes="*/build.xml" /> ++ </subant> ++ </target> ++ + <!-- **************************************************************************** --> + <!-- * * --> + <!-- * Section for building the boot image * --> +Index: rvm/src-generated/opt-ir/InstructionFormatList.dat +=================================================================== +--- rvm/src-generated/opt-ir/InstructionFormatList.dat (revision 11878) ++++ rvm/src-generated/opt-ir/InstructionFormatList.dat (working copy) +@@ -149,6 +149,14 @@ + "U Cond OPT_ConditionOperand" "U BranchProfile OPT_BranchProfileOperand" + + ++BooleanCmp2 ++1 0 8 ++"D Result OPT_RegisterOperand" "U Val1 OPT_Operand" "U Val2 OPT_Operand" \ ++"U Cond1 OPT_ConditionOperand" "U BranchProfile1 OPT_BranchProfileOperand" \ ++"U Val3 OPT_Operand" "U Val4 OPT_Operand" \ ++"U Cond2 OPT_ConditionOperand" "U BranchProfile2 OPT_BranchProfileOperand" ++ ++ + CondMove + 1 0 5 + "D Result OPT_RegisterOperand" "U Val1 OPT_Operand" "U Val2 OPT_Operand" \ +Index: rvm/src-generated/opt-ir/OperatorList.dat +=================================================================== +--- rvm/src-generated/opt-ir/OperatorList.dat (revision 11878) ++++ rvm/src-generated/opt-ir/OperatorList.dat (working copy) +@@ -1255,6 +1255,20 @@ + + + ++# Compare two sets of two int values and put the boolean OR in the result register ++BOOLEAN_CMP2_INT_OR ++BooleanCmp2 ++compare ++ ++ ++ ++# Compare two sets of two int values and put the boolean AND in the result register ++BOOLEAN_CMP2_INT_AND ++BooleanCmp2 ++compare ++ ++ ++ + # Load a singed byte + # NOTE: Because of our strategy of using explict guard instructions, there is no + # way in the HIR/LIR that the actual load instruction can except. +Index: rvm/src/OptDummy.java +=================================================================== +--- rvm/src/OptDummy.java (revision 11878) ++++ rvm/src/OptDummy.java (working copy) +@@ -20,4 +20,5 @@ + static org.jikesrvm.opt.OPT_Compiler a; + static org.jikesrvm.opt.VM_OptSaveVolatile g; + static org.jikesrvm.opt.OPT_SpecializedMethodPool q; ++ static org.jikesrvm.opt.ir.BooleanCmp2 b; + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cap...@us...> - 2007-03-20 18:53:30
|
Revision: 6 http://svn.sourceforge.net/pearcolator/?rev=6&view=rev Author: captain5050 Date: 2007-03-20 08:49:03 -0700 (Tue, 20 Mar 2007) Log Message: ----------- Build fixes. Move files from rvm into dbt Modified Paths: -------------- build.xml src/org/binarytranslator/vmInterface/DBT_Trace.java Added Paths: ----------- ext/DBT_Dummy.java ext/org/jikesrvm/classloader/ ext/org/jikesrvm/classloader/VM_Member.java ext/org/jikesrvm/classloader/VM_Method.java ext/org/jikesrvm/classloader/VM_NormalMethod.java ext/org/jikesrvm/opt/OPT_Simplifier.java ext/org/jikesrvm/opt/ir/OPT_BC2IR.java ext/org/jikesrvm/opt/ir/OPT_ConditionOperand.java ext/org/jikesrvm/opt/ir/OPT_GenerationContext.java ext/org/jikesrvm/opt/ir/OPT_HIRInfo.java ext/org/jikesrvm/opt/ir/ia32/ ext/org/jikesrvm/opt/ir/ia32/OPT_IA32ConditionOperand.java Modified: build.xml =================================================================== --- build.xml 2007-03-19 16:01:57 UTC (rev 5) +++ build.xml 2007-03-20 15:49:03 UTC (rev 6) @@ -15,16 +15,34 @@ </javac> </target> <target name="compile-external"> + <delete verbose="true"> + <fileset dir="${build.classes}"> + <include name="org/jikesrvm/opt/ir/ia32/OPT_IA32ConditionOperand.class" /> + <include name="org/jikesrvm/opt/ir/OPT_HIRGenerator.class" /> + <include name="org/jikesrvm/opt/ir/OPT_GenerationContext.class" /> + <include name="org/jikesrvm/opt/ir/OPT_ConditionOperand.class" /> + <include name="org/jikesrvm/opt/ir/OPT_BC2IR.class" /> + <include name="org/jikesrvm/opt/ir/OPT_HIRInfo.class" /> + <include name="org/jikesrvm/opt/OPT_Simplifier.class" /> + <include name="org/jikesrvm/ppc/PPC_Disassembler.class" /> + <include name="org/jikesrvm/ppc/opcode_tab.class" /> + <include name="org/jikesrvm/ppc/opcodeXX.class" /> + <include name="org/jikesrvm/classloader/VM_Method.class" /> + <include name="org/jikesrvm/classloader/VM_Member.class" /> + <include name="org/jikesrvm/classloader/VM_NormalMethod.class" /> + </fileset> + </delete> <javac destdir="${build.classes}" debug="true" debugLevel="lines,source" source="1.5" target="1.5" srcdir="${dbt-ext.java}"> + <include name="DBT_Dummy.java" /> <classpath> <pathelement location="${build.vmmagic-stub.classes}"/> <pathelement location="${build.classes}"/> </classpath> </javac> </target> -</project> \ No newline at end of file +</project> Added: ext/DBT_Dummy.java =================================================================== --- ext/DBT_Dummy.java (rev 0) +++ ext/DBT_Dummy.java 2007-03-20 15:49:03 UTC (rev 6) @@ -0,0 +1,25 @@ +/* + * 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 + */ + +/** + * Dummy class containing enough references to force java compiler + * to find every class comprising the chnages to the opt compiler for DBT + */ +class OptDummy { + static org.jikesrvm.opt.ir.ia32.OPT_IA32ConditionOperand a; + static org.jikesrvm.opt.ir.OPT_HIRGenerator b; + static org.jikesrvm.opt.ir.OPT_GenerationContext c; + static org.jikesrvm.opt.ir.OPT_ConditionOperand d; + static org.jikesrvm.opt.ir.OPT_HIRInfo e; + static org.jikesrvm.opt.OPT_Simplifier f; + static org.jikesrvm.ppc.PPC_Disassembler g; + static org.jikesrvm.classloader.VM_Method j; + static org.jikesrvm.classloader.VM_Member k; + static org.jikesrvm.classloader.VM_NormalMethod l; +} Added: ext/org/jikesrvm/classloader/VM_Member.java =================================================================== --- ext/org/jikesrvm/classloader/VM_Member.java (rev 0) +++ ext/org/jikesrvm/classloader/VM_Member.java 2007-03-20 15:49:03 UTC (rev 6) @@ -0,0 +1,197 @@ +/* + * This file is part of Jikes RVM (http://jikesrvm.sourceforge.net). + * The Jikes RVM 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 IBM Corp 2001,2002 + */ +package org.jikesrvm.classloader; + +import org.jikesrvm.*; +import org.vmmagic.pragma.*; +import org.vmmagic.unboxed.Offset; + +/** + * A field or method of a java class. + * + * @author Bowen Alpern + * @author Dave Grove + * @author Derek Lieber + */ +public abstract class VM_Member extends VM_AnnotatedElement implements VM_Constants, VM_ClassLoaderConstants { + + /** + * The class that declared this member, avaliable by calling + * getDeclaringClass once the class is loaded. + */ + private final VM_TypeReference declaringClass; + + /** + * The canonical VM_MemberReference for this member + */ + protected final VM_MemberReference memRef; + + /** + * The modifiers associated with this member. + */ + public final short modifiers; + + /** + * The signature is a string representing the generic type for this + * field or method declaration, may be null + */ + private final VM_Atom signature; + + /** + * The member's jtoc/obj/tib offset in bytes. + * Set by {@link VM_Class#resolve()} + */ + protected int offset; + + /** + * NOTE: Only {@link VM_Class} is allowed to create an instance of a VM_Member. + * + * @param declaringClass the VM_TypeReference object of the class that declared this member + * @param memRef the canonical memberReference for this member. + * @param modifiers modifiers associated with this member. + * @param signature generic type of this member + * @param annotations array of runtime visible annotations + */ + protected VM_Member(VM_TypeReference declaringClass, VM_MemberReference memRef, + short modifiers, VM_Atom signature, + VM_Annotation[] annotations) { + super(annotations); + this.declaringClass = declaringClass; + this.memRef = memRef; + this.modifiers = modifiers; + this.signature = signature; + this.offset = Short.MIN_VALUE+1; // invalid value. Set to valid value during VM_Class.resolve() + } + + //--------------------------------------------------------------------// + // Section 1. // + // The following are available after class loading. // + //--------------------------------------------------------------------// + + /** + * Class that declared this field or method. Not available before + * the class is loaded. + */ + @Uninterruptible + public final VM_Class getDeclaringClass() { + return declaringClass.peekResolvedType().asClass(); + } + + /** + * Canonical member reference for this member. + */ + @Uninterruptible + public final VM_MemberReference getMemberRef() { + return memRef; + } + + /** + * Name of this member. + */ + @Uninterruptible + public final VM_Atom getName() { + return memRef.getName(); + } + + /** + * Descriptor for this member. + * something like "I" for a field or "(I)V" for a method. + */ + @Uninterruptible + public final VM_Atom getDescriptor() { + return memRef.getDescriptor(); + } + + /** + * Generic type for member + */ + public final VM_Atom getSignature() { + return signature; + } + + /** + * Get a unique id for this member. + * The id is the id of the canonical VM_MemberReference for this member + * and thus may be used to find the member by first finding the member reference. + */ + @Uninterruptible + public final int getId() { + return memRef.getId(); + } + + /* + * Define hashcode in terms of VM_Atom.hashCode to enable + * consistent hash codes during bootImage writing and run-time. + */ + public int hashCode() { + return memRef.hashCode(); + } + + public final String toString() { + return declaringClass + "." + getName() + " " + getDescriptor(); + } + + /** + * Usable from classes outside its package? + */ + public final boolean isPublic() { + return (modifiers & ACC_PUBLIC) != 0; + } + + /** + * Usable only from this class? + */ + public final boolean isPrivate() { + return (modifiers & ACC_PRIVATE) != 0; + } + + /** + * Usable from subclasses? + */ + public final boolean isProtected() { + return (modifiers & ACC_PROTECTED) != 0; + } + + /** + * Get the member's modifiers. + */ + public final int getModifiers() { + return modifiers; + } + + //------------------------------------------------------------------// + // Section 2. // + // The following are available after the declaring class has been // + // "resolved". // + //------------------------------------------------------------------// + + /** + * Offset of this field or method, in bytes. + * <ul> + * <li> For a static field: offset of field from start of jtoc + * <li> For a static method: offset of code object reference from start of jtoc + * <li> For a non-static field: offset of field from start of object + * <li> For a non-static method: offset of code object reference from start of tib + * </ul> + */ + @Uninterruptible + public final Offset getOffset() { + if (VM.VerifyAssertions) VM._assert(declaringClass.isResolved()); + return Offset.fromIntSignExtend(offset); + } + + /** + * Only meant to be used by VM_ObjectModel.layoutInstanceFields. + * TODO: refactor system so this functionality is in the classloader package + * and this method doesn't have to be final. + */ + public final void setOffset(Offset off) { + offset = off.toInt(); + } +} Added: ext/org/jikesrvm/classloader/VM_Method.java =================================================================== --- ext/org/jikesrvm/classloader/VM_Method.java (rev 0) +++ ext/org/jikesrvm/classloader/VM_Method.java 2007-03-20 15:49:03 UTC (rev 6) @@ -0,0 +1,642 @@ +/* + * This file is part of Jikes RVM (http://jikesrvm.sourceforge.net). + * The Jikes RVM 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 IBM Corp 2001,2002 + */ +package org.jikesrvm.classloader; + +import org.jikesrvm.*; +import org.jikesrvm.ArchitectureSpecific.VM_CodeArray; +import org.jikesrvm.ArchitectureSpecific.VM_LazyCompilationTrampolineGenerator; + +import java.io.DataInputStream; +import java.io.IOException; + +import org.vmmagic.unboxed.Offset; +import org.vmmagic.pragma.*; + +/** + * A method of a java class corresponding to a method_info structure + * in the class file. A method is read from a class file using the + * {@link #readMethod} method. + * + * @author Bowen Alpern + * @author Dave Grove + * @author Derek Lieber + * @author Ian Rogers + */ +public abstract class VM_Method extends VM_Member implements VM_BytecodeConstants { + + /** + * current compiled method for this method + */ + protected VM_CompiledMethod currentCompiledMethod; + /** + * exceptions this method might throw (null --> none) + */ + protected final VM_TypeReference[] exceptionTypes; + /** + * Method paramter annotations from the class file that are + * described as runtime visible. These annotations are available to + * the reflection API. + */ + protected final VM_Annotation[] parameterAnnotations; + /** + * A value present in the method info tables of annotation types. It + * represents the default result from an annotation method. + */ + protected final Object annotationDefault; + /** + * The offset of this virtual method in the jtoc if it's been placed + * there by constant propagation, otherwise 0. + */ + private Offset jtocOffset; + + /** + * Construct a read method + * + * @param declaringClass the VM_Class object of the class that declared this field + * @param memRef the canonical memberReference for this method. + * @param modifiers modifiers associated with this method. + * @param exceptionTypes exceptions thrown by this method. + * @param signature generic type of this method. + * @param annotations array of runtime visible annotations + * @param parameterAnnotations array of runtime visible parameter annotations + * @param annotationDefault value for this annotation that appears + */ + protected VM_Method(VM_TypeReference declaringClass, VM_MemberReference memRef, + short modifiers, VM_TypeReference[] exceptionTypes, VM_Atom signature, + VM_Annotation[] annotations, + VM_Annotation[] parameterAnnotations, + Object annotationDefault) + { + super(declaringClass, memRef, (short)(modifiers & APPLICABLE_TO_METHODS), signature, annotations); + this.parameterAnnotations = parameterAnnotations; + this.annotationDefault = annotationDefault; + memRef.asMethodReference().setResolvedMember(this); + this.exceptionTypes = exceptionTypes; + this.jtocOffset = Offset.fromIntSignExtend(-1); + } + + /** + * Called from {@link VM_Class#readClass(VM_TypeReference, DataInputStream)} to create an + * instance of a VM_Method by reading the relevant data from the argument bytecode stream. + * + * @param declaringClass the VM_TypeReference of the class being loaded + * @param constantPool the constantPool of the VM_Class object that's being constructed + * @param memRef the canonical memberReference for this member. + * @param modifiers modifiers associated with this member. + * @param input the DataInputStream to read the method's attributes from + */ + static VM_Method readMethod(VM_TypeReference declaringClass, int[] constantPool, VM_MemberReference memRef, + short modifiers, DataInputStream input) throws IOException { + short tmp_localWords = 0; + short tmp_operandWords = 0; + byte[] tmp_bytecodes = null; + VM_ExceptionHandlerMap tmp_exceptionHandlerMap = null; + VM_TypeReference[] tmp_exceptionTypes = null; + int[] tmp_lineNumberMap = null; + VM_Atom tmp_signature = null; + VM_Annotation[] annotations = null; + VM_Annotation[] parameterAnnotations = null; + Object tmp_annotationDefault = null; + + // Read the attributes + for (int i = 0, n = input.readUnsignedShort(); i<n; i++) { + VM_Atom attName = VM_Class.getUtf(constantPool, input.readUnsignedShort()); + int attLength = input.readInt(); + + // Only bother to interpret non-boring Method attributes + if (attName == VM_ClassLoader.codeAttributeName) { + tmp_operandWords = input.readShort(); + tmp_localWords = input.readShort(); + tmp_bytecodes = new byte[input.readInt()]; + input.readFully(tmp_bytecodes); + tmp_exceptionHandlerMap = VM_ExceptionHandlerMap.readExceptionHandlerMap(input, constantPool); + + // Read the attributes portion of the code attribute + for (int j = 0, n2 = input.readUnsignedShort(); j<n2; j++) { + attName = VM_Class.getUtf(constantPool, input.readUnsignedShort()); + attLength = input.readInt(); + + if (attName == VM_ClassLoader.lineNumberTableAttributeName) { + int cnt = input.readUnsignedShort(); + if (cnt != 0) { + tmp_lineNumberMap = new int[cnt]; + for (int k = 0; k<cnt; k++) { + int startPC = input.readUnsignedShort(); + int lineNumber = input.readUnsignedShort(); + tmp_lineNumberMap[k] = (lineNumber << BITS_IN_SHORT) | startPC; + } + } + } else { + // All other entries in the attribute portion of the code attribute are boring. + input.skipBytes(attLength); + } + } + } else if (attName == VM_ClassLoader.exceptionsAttributeName) { + int cnt = input.readUnsignedShort(); + if (cnt != 0) { + tmp_exceptionTypes = new VM_TypeReference[cnt]; + for (int j = 0, m = tmp_exceptionTypes.length; j < m; ++j) { + tmp_exceptionTypes[j] = VM_Class.getTypeRef(constantPool, input.readUnsignedShort()); + } + } + } else if (attName == VM_ClassLoader.syntheticAttributeName) { + modifiers |= ACC_SYNTHETIC; + } else if (attName == VM_ClassLoader.signatureAttributeName) { + tmp_signature = VM_Class.getUtf(constantPool, input.readUnsignedShort()); + } else if (attName == VM_ClassLoader.runtimeVisibleAnnotationsAttributeName) { + annotations = VM_AnnotatedElement.readAnnotations(constantPool, input, 2, + declaringClass.getClassLoader()); + } else if (attName == VM_ClassLoader.runtimeVisibleParameterAnnotationsAttributeName) { + parameterAnnotations = VM_AnnotatedElement.readAnnotations(constantPool, input, 1, + declaringClass.getClassLoader()); + } else if (attName == VM_ClassLoader.annotationDefaultAttributeName) { + try { + tmp_annotationDefault = VM_Annotation.readValue(constantPool, input, declaringClass.getClassLoader()); + } + catch (ClassNotFoundException e){ + throw new Error(e); + } + } else { + // all other method attributes are boring + input.skipBytes(attLength); + } + } + VM_Method method; + if ((modifiers & ACC_NATIVE) != 0) { + method = new VM_NativeMethod(declaringClass, memRef, modifiers, tmp_exceptionTypes, tmp_signature, + annotations, parameterAnnotations, tmp_annotationDefault); + } else if ((modifiers & ACC_ABSTRACT) != 0) { + method = new VM_AbstractMethod(declaringClass, memRef, modifiers, tmp_exceptionTypes, tmp_signature, + annotations, parameterAnnotations, tmp_annotationDefault); + + } else { + method = new VM_NormalMethod(declaringClass, memRef, modifiers, tmp_exceptionTypes, + tmp_localWords, tmp_operandWords, tmp_bytecodes, + tmp_exceptionHandlerMap, tmp_lineNumberMap, + constantPool, tmp_signature, + annotations, parameterAnnotations, tmp_annotationDefault); + } + return method; + } + + /** + * Create a copy of the method that occurs in the annotation + * interface. The method body will contain a read of the field at + * the constant pool index specified. + * + * @param annotationClass the class this method belongs to + * @param constantPool for the class + * @param memRef the member reference corresponding to this method + * @param interfaceMethod the interface method that will copied to + * produce the annotation method + * @param constantPoolIndex the index of the field that will be + * returned by this method + * @return the created method + */ + static VM_Method createAnnotationMethod(VM_TypeReference annotationClass, int[] constantPool, + VM_MemberReference memRef, VM_Method interfaceMethod, + int constantPoolIndex) { + byte[] bytecodes = new byte[] { + (byte)JBC_aload_0, + (byte)JBC_getfield, + (byte)(constantPoolIndex >>> 8), + (byte)constantPoolIndex, + // Xreturn + (byte)typeRefToReturnBytecode(interfaceMethod.getReturnType()) + }; + return new VM_NormalMethod(annotationClass, memRef, (short)(ACC_PUBLIC|ACC_FINAL|ACC_SYNTHETIC), null, + (short)1, (short)2, bytecodes, + null, null, + constantPool, + null, null, null, null); + } + /** + * Create a method to initialise the annotation class + * + * @param aClass the class this method belongs to + * @param constantPool for the class + * @param memRef the member reference corresponding to this method + * @param objectInitIndex an index into the constant pool for a + * method reference to java.lang.Object.<init> + * @param aFields + * @param aMethods + * @return the created method + */ + static VM_Method createAnnotationInit(VM_TypeReference aClass, int[] constantPool, + VM_MemberReference memRef, int objectInitIndex, + VM_Field[] aFields, VM_Method[] aMethods, + int[] defaultConstants) { + byte[] bytecode = new byte[6+(defaultConstants.length*7)]; + bytecode[0] = (byte)JBC_aload_0; // stack[0] = this + bytecode[1] = (byte)JBC_aload_1; // stack[1] = instanceof VM_Annotation + bytecode[2] = (byte)JBC_invokespecial; + bytecode[3] = (byte)(objectInitIndex >>> 8); + bytecode[4] = (byte)objectInitIndex; + for(int i=0, j=0; i < aMethods.length; i++) { + if(aMethods[i].annotationDefault != null) { + bytecode[(j*7)+5+0] = (byte)JBC_aload_0; // stack[0] = this + if(VM_Class.getLiteralSize(constantPool, defaultConstants[j]) == BYTES_IN_INT) { + bytecode[(j*7)+5+1] = (byte)JBC_ldc_w; // stack[1] = value + } + else { + bytecode[(j*7)+5+1] = (byte)JBC_ldc2_w;// stack[1&2] = value + } + bytecode[(j*7)+5+2] = (byte)(defaultConstants[j] >>> 8); + bytecode[(j*7)+5+3] = (byte)defaultConstants[j]; + bytecode[(j*7)+5+4] = (byte)JBC_putfield; + bytecode[(j*7)+5+5] = (byte)(i >>> 8); + bytecode[(j*7)+5+6] = (byte)i; + j++; + } + } + bytecode[bytecode.length-1] = (byte)JBC_return; + return new VM_NormalMethod(aClass, memRef, (short)(ACC_PUBLIC|ACC_FINAL|ACC_SYNTHETIC), null, + (short)2, (short)3, bytecode, + null, null, + constantPool, + null, null, null, null); + } + + /** + * What would be the appropriate return bytecode for the given type + * reference? + */ + private static int typeRefToReturnBytecode(VM_TypeReference tr) { + if(!tr.isPrimitiveType()) { + return JBC_areturn; + } else { + VM_Primitive pt = (VM_Primitive)tr.peekResolvedType(); + if((pt == VM_Type.BooleanType)||(pt == VM_Type.ByteType)||(pt == VM_Type.ShortType)|| + (pt == VM_Type.CharType)||(pt == VM_Type.IntType)) { + return JBC_ireturn; + } + else if(pt == VM_Type.LongType) { + return JBC_lreturn; + } + else if(pt == VM_Type.FloatType) { + return JBC_freturn; + } + else if(pt == VM_Type.DoubleType) { + return JBC_dreturn; + } + else { + VM._assert(false); + return -1; + } + } + } + /** + * Is this method a class initializer? + */ + @Uninterruptible + public final boolean isClassInitializer() { + return getName() == VM_ClassLoader.StandardClassInitializerMethodName; + } + + /** + * Is this method an object initializer? + */ + @Uninterruptible + public final boolean isObjectInitializer() { + return getName() == VM_ClassLoader.StandardObjectInitializerMethodName; + } + + /** + * Is this method a compiler-generated object initializer helper? + */ + @Uninterruptible + public final boolean isObjectInitializerHelper() { + return getName() == VM_ClassLoader.StandardObjectInitializerHelperMethodName; + } + + /** + * Type of this method's return value. + */ + @Uninterruptible + public final VM_TypeReference getReturnType() { + return memRef.asMethodReference().getReturnType(); + } + + /** + * Type of this method's parameters. + * Note: does *not* include implicit "this" parameter, if any. + */ + @Uninterruptible + public final VM_TypeReference[] getParameterTypes() { + return memRef.asMethodReference().getParameterTypes(); + } + + /** + * Space required by this method for its parameters, in words. + * Note: does *not* include implicit "this" parameter, if any. + */ + @Uninterruptible + public final int getParameterWords() { + return memRef.asMethodReference().getParameterWords(); + } + + /** + * Has machine code been generated for this method's bytecodes? + */ + public final boolean isCompiled() { + return currentCompiledMethod != null; + } + + /** + * Get the current compiled method for this method. + * Will return null if there is no current compiled method! + * + * We make this method Unpreemptible to avoid a race-condition + * in VM_Reflection.invoke. + * @return compiled method + */ + @Unpreemptible + public final synchronized VM_CompiledMethod getCurrentCompiledMethod() { + return currentCompiledMethod; + } + + /** + * Declared as statically dispatched? + */ + @Uninterruptible + public final boolean isStatic() { + return (modifiers & ACC_STATIC) != 0; + } + + /** + * Declared as non-overridable by subclasses? + */ + @Uninterruptible + public final boolean isFinal() { + return (modifiers & ACC_FINAL) != 0; + } + + /** + * Guarded by monitorenter/monitorexit? + */ + @Uninterruptible + public final boolean isSynchronized() { + return (modifiers & ACC_SYNCHRONIZED) != 0; + } + + /** + * Not implemented in java? + */ + @Uninterruptible + public final boolean isNative() { + return (modifiers & ACC_NATIVE) != 0; + } + + /** + * Not implemented in Java and use C not JNI calling convention + */ + public final boolean isSysCall() { + return isNative() && isStatic() && isAnnotationDeclared(VM_TypeReference.SysCall); + } + + /** + * Implemented in subclass? + */ + @Uninterruptible + public final boolean isAbstract() { + return (modifiers & ACC_ABSTRACT) != 0; + } + + /** + * Not present in source code file? + */ + public boolean isSynthetic() { + return (modifiers & ACC_SYNTHETIC) != 0; + } + + /** + * Exceptions thrown by this method - + * something like { "java/lang/IOException", "java/lang/EOFException" } + * @return info (null --> method doesn't throw any exceptions) + */ + @Uninterruptible + public final VM_TypeReference[] getExceptionTypes() { + return exceptionTypes; + } + + /** + * Is this method interruptible? + * In other words, should the compiler insert yieldpoints + * in method prologue, epilogue, and backwards branches. + * Also, only methods that are Interruptible have stackoverflow checks + * in the method prologue (since there is no mechanism for handling a stackoverflow + * that doesn't violate the uninterruptiblity of the method). + * To determine if a method is interruptible, the following conditions + * are checked (<em>in order</em>): + * <ul> + * <li> If it is a <clinit> or <init> method then it is interruptible. + * <li> If is the synthetic 'this' method used by jikes to + * factor out default initializers for <init> methods then it is interruptible. + * <li> If it is annotated with <CODE>Interruptible</CODE> it is interruptible. + * <li> If it is annotated with <CODE>Preemptible</CODE> it is interruptible. + * <li> If it is annotated with <CODE>Uninterruptible</CODE> it is not interruptible. + * <li> If it is annotated with <CODE>UninterruptibleNoWarn</CODE> it is not interruptible. + * <li> If it is annotated with <CODE>Unpreemptible</CODE> it is not interruptible. + * <li> If its declaring class is annotated with <CODE>Uninterruptible</CODE> + * or <CODE>Unpreemptible</CODE> it is not interruptible. + * </ul> + */ + public final boolean isInterruptible() { + if (isClassInitializer() || isObjectInitializer()) return true; + if (isObjectInitializerHelper()) return true; + if (hasInterruptibleAnnotation()) return true; + if (hasPreemptibleAnnotation()) return true; + if (hasUninterruptibleNoWarnAnnotation()) return false; + if (hasUninterruptibleAnnotation()) return false; + if (hasUnpreemptibleAnnotation()) return false; + if (getDeclaringClass().hasUnpreemptibleAnnotation()) return false; + return !getDeclaringClass().hasUninterruptibleAnnotation(); + } + + /** + * Is the method Unpreemptible? See the comment in {@link #isInterruptible} + */ + public final boolean isUnpreemptible() { + if (isClassInitializer() || isObjectInitializer()) return false; + if (isObjectInitializerHelper()) return false; + if (hasInterruptibleAnnotation()) return false; + if (hasPreemptibleAnnotation()) return false; + if (hasUninterruptibleAnnotation()) return false; + if (hasUninterruptibleNoWarnAnnotation()) return false; + if (hasUnpreemptibleAnnotation()) return true; + return getDeclaringClass().hasUnpreemptibleAnnotation(); + } + + /** + * Is the method Uninterruptible? See the comment in {@link #isInterruptible} + */ + public final boolean isUninterruptible() { + if (isClassInitializer() || isObjectInitializer()) return false; + if (isObjectInitializerHelper()) return false; + if (hasInterruptibleAnnotation()) return false; + if (hasPreemptibleAnnotation()) return false; + if (hasUnpreemptibleAnnotation()) return false; + if (hasUninterruptibleAnnotation()) return true; + if (hasUninterruptibleNoWarnAnnotation()) return true; + return getDeclaringClass().hasUninterruptibleAnnotation(); + } + + /** + * Has this method been marked as forbidden to inline? + * ie., it is marked with the <CODE>NoInline</CODE> annotation or + * the <CODE>NoOptCompile</CODE> annotation? + */ + public final boolean hasNoInlinePragma() { + return (hasNoInlineAnnotation() || hasNoOptCompileAnnotation()); + } + + /** + * @return true if the method may write to a given field + */ + public boolean mayWrite(VM_Field field) { + return true; // be conservative. native methods can write to anything + } + + /** + * @return true if the method is the implementation of a runtime service + * that is called "under the covers" from the generated code and thus is not subject to + * inlining via the normal mechanisms. + */ + public boolean isRuntimeServiceMethod() { + return false; // only VM_NormalMethods can be runtime service impls in Jikes RVM and they override this method + } + + //------------------------------------------------------------------// + // Section 2. // + // The following are available after the declaring class has been // + // "resolved". // + //------------------------------------------------------------------// + + /** + * Get the code array that corresponds to the entry point (prologue) for the method. + */ + public final synchronized VM_CodeArray getCurrentEntryCodeArray() { + VM_Class declaringClass = getDeclaringClass(); + if (VM.VerifyAssertions) VM._assert(declaringClass.isResolved()); + if (isCompiled()) { + return currentCompiledMethod.getEntryCodeArray(); + } else if (!VM.writingBootImage || isNative()) { + if (!isStatic() && !isObjectInitializer() && !isPrivate()) { + // A non-private virtual method. + if (declaringClass.isJavaLangObjectType() || + declaringClass.getSuperClass().findVirtualMethod(getName(), getDescriptor()) == null) { + // The root method of a virtual method family can use the lazy method invoker directly. + return VM_Entrypoints.lazyMethodInvokerMethod.getCurrentEntryCodeArray(); + } else { + // All other virtual methods in the family must generate unique stubs to + // ensure correct operation of the method test (guarded inlining of virtual calls). + return VM_LazyCompilationTrampolineGenerator.getTrampoline(); + } + } else { + // We'll never do a method test against this method. + // Therefore we can use the lazy method invoker directly. + return VM_Entrypoints.lazyMethodInvokerMethod.getCurrentEntryCodeArray(); + } + } else { + compile(); + return currentCompiledMethod.getEntryCodeArray(); + } + } + + /** + * Generate machine code for this method if valid + * machine code doesn't already exist. + * Return the resulting VM_CompiledMethod object. + */ + public final synchronized void compile() { + if (VM.VerifyAssertions) VM._assert(getDeclaringClass().isResolved()); + if (isCompiled()) return; + + if (VM.TraceClassLoading && VM.runningVM) VM.sysWrite("VM_Method: (begin) compiling " + this + "\n"); + + VM_CompiledMethod cm = genCode(); + + // Ensure that cm wasn't invalidated while it was being compiled. + synchronized(cm) { + if (cm.isInvalid()) { + VM_CompiledMethods.setCompiledMethodObsolete(cm); + } else { + currentCompiledMethod = cm; + } + } + + if (VM.TraceClassLoading && VM.runningVM) VM.sysWrite("VM_Method: (end) compiling " + this + "\n"); + } + + protected abstract VM_CompiledMethod genCode(); + + //----------------------------------------------------------------// + // Section 3. // + // The following are available after the declaring class has been // + // "instantiated". // + //----------------------------------------------------------------// + + /** + * Change machine code that will be used by future executions of this method + * (ie. optimized <-> non-optimized) + * @param compiledMethod new machine code + * Side effect: updates jtoc or method dispatch tables + * ("type information blocks") + * for this class and its subclasses + */ + public synchronized void replaceCompiledMethod(VM_CompiledMethod compiledMethod) { + if (VM.VerifyAssertions) VM._assert(getDeclaringClass().isInstantiated()); + // If we're replacing with a non-null compiledMethod, ensure that is still valid! + if (compiledMethod != null) { + synchronized(compiledMethod) { + if (compiledMethod.isInvalid()) return; + } + } + + // Grab version that is being replaced + VM_CompiledMethod oldCompiledMethod = currentCompiledMethod; + currentCompiledMethod = compiledMethod; + + // Install the new method in jtoc/tib. If virtual, will also replace in + // all subclasses that inherited the method. + getDeclaringClass().updateMethod(this); + + // Replace constant-ified virtual method in JTOC if necessary + if(jtocOffset.toInt() != -1) { + VM_Statics.setSlotContents(jtocOffset, getCurrentEntryCodeArray()); + } + + // Now that we've updated the jtoc/tib, old version is obsolete + if (oldCompiledMethod != null) { + VM_CompiledMethods.setCompiledMethodObsolete(oldCompiledMethod); + } + } + + /** + * If CM is the current compiled code for this, then invaldiate it. + */ + public final synchronized void invalidateCompiledMethod(VM_CompiledMethod cm) { + if (VM.VerifyAssertions) VM._assert(getDeclaringClass().isInstantiated()); + if (currentCompiledMethod == cm) { + replaceCompiledMethod(null); + } + } + + /** + * Find or create a jtoc offset for this method + */ + public final synchronized Offset findOrCreateJtocOffset() { + if (VM.VerifyAssertions) VM._assert(!isStatic() && !isObjectInitializer()); + if(jtocOffset.EQ(Offset.zero())) { + jtocOffset = VM_Statics.allocateReferenceSlot(); + VM_Statics.setSlotContents(jtocOffset, getCurrentEntryCodeArray()); + } + return jtocOffset; + } +} Added: ext/org/jikesrvm/classloader/VM_NormalMethod.java =================================================================== --- ext/org/jikesrvm/classloader/VM_NormalMethod.java (rev 0) +++ ext/org/jikesrvm/classloader/VM_NormalMethod.java 2007-03-20 15:49:03 UTC (rev 6) @@ -0,0 +1,675 @@ +/* + * This file is part of Jikes RVM (http://jikesrvm.sourceforge.net). + * The Jikes RVM 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 IBM Corp 2001,2002, 2004 + */ +package org.jikesrvm.classloader; + +import org.jikesrvm.*; +import org.vmmagic.pragma.*; +import org.jikesrvm.opt.ir.OPT_HIRGenerator; +import org.jikesrvm.opt.ir.OPT_BC2IR; +import org.jikesrvm.opt.ir.OPT_GenerationContext; + +/** + * A method of a java class that has bytecodes. + * + * @author Bowen Alpern + * @author Stephen Fink + * @author Dave Grove + * @author Derek Lieber + * @modified Ian Rogers + */ +public class VM_NormalMethod + extends VM_Method + implements VM_BytecodeConstants +{ + + /* As we read the bytecodes for the method, we compute + * a simple summary of some interesting properties of the method. + * Because we do this for every method, we require the summarization to + * be fast and the computed summary to be very space efficient. + * + * The following constants encode the estimated relative cost in + * machine instructions when a particular class of bytecode is compiled + * by the optimizing compiler. The estimates approximate the typical + * optimization the compiler is able to perform. + * This information is used to estimate how big a method will be when + * it is inlined. + */ + public static final int SIMPLE_OPERATION_COST = 1; + public static final int LONG_OPERATION_COST = 2; + public static final int ARRAY_LOAD_COST = 2; + public static final int ARRAY_STORE_COST = 2; + public static final int JSR_COST = 5; + public static final int CALL_COST = 6; + // Bias to inlining methods with magic + // most magics are quite cheap (0-1 instructions) + public static final int MAGIC_COST = 0; + // News are actually more expensive than calls + // but bias to inline methods that allocate + // objects becuase we expect better downstream optimization of + // the caller due to class analysis + // and propagation of nonNullness + public static final int ALLOCATION_COST = 4; + // Approximations, assuming some CSE/PRE of object model computations + public static final int CLASS_CHECK_COST = 2*SIMPLE_OPERATION_COST; + public static final int STORE_CHECK_COST = 4*SIMPLE_OPERATION_COST; + // Just a call. + public static final int THROW_COST = CALL_COST; + // Really a bunch of operations plus a call, but undercharge because + // we don't have worry about this causing an exponential growth of call chain + // and we probably want to inline synchronization + // (to get a chance to optimize it). + public static final int SYNCH_COST = 4*SIMPLE_OPERATION_COST; + // The additional cost of a switch isn't that large, since if the + // switch has more than a few cases the method will be too big to inline + // anyways. + public static final int SWITCH_COST = CALL_COST; + + // Definition of flag bits + protected static final char HAS_MAGIC = 0x8000; + protected static final char HAS_SYNCH = 0x4000; + protected static final char HAS_ALLOCATION = 0x2000; + protected static final char HAS_THROW = 0x1000; + protected static final char HAS_INVOKE = 0x0800; + protected static final char HAS_FIELD_READ = 0x0400; + protected static final char HAS_FIELD_WRITE= 0x0200; + protected static final char HAS_ARRAY_READ = 0x0100; + protected static final char HAS_ARRAY_WRITE= 0x0080; + protected static final char HAS_JSR = 0x0040; + protected static final char HAS_COND_BRANCH= 0x0020; + protected static final char HAS_SWITCH = 0x0010; + protected static final char HAS_BACK_BRANCH= 0x0008; + protected static final char IS_RS_METHOD = 0x0004; + + /** + * storage for bytecode summary flags + */ + protected char summaryFlags; + /** + * storage for bytecode summary size + */ + protected char summarySize; + + /** + * words needed for local variables (including parameters) + */ + private final short localWords; + + /** + * words needed for operand stack (high water mark) + * TODO: OSR redesign; add subclass of NormalMethod for OSR method + * and then make this field final in NormalMethod. + */ + private short operandWords; + + /** + * bytecodes for this method (null --> none) + */ + public final byte[] bytecodes; + + /** + * try/catch/finally blocks for this method (null --> none) + */ + private final VM_ExceptionHandlerMap exceptionHandlerMap; + + /** + * pc to source-line info (null --> none) + * Each entry contains both the line number (upper 16 bits) + * and corresponding start PC (lower 16 bits). + */ + private final int[] lineNumberMap; + + // Extra fields for on-stack replacement + // TODO: rework the system so we don't waste space for this on the VM_Method object + /* bytecode array constists of prologue and original bytecodes */ + private byte[] synthesizedBytecodes = null; + /* record osr prologue */ + private byte[] osrPrologue = null; + /* prologue may change the maximum stack height, remember the + * original stack height */ + private short savedOperandWords; + + /** + * Construct a normal Java bytecode method's information + * + * @param dc the VM_TypeReference object of the class that declared this field + * @param mr the canonical memberReference for this member. + * @param mo modifiers associated with this member. + * @param et exceptions thrown by this method. + * @param lw the number of local words used by the bytecode of this method + * @param ow the number of operand words used by the bytecode of this method + * @param bc the bytecodes of this method + * @param eMap the exception handler map for this method + * @param lm the line number map for this method + * @param constantPool the constantPool for this method + * @param sig generic type of this method. + * @param annotations array of runtime visible annotations + * @param parameterAnnotations array of runtime visible paramter annotations + * @param ad annotation default value for that appears in annotation classes + */ + public VM_NormalMethod(VM_TypeReference dc, VM_MemberReference mr, + short mo, VM_TypeReference[] et, short lw, short ow, byte[] bc, + VM_ExceptionHandlerMap eMap, int[] lm, + int[] constantPool, VM_Atom sig, + VM_Annotation[] annotations, + VM_Annotation[] parameterAnnotations, + Object ad) + { + super(dc, mr, mo, et, sig, annotations, parameterAnnotations, ad); + localWords = lw; + operandWords = ow; + bytecodes = bc; + exceptionHandlerMap = eMap; + lineNumberMap = lm; + computeSummary(constantPool); + } + + /** + * Generate the code for this method + */ + protected VM_CompiledMethod genCode() throws VerifyError { + // The byte code verifier is dead; needs replacement. +// if (VM.VerifyBytecode) { +// VM_Verifier verifier = new VM_Verifier(); +// verifier.verifyMethod(this); +// } + + if (VM.writingBootImage) { + return VM_BootImageCompiler.compile(this); + } else { + return VM_RuntimeCompiler.compile(this); + } + } + + /** + * Space required by this method for its local variables, in words. + * Note: local variables include parameters + */ + @Uninterruptible + public int getLocalWords() { + return localWords; + } + + /** + * Space required by this method for its operand stack, in words. + */ + @Uninterruptible + public int getOperandWords() { + return operandWords; + } + + /** + * Get a representation of the bytecodes in the code attribute of this method. + * @return object representing the bytecodes + */ + public VM_BytecodeStream getBytecodes() { + return new VM_BytecodeStream(this, bytecodes); + } + + /** + * Fill in DynamicLink object for the invoke at the given bytecode index + * @param dynamicLink the dynamicLink object to initialize + * @param bcIndex the bcIndex of the invoke instruction + */ + @Uninterruptible + public void getDynamicLink(VM_DynamicLink dynamicLink, int bcIndex) { + if (VM.VerifyAssertions) VM._assert(bytecodes != null); + if (VM.VerifyAssertions) VM._assert(bcIndex + 2 < bytecodes.length); + int bytecode = bytecodes[bcIndex] & 0xFF; + if (VM.VerifyAssertions) VM._assert((VM_BytecodeConstants.JBC_invokevirtual <= bytecode) + && (bytecode <= VM_BytecodeConstants.JBC_invokeinterface)); + int constantPoolIndex = ((bytecodes[bcIndex + 1] & 0xFF) << BITS_IN_BYTE) | (bytecodes[bcIndex + 2] & 0xFF); + dynamicLink.set(getDeclaringClass().getMethodRef(constantPoolIndex), bytecode); + } + + /** + * Size of bytecodes for this method + */ + public int getBytecodeLength() { + return bytecodes.length; + } + + /** + * Exceptions caught by this method. + * @return info (null --> method doesn't catch any exceptions) + */ + @Uninterruptible + public VM_ExceptionHandlerMap getExceptionHandlerMap() { + return exceptionHandlerMap; + } + + /** + * Return the line number information for the argument bytecode index. + * @return The line number, a positive integer. Zero means unable to find. + */ + @Uninterruptible + public int getLineNumberForBCIndex(int bci) { + if (lineNumberMap == null) return 0; + int idx; + for (idx = 0; idx<lineNumberMap.length; idx++) { + int pc = lineNumberMap[idx] & 0xffff; // lower 16 bits are bcIndex + if (bci < pc) { + if (idx == 0) idx++; // add 1, so we can subtract 1 below. + break; + } + } + return lineNumberMap[--idx] >>> 16; // upper 16 bits are line number + } + + // Extra methods for on-stack replacement + // VM_BaselineCompiler and OPT_BC2IR should check if a method is + // for specialization by calling isForOsrSpecialization, the compiler + // uses synthesized bytecodes (prologue + original bytecodes) for + // OSRing method. Other interfaces of method are not changed, therefore, + // dynamic linking and gc referring to bytecodes are safe. + + /** + * Checks if the method is in state for OSR specialization now + * @return true, if it is (with prologue) + */ + public boolean isForOsrSpecialization() { + return this.synthesizedBytecodes != null; + } + + /** + * Sets method in state for OSR specialization, i.e, the subsequent calls + * of {@link #getBytecodes} return the stream of specialized bytecodes. + * + * NB: between flag and action, it should not allow GC or threadSwitch happen. + * @param prologue The bytecode of prologue + * @param newStackHeight The prologue may change the default height of + * stack + */ + public void setForOsrSpecialization(byte[] prologue, short newStackHeight) { + if (VM.VerifyAssertions) VM._assert(this.synthesizedBytecodes == null); + + byte[] newBytecodes = new byte[prologue.length + bytecodes.length]; + System.arraycopy(prologue, 0, newBytecodes, 0, prologue.length); + System.arraycopy(bytecodes, 0, newBytecodes, prologue.length, bytecodes.length); + + this.osrPrologue = prologue; + this.synthesizedBytecodes = newBytecodes; + this.savedOperandWords = operandWords; + if (newStackHeight > operandWords) + this.operandWords = newStackHeight; + } + + /** + * Restores the original state of the method. + */ + public void finalizeOsrSpecialization() { + if (VM.VerifyAssertions) VM._assert(this.synthesizedBytecodes != null); + this.synthesizedBytecodes = null; + this.osrPrologue = null; + this.operandWords = savedOperandWords; + } + + /** + * Returns the OSR prologue length for adjusting various tables and maps. + * @return the length of prologue if the method is in state for OSR, + * 0 otherwise. + */ + public int getOsrPrologueLength() { + return isForOsrSpecialization()?this.osrPrologue.length:0; + } + + /** + * Returns a bytecode stream of osr prologue + * @return osr prologue bytecode stream + */ + public VM_BytecodeStream getOsrPrologue() { + if (VM.VerifyAssertions) VM._assert(synthesizedBytecodes != null); + return new VM_BytecodeStream(this, osrPrologue); + } + + /** + * Returns the synthesized bytecode stream with osr prologue + * @return bytecode stream + */ + public VM_BytecodeStream getOsrSynthesizedBytecodes() { + if (VM.VerifyAssertions) VM._assert(synthesizedBytecodes != null); + return new VM_BytecodeStream(this, synthesizedBytecodes); + } + + + /* + * Methods to access and compute method summary information + */ + + /** + * @return An estimate of the expected size of the machine code instructions + * that will be generated by the opt compiler if the method is inlined. + */ + public int inlinedSizeEstimate() { + return summarySize & 0xFFFF; + } + + /** + * @return true if the method contains a VM_Magic.xxx or Address.yyy + */ + public boolean hasMagic() { + return (summaryFlags & HAS_MAGIC) != 0; + } + + /** + * @return true if the method contains a monitorenter/exit or is synchronized + */ + public boolean hasSynch() { + return (summaryFlags & HAS_SYNCH) != 0; + } + + /** + * @return true if the method contains an allocation + */ + public boolean hasAllocation() { + return (summaryFlags & HAS_ALLOCATION) != 0; + } + + /** + * @return true if the method contains an athrow + */ + public boolean hasThrow() { + return (summaryFlags & HAS_THROW) != 0; + } + + /** + * @return true if the method contains an invoke + */ + public boolean hasInvoke() { + return (summaryFlags & HAS_INVOKE) != 0; + } + + /** + * @return true if the method contains a getfield or getstatic + */ + public boolean hasFieldRead() { + return (summaryFlags & HAS_FIELD_READ) != 0; + } + + /** + * @return true if the method contains a putfield or putstatic + */ + public boolean hasFieldWrite() { + return (summaryFlags & HAS_FIELD_WRITE) != 0; + } + + /** + * @return true if the method contains an array load + */ + public boolean hasArrayRead() { + return (summaryFlags & HAS_ARRAY_READ) != 0; + } + + /** + * @return true if the method contains an array store + */ + public boolean hasArrayWrite() { + return (summaryFlags & HAS_ARRAY_WRITE) != 0; + } + + /** + * @return true if the method contains a jsr + */ + public boolean hasJSR() { + return (summaryFlags & HAS_JSR) != 0; + } + + /** + * @return true if the method contains a conditional branch + */ + public boolean hasCondBranch() { + return (summaryFlags & HAS_COND_BRANCH) != 0; + } + + /** + * @return true if the method contains a switch + */ + public boolean hasSwitch() { + return (summaryFlags & HAS_SWITCH) != 0; + } + + /** + * @return true if the method contains a backwards branch + */ + public boolean hasBackwardsBranch() { + return (summaryFlags & HAS_BACK_BRANCH) != 0; + } + + /** + * @return true if the method is the implementation of a runtime service + * that is called "under the covers" from the generated code and thus is not subject to + * inlining via the normal mechanisms. + */ + public boolean isRuntimeServiceMethod() { + return (summaryFlags & IS_RS_METHOD) != 0; + } + + /** + * Set the value of the 'runtime service method' flag to the argument + * value. A method is considered to be a runtime service method if it + * is only/primarialy invoked "under the covers" from the generated code + * and thus is not subject to inlining via the normal mechanisms. + * For example, the implementations of bytecodes such as new or checkcast + * or the implementation of yieldpoints. + * @param value true if this is a runtime service method, false it is not. + */ + public void setRuntimeServiceMethod(boolean value) { + if (value) { + summaryFlags |= IS_RS_METHOD; + } else { + summaryFlags &= ~IS_RS_METHOD; + } + } + + /** + * @return true if the method may write to a given field + */ + public boolean mayWrite(VM_Field field) { + if (!hasFieldWrite()) return false; + VM_FieldReference it = field.getMemberRef().asFieldReference(); + VM_BytecodeStream bcodes = getBytecodes(); + while (bcodes.hasMoreBytecodes()) { + int opcode = bcodes.nextInstruction(); + if (opcode == JBC_putstatic || opcode == JBC_putfield) { + VM_FieldReference fr = bcodes.getFieldReference(); + if (!fr.definitelyDifferent(it)) return true; + } else { + bcodes.skipInstruction(); + } + } + return false; + } + + /** + * This method computes a summary of interesting method characteristics + * and stores an encoding of the summary as an int. + */ + protected void computeSummary(int[] constantPool) { + int calleeSize = 0; + if (isSynchronized()) { + summaryFlags |= HAS_SYNCH; + calleeSize += 2*SYNCH_COST; // NOTE: ignoring catch/unlock/rethrow block. Probably the right thing to do. + } + + VM_BytecodeStream bcodes = getBytecodes(); + while (bcodes.hasMoreBytecodes()) { + switch (bcodes.nextInstruction()) { + // Array loads: null check, bounds check, index computation, load + case JBC_iaload:case JBC_laload:case JBC_faload:case JBC_daload: + case JBC_aaload:case JBC_baload:case JBC_caload:case JBC_saload: + summaryFlags |= HAS_ARRAY_READ; + calleeSize += ARRAY_LOAD_COST; + break; + + // Array stores: null check, bounds check, index computation, load + case JBC_iastore:case JBC_lastore:case JBC_fastore: + case JBC_dastore:case JBC_bastore:case JBC_castore:case JBC_sastore: + summaryFlags |= HAS_ARRAY_WRITE; + calleeSize += ARRAY_STORE_COST; + break; + case JBC_aastore: + summaryFlags |= HAS_ARRAY_WRITE; + calleeSize += ARRAY_STORE_COST + STORE_CHECK_COST; + break; + + // primitive computations (likely to be very cheap) + case JBC_iadd:case JBC_fadd:case JBC_dadd:case JBC_isub: + case JBC_fsub:case JBC_dsub:case JBC_imul:case JBC_fmul: + case JBC_dmul:case JBC_idiv:case JBC_fdiv:case JBC_ddiv: + case JBC_irem:case JBC_frem:case JBC_drem:case JBC_ineg: + case JBC_fneg:case JBC_dneg:case JBC_ishl:case JBC_ishr: + case JBC_lshr:case JBC_iushr:case JBC_iand:case JBC_ior: + case JBC_ixor:case JBC_iinc: + calleeSize += SIMPLE_OPERATION_COST; + break; + + // long computations may be different cost than primitive computations + case JBC_ladd:case JBC_lsub:case JBC_lmul:case JBC_ldiv: + case JBC_lrem:case JBC_lneg:case JBC_lshl:case JBC_lushr: + case JBC_land:case JBC_lor:case JBC_lxor: + calleeSize += LONG_OPERATION_COST; + break; + + // Some conversion operations are very cheap + case JBC_int2byte:case JBC_int2char:case JBC_int2short: + calleeSize += SIMPLE_OPERATION_COST; + break; + // Others are a little more costly + case JBC_i2l:case JBC_l2i: + calleeSize += LONG_OPERATION_COST; + break; + // Most are roughly as expensive as a call + case JBC_i2f:case JBC_i2d:case JBC_l2f:case JBC_l2d: + case JBC_f2i:case JBC_f2l:case JBC_f2d:case JBC_d2i: + case JBC_d2l:case JBC_d2f: + calleeSize += CALL_COST; + break; + + // approximate compares as 1 simple operation + case JBC_lcmp:case JBC_fcmpl:case JBC_fcmpg:case JBC_dcmpl: + case JBC_dcmpg: + calleeSize += SIMPLE_OPERATION_COST; + break; + + // most control flow is cheap; jsr is more expensive + case JBC_ifeq:case JBC_ifne:case JBC_iflt:case JBC_ifge: + case JBC_ifgt:case JBC_ifle:case JBC_if_icmpeq:case JBC_if_icmpne: + case JBC_if_icmplt:case JBC_if_icmpge:case JBC_if_icmpgt: + case JBC_if_icmple:case JBC_if_acmpeq:case JBC_if_acmpne: + case JBC_ifnull:case JBC_ifnonnull: + summaryFlags |= HAS_COND_BRANCH; + if (bcodes.getBranchOffset() < 0) summaryFlags |= HAS_BACK_BRANCH; + calleeSize += SIMPLE_OPERATION_COST; + continue; // we've processed all of the bytes, so avoid the call to skipInstruction() + case JBC_goto: + if (bcodes.getBranchOffset() < 0) summaryFlags |= HAS_BACK_BRANCH; + calleeSize += SIMPLE_OPERATION_COST; + continue; // we've processed all of the bytes, so avoid the call to skipInstruction() + case JBC_goto_w: + if (bcodes.getWideBranchOffset() < 0) summaryFlags |= HAS_BACK_BRANCH; + calleeSize += SIMPLE_OPERATION_COST; + continue; // we've processed all of the bytes, so avoid the call to skipInstruction() + case JBC_jsr:case JBC_jsr_w: + summaryFlags |= HAS_JSR; + calleeSize += JSR_COST; + break; + + case JBC_tableswitch:case JBC_lookupswitch: + summaryFlags |= HAS_SWITCH; + calleeSize += SWITCH_COST; + break; + + case JBC_putstatic: case JBC_putfield: + summaryFlags |= HAS_FIELD_WRITE; + calleeSize += SIMPLE_OPERATION_COST; + break; + + case JBC_getstatic: case JBC_getfield: + summaryFlags |= HAS_FIELD_READ; + calleeSize += SIMPLE_OPERATION_COST; + break; + + // Various flavors of calls. Assign them call cost (differentiate?) + case JBC_invokevirtual:case JBC_invokespecial: + case JBC_invokestatic: + // Special case VM_Magic's as being cheaper. + VM_MethodReference meth = bcodes.getMethodReference(constantPool); + if (meth.getType().isMagicType()) { + summaryFlags |= HAS_MAGIC; + calleeSize += MAGIC_COST; + } else { + summaryFlags |= HAS_INVOKE; + calleeSize += CALL_COST; + } + continue; // we've processed all of the bytes, so avoid the call to skipInstruction() + + case JBC_invokeinterface: + summaryFlags |= HAS_INVOKE; + calleeSize += CALL_COST; + break; + + case JBC_xxxunusedxxx: + if (VM.VerifyAssertions) VM._assert(VM.NOT_REACHED); + break; + + case JBC_new: case JBC_newarray: case JBC_anewarray: + summaryFlags |= HAS_ALLOCATION; + calleeSize += ALLOCATION_COST; + break; + + case JBC_arraylength: + calleeSize += SIMPLE_OPERATION_COST; + break; + + case JBC_athrow: + summaryFlags |= HAS_THROW; + calleeSize += THROW_COST; + break; + + case JBC_checkcast:case JBC_instanceof: + calleeSize += CLASS_CHECK_COST; + break; + + case JBC_monitorenter:case JBC_monitorexit: + summaryFlags |= HAS_SYNCH; + calleeSize += SYNCH_COST; + break; + + case JBC_multianewarray: + summaryFlags |= HAS_ALLOCATION; + calleeSize += CALL_COST; + break; + } + bcodes.skipInstruction(); + } + if (calleeSize > Character.MAX_VALUE) { + summarySize = Character.MAX_VALUE; + } else { + summarySize = (char)calleeSize; + } + } + + /** + * Create an optimizing compiler HIR code generator for this type of + * method + * @param context the generation context for the HIR generation + * @return a HIR generator + */ + public OPT_HIRGenerator createHIRGenerator(OPT_GenerationContext context){ + return new OPT_BC2IR(context); + } + + /** + * Must this method be OPT compiled? + * @param context the generation context for the HIR generation + * @return a HIR generator + */ + public boolean optCompileOnly() { + return false; + } +} Added: ext/org/jikesrvm/opt/OPT_Simplifier.java =================================================================== --- ext/org/jikesrvm/opt/OPT_Simplifier.java (rev 0) +++ ext/org/jikesrvm/opt/OPT_Simplifier.java 2007-03-20 15:49:03 UTC (rev 6) @@ -0,0 +1,3160 @@ +/* + *... [truncated message content] |
From: <cap...@us...> - 2007-03-19 16:02:01
|
Revision: 5 http://svn.sourceforge.net/pearcolator/?rev=5&view=rev Author: captain5050 Date: 2007-03-19 09:01:57 -0700 (Mon, 19 Mar 2007) Log Message: ----------- Build fixes and small tidy ups Modified Paths: -------------- src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java src/org/binarytranslator/arch/x86/decoder/X86_FlagLaziness.java src/org/binarytranslator/generic/branch/ProcedureInformation.java src/org/binarytranslator/generic/decoder/DecoderUtils.java src/org/binarytranslator/generic/memory/ByteAddressedMemory.java src/org/binarytranslator/generic/memory/CallBasedMemory.java src/org/binarytranslator/generic/memory/IntAddressedMemory.java src/org/binarytranslator/generic/memory/IntAddressedPreSwappedMemory.java src/org/binarytranslator/generic/memory/Memory.java src/org/binarytranslator/vmInterface/DBT_Trace.java Removed Paths: ------------- src/org/binarytranslator/generic/branch/ProcedureInformationComparator.java Modified: src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java =================================================================== --- src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java 2007-03-18 22:49:42 UTC (rev 4) +++ src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java 2007-03-19 16:01:57 UTC (rev 5) @@ -81,41 +81,122 @@ */ public final class PPC2IR extends DecoderUtils implements OPT_HIRGenerator, OPT_Operators, OPT_Constants { - /** - * Construct the PPC2IR object for the generation context; then - * we'll be ready to start generating the HIR. - */ - public PPC2IR(OPT_GenerationContext context) { - super(context); - // Create register maps PPC -> OPT_Register - intRegMap = new OPT_Register[32]; - intRegInUseMap = new boolean[32]; - fpRegMap = new OPT_Register[32]; - fpRegInUseMap = new boolean[32]; - crFieldMap_Lt = new OPT_Register[8]; - crFieldMap_Gt = new OPT_Register[8]; - crFieldMap_Eq = new OPT_Register[8]; - crFieldMap_SO = new OPT_Register[8]; - crFieldInUseMap = new boolean[8]; + // -oO Caches of references to process space entities Oo- - // Debug - if(DBT_Options.debugCFG) { - report("CFG at end of constructor:\n" + gc.cfg); - } - } + /** Type reference to the PPC process space */ + private static final VM_TypeReference psTref; - /** - * Translate the instruction at the given pc - * @param lazy the status of the lazy evaluation - * @param pc the program counter for the instruction - * @return the next instruction address or -1 - */ - protected int translateInstruction(Laziness lazy, int pc) { - return PPC_InstructionDecoder.translateInstruction(this, (PPC_ProcessSpace)ps, (PPC_Laziness)lazy, pc); - } + /** References to PPC process space GPR register fields */ + private static final VM_FieldReference[] gprFieldRefs; - // -oO Creations for being a PPC translator Oo- + /** References to PPC process space FPR register fields */ + private static final VM_FieldReference[] fprFieldRefs; + /** Reference to PPC process space condition register lt array field */ + private static final VM_FieldReference crf_ltFieldRef; + + /** Reference to PPC process space condition register gt array field */ + private static final VM_FieldReference crf_gtFieldRef; + + /** Reference to PPC process space condition register eq array field */ + private static final VM_FieldReference crf_eqFieldRef; + + /** Reference to PPC process space condition register so array field */ + private static final VM_FieldReference crf_soFieldRef; + + /** Reference to PPC process space xer_so field */ + private static final VM_FieldReference xer_soFieldRef; + /** Reference to PPC process space xer_ov field */ + private static final VM_FieldReference xer_ovFieldRef; + /** Reference to PPC process space xer_ca field */ + private static final VM_FieldReference xer_caFieldRef; + /** Reference to PPC process space xer_byteCount field */ + private static final VM_FieldReference xer_byteCountFieldRef; + + /** Reference to PPC process space fpscr field */ + private static final VM_FieldReference fpscrFieldRef; + + /** Reference to PPC process space ctr field */ + private static final VM_FieldReference ctrFieldRef; + + /** Reference to PPC process space lr fild */ + private static final VM_FieldReference lrFieldRef; + + /** Reference to PPC process space pc field */ + private static final VM_FieldReference pcFieldRef; + + /** Reference to PPC process space recordUncaughtBclr method */ + private static final VM_MethodReference recordUncaughtBclrMethRef; + + /** Reference to PPC process space recordUncaughtBcctr method */ + private static final VM_MethodReference recordUncaughtBcctrMethRef; + + /* Static initializer */ + static { + psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), + VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") + ); + gprFieldRefs = new VM_FieldReference[32]; + fprFieldRefs = new VM_FieldReference[32]; + final VM_Atom intAtom = VM_Atom.findOrCreateAsciiAtom("I"); + final VM_Atom doubleAtom = VM_Atom.findOrCreateAsciiAtom("D"); + for (int i=0; i < 32; i++){ + gprFieldRefs[i] = VM_MemberReference.findOrCreate(psTref, + VM_Atom.findOrCreateAsciiAtom("r"+i), + intAtom + ).asFieldReference(); + fprFieldRefs[i] = VM_MemberReference.findOrCreate(psTref, + VM_Atom.findOrCreateAsciiAtom("f"+i), + doubleAtom + ).asFieldReference(); + } + final VM_Atom boolArrayAtom = VM_Atom.findOrCreateAsciiAtom("[Z"); + crf_ltFieldRef = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_lt"), + boolArrayAtom + ).asFieldReference(); + crf_gtFieldRef = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_gt"), + boolArrayAtom + ).asFieldReference(); + crf_eqFieldRef = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_eq"), + boolArrayAtom + ).asFieldReference(); + crf_soFieldRef = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_so"), + boolArrayAtom + ).asFieldReference(); + final VM_Atom boolAtom = VM_Atom.findOrCreateAsciiAtom("Z"); + xer_soFieldRef = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("xer_so"), + boolAtom + ).asFieldReference(); + xer_ovFieldRef = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("xer_ov"), + boolAtom + ).asFieldReference(); + xer_caFieldRef = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("xer_ca"), + boolAtom + ).asFieldReference(); + final VM_Atom byteAtom = VM_Atom.findOrCreateAsciiAtom("B"); + xer_byteCountFieldRef = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("xer_byteCount"), + byteAtom + ).asFieldReference(); + fpscrFieldRef = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("fpscr"), + intAtom + ).asFieldReference(); + ctrFieldRef = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("ctr"), + intAtom + ).asFieldReference(); + lrFieldRef = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("lr"), + intAtom + ).asFieldReference(); + pcFieldRef = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("pc"), + intAtom + ).asFieldReference(); + recordUncaughtBclrMethRef = (VM_MethodReference)VM_MemberReference.findOrCreate(psTref, + VM_Atom.findOrCreateAsciiAtom("recordUncaughtBclr"), + VM_Atom.findOrCreateAsciiAtom("(II)V")); + recordUncaughtBcctrMethRef = (VM_MethodReference)VM_MemberReference.findOrCreate(psTref, + VM_Atom.findOrCreateAsciiAtom("recordUncaughtBcctr"), + VM_Atom.findOrCreateAsciiAtom("(II)V")); + } + // -oO PPC register to HIR register mappings Oo- /** @@ -124,20 +205,20 @@ * block. This avoids potential inconsistencies caused by using lazy * allocation and backward branches. */ - private OPT_Register intRegMap[]; + private final OPT_Register intRegMap[]; /** * Which PPC general purpose registers are in use */ - private boolean intRegInUseMap[]; + private final boolean intRegInUseMap[]; /** * The mapping of PPC floating point registers to HIR registers. */ - private OPT_Register fpRegMap[]; + private final OPT_Register fpRegMap[]; /** * Which PPC floating point registers are in use */ - private boolean fpRegInUseMap[]; + private final boolean fpRegInUseMap[]; /** * The HIR register holding the PPC FPSCR register. @@ -167,12 +248,6 @@ private boolean lrRegInUse; /** - * The HIR register holding the PPC XER register when it is combined - * in a fillAll or spillAll block - */ - private OPT_Register xerRegMap; - - /** * The HIR register holding the PPC XER register's byte count (bits * 25 to 31) */ @@ -203,34 +278,67 @@ * value of the corresponding condition register field's SO * bit. */ - private OPT_Register crFieldMap_Lt[]; + private final OPT_Register crFieldMap_Lt[]; /** * These 8 registers hold a zero or non-zero value depending on the * value of the corresponding condition register field's SO * bit. */ - private OPT_Register crFieldMap_Gt[]; + private final OPT_Register crFieldMap_Gt[]; /** * These 8 registers hold a zero or non-zero value depending on the * value of the corresponding condition register field's SO * bit. */ - private OPT_Register crFieldMap_Eq[]; + private final OPT_Register crFieldMap_Eq[]; /** * These 8 registers hold a zero or non-zero value depending on the * value of the corresponding condition register field's SO * bit. */ - private OPT_Register crFieldMap_SO[]; + private final OPT_Register crFieldMap_SO[]; /** * What condition register fields are in use? */ - private boolean crFieldInUseMap[]; + private final boolean crFieldInUseMap[]; + /** + * Construct the PPC2IR object for the generation context; then + * we'll be ready to start generating the HIR. + */ + public PPC2IR(OPT_GenerationContext context) { + super(context); + // Create register maps PPC -> OPT_Register + intRegMap = new OPT_Register[32]; + intRegInUseMap = new boolean[32]; + fpRegMap = new OPT_Register[32]; + fpRegInUseMap = new boolean[32]; + crFieldMap_Lt = new OPT_Register[8]; + crFieldMap_Gt = new OPT_Register[8]; + crFieldMap_Eq = new OPT_Register[8]; + crFieldMap_SO = new OPT_Register[8]; + crFieldInUseMap = new boolean[8]; + + // Debug + if(DBT_Options.debugCFG) { + report("CFG at end of constructor:\n" + gc.cfg); + } + } + + /** + * Translate the instruction at the given pc + * @param lazy the status of the lazy evaluation + * @param pc the program counter for the instruction + * @return the next instruction address or -1 + */ + protected int translateInstruction(Laziness lazy, int pc) { + return PPC_InstructionDecoder.translateInstruction(this, (PPC_ProcessSpace)ps, (PPC_Laziness)lazy, pc); + } + // -oO Fill/spill registers between OPT_Registers and the PPC_ProcessSpace Oo- /** @@ -249,17 +357,10 @@ else { result = new OPT_RegisterOperand(intRegMap[r], VM_TypeReference.Int); } - - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("r"+r), - VM_Atom.findOrCreateAsciiAtom("I") - ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, result, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(gprFieldRefs[r].peekResolvedField().getOffset()), + new OPT_LocationOperand(gprFieldRefs[r]), new OPT_TrueGuardOperand()) ); } @@ -276,16 +377,10 @@ OPT_RegisterOperand regOp = new OPT_RegisterOperand(intRegMap[r], VM_TypeReference.Int); - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("r"+r), - VM_Atom.findOrCreateAsciiAtom("I") - ).asFieldReference(); appendInstructionToCurrentBlock(PutField.create(PUTFIELD, regOp, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(gprFieldRefs[r].peekResolvedField().getOffset()), + new OPT_LocationOperand(gprFieldRefs[r]), new OPT_TrueGuardOperand()) ); } @@ -308,16 +403,10 @@ result = new OPT_RegisterOperand(fpRegMap[r], VM_TypeReference.Double); } - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("f"+r), - VM_Atom.findOrCreateAsciiAtom("D") - ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, result, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(fprFieldRefs[r].peekResolvedField().getOffset()), + new OPT_LocationOperand(fprFieldRefs[r]), new OPT_TrueGuardOperand()) ); } @@ -334,16 +423,10 @@ OPT_RegisterOperand regOp = new OPT_RegisterOperand(fpRegMap[r], VM_TypeReference.Double); - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("f"+r), - VM_Atom.findOrCreateAsciiAtom("D") - ).asFieldReference(); appendInstructionToCurrentBlock(PutField.create(PUTFIELD, regOp, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(fprFieldRefs[r].peekResolvedField().getOffset()), + new OPT_LocationOperand(fprFieldRefs[r]), new OPT_TrueGuardOperand()) ); } @@ -368,55 +451,40 @@ OPT_RegisterOperand arrayref = gc.temps.makeTemp(VM_TypeReference.BooleanArray); - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_lt"), - VM_Atom.findOrCreateAsciiAtom("[Z") - ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, arrayref, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(crf_ltFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(crf_ltFieldRef), new OPT_TrueGuardOperand()) ); appendInstructionToCurrentBlock(ALoad.create(UBYTE_ALOAD, lt, arrayref, new OPT_IntConstantOperand(crf), new OPT_LocationOperand(VM_TypeReference.BooleanArray), new OPT_TrueGuardOperand())); - ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_gt"), - VM_Atom.findOrCreateAsciiAtom("[Z") - ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, arrayref, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(crf_gtFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(crf_gtFieldRef), new OPT_TrueGuardOperand()) ); appendInstructionToCurrentBlock(ALoad.create(UBYTE_ALOAD, gt, arrayref, new OPT_IntConstantOperand(crf), new OPT_LocationOperand(VM_TypeReference.BooleanArray), new OPT_TrueGuardOperand())); - ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_eq"), - VM_Atom.findOrCreateAsciiAtom("[Z") - ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, arrayref, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(crf_eqFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(crf_eqFieldRef), new OPT_TrueGuardOperand()) ); appendInstructionToCurrentBlock(ALoad.create(UBYTE_ALOAD, eq, arrayref, new OPT_IntConstantOperand(crf), new OPT_LocationOperand(VM_TypeReference.BooleanArray), new OPT_TrueGuardOperand())); - ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_so"), - VM_Atom.findOrCreateAsciiAtom("[Z") - ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, arrayref, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(crf_soFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(crf_soFieldRef), new OPT_TrueGuardOperand()) ); appendInstructionToCurrentBlock(ALoad.create(UBYTE_ALOAD, so, @@ -439,55 +507,40 @@ OPT_RegisterOperand arrayref = gc.temps.makeTemp(VM_TypeReference.BooleanArray); - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_lt"), - VM_Atom.findOrCreateAsciiAtom("[Z") - ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, arrayref, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(crf_ltFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(crf_ltFieldRef), new OPT_TrueGuardOperand()) ); appendInstructionToCurrentBlock(AStore.create(BYTE_ASTORE, lt, arrayref, new OPT_IntConstantOperand(crf), new OPT_LocationOperand(VM_TypeReference.BooleanArray), new OPT_TrueGuardOperand())); - ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_gt"), - VM_Atom.findOrCreateAsciiAtom("[Z") - ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, arrayref, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(crf_gtFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(crf_gtFieldRef), new OPT_TrueGuardOperand()) ); appendInstructionToCurrentBlock(AStore.create(BYTE_ASTORE, gt, arrayref, new OPT_IntConstantOperand(crf), new OPT_LocationOperand(VM_TypeReference.BooleanArray), new OPT_TrueGuardOperand())); - ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_eq"), - VM_Atom.findOrCreateAsciiAtom("[Z") - ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, arrayref, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(crf_eqFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(crf_eqFieldRef), new OPT_TrueGuardOperand()) ); appendInstructionToCurrentBlock(AStore.create(BYTE_ASTORE, eq, arrayref, new OPT_IntConstantOperand(crf), new OPT_LocationOperand(VM_TypeReference.BooleanArray), new OPT_TrueGuardOperand())); - ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_so"), - VM_Atom.findOrCreateAsciiAtom("[Z") - ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, arrayref, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(crf_soFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(crf_soFieldRef), new OPT_TrueGuardOperand()) ); appendInstructionToCurrentBlock(AStore.create(BYTE_ASTORE, so, @@ -510,20 +563,12 @@ else { result = new OPT_RegisterOperand(fpscrRegMap, VM_TypeReference.Int); } - - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("fpscr"), - VM_Atom.findOrCreateAsciiAtom("I") - ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, result, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(fpscrFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(fpscrFieldRef), new OPT_TrueGuardOperand()) ); - } /** @@ -533,16 +578,10 @@ { OPT_RegisterOperand regOp = new OPT_RegisterOperand(fpscrRegMap, VM_TypeReference.Int); - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("fpscr"), - VM_Atom.findOrCreateAsciiAtom("I") - ).asFieldReference(); appendInstructionToCurrentBlock(PutField.create(PUTFIELD, regOp, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(fpscrFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(fpscrFieldRef), new OPT_TrueGuardOperand()) ); } @@ -561,16 +600,10 @@ else { result = new OPT_RegisterOperand(ctrRegMap, VM_TypeReference.Int); } - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("ctr"), - VM_Atom.findOrCreateAsciiAtom("I") - ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, result, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(ctrFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(ctrFieldRef), new OPT_TrueGuardOperand()) ); } @@ -583,16 +616,10 @@ { OPT_RegisterOperand regOp = new OPT_RegisterOperand(ctrRegMap, VM_TypeReference.Int); - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("ctr"), - VM_Atom.findOrCreateAsciiAtom("I") - ).asFieldReference(); appendInstructionToCurrentBlock(PutField.create(PUTFIELD, regOp, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(ctrFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(ctrFieldRef), new OPT_TrueGuardOperand()) ); } @@ -604,69 +631,52 @@ */ private void fillXERRegister() { - OPT_RegisterOperand xerRegMap_Op; OPT_RegisterOperand xerRegMap_SO_Op; OPT_RegisterOperand xerRegMap_OV_Op; OPT_RegisterOperand xerRegMap_ByteCountOp; OPT_RegisterOperand xerRegMap_CA_Op; if (xerRegMap_SO == null) { - xerRegMap_Op = gc.temps.makeTempInt(); - xerRegMap_SO_Op = gc.temps.makeTempInt(); - xerRegMap_OV_Op = gc.temps.makeTempInt(); - xerRegMap_ByteCountOp = gc.temps.makeTempInt(); + xerRegMap_SO_Op = gc.temps.makeTempBoolean(); + xerRegMap_OV_Op = gc.temps.makeTempBoolean(); xerRegMap_CA_Op = gc.temps.makeTempBoolean(); + xerRegMap_ByteCountOp = gc.temps.makeTemp(VM_TypeReference.Byte); - xerRegMap = xerRegMap_Op.register; xerRegMap_SO = xerRegMap_SO_Op.register; xerRegMap_OV = xerRegMap_OV_Op.register; - xerRegMap_ByteCount = xerRegMap_ByteCountOp.register; xerRegMap_CA = xerRegMap_CA_Op.register; + xerRegMap_ByteCount = xerRegMap_ByteCountOp.register; } else { - xerRegMap_Op = new OPT_RegisterOperand(xerRegMap, VM_TypeReference.Int); - xerRegMap_SO_Op = new OPT_RegisterOperand(xerRegMap_SO, VM_TypeReference.Int); - xerRegMap_OV_Op = new OPT_RegisterOperand(xerRegMap_OV, VM_TypeReference.Int); - xerRegMap_ByteCountOp = new OPT_RegisterOperand(xerRegMap_ByteCount, VM_TypeReference.Int); + xerRegMap_SO_Op = new OPT_RegisterOperand(xerRegMap_SO, VM_TypeReference.Boolean); + xerRegMap_OV_Op = new OPT_RegisterOperand(xerRegMap_OV, VM_TypeReference.Boolean); xerRegMap_CA_Op = new OPT_RegisterOperand(xerRegMap_CA, VM_TypeReference.Boolean); + xerRegMap_ByteCountOp = new OPT_RegisterOperand(xerRegMap_ByteCount, VM_TypeReference.Byte); } - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("xer"), - VM_Atom.findOrCreateAsciiAtom("I") - ).asFieldReference(); - appendInstructionToCurrentBlock(GetField.create(GETFIELD, xerRegMap_Op, + appendInstructionToCurrentBlock(GetField.create(GETFIELD, xerRegMap_SO_Op, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(xer_soFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(xer_soFieldRef), new OPT_TrueGuardOperand()) ); - // Copy SO bit into XER[SO] register - appendInstructionToCurrentBlock(Binary.create(INT_AND, xerRegMap_SO_Op, - xerRegMap_Op.copyRO(), - new OPT_IntConstantOperand(1 << 31))); - - // Copy OV bit into XER[OV] register - appendInstructionToCurrentBlock(Binary.create(INT_AND, xerRegMap_OV_Op, - xerRegMap_Op.copyRO(), - new OPT_IntConstantOperand(1 << 30))); - - // Copy CA bit into XER[CA] register - OPT_RegisterOperand tempInt = getTempInt(0); - appendInstructionToCurrentBlock(Binary.create(INT_AND, tempInt, - xerRegMap_Op.copyRO(), - new OPT_IntConstantOperand(1 << 29))); - appendInstructionToCurrentBlock(BooleanCmp.create(BOOLEAN_CMP_INT, xerRegMap_CA_Op, - tempInt.copyRO(), - new OPT_IntConstantOperand(0), - OPT_ConditionOperand.NOT_EQUAL(), - OPT_BranchProfileOperand.unlikely())); - - // Copy byte count bits out - appendInstructionToCurrentBlock(Binary.create(INT_AND, xerRegMap_ByteCountOp, - xerRegMap_Op.copyRO(), - new OPT_IntConstantOperand(0x3f))); + appendInstructionToCurrentBlock(GetField.create(GETFIELD, xerRegMap_OV_Op, + gc.makeLocal(1,psTref), + new OPT_AddressConstantOperand(xer_ovFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(xer_ovFieldRef), + new OPT_TrueGuardOperand()) + ); + appendInstructionToCurrentBlock(GetField.create(GETFIELD, xerRegMap_CA_Op, + gc.makeLocal(1,psTref), + new OPT_AddressConstantOperand(xer_caFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(xer_caFieldRef), + new OPT_TrueGuardOperand()) + ); + appendInstructionToCurrentBlock(GetField.create(GETFIELD, xerRegMap_ByteCountOp, + gc.makeLocal(1,psTref), + new OPT_AddressConstantOperand(xer_byteCountFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(xer_byteCountFieldRef), + new OPT_TrueGuardOperand()) + ); } /** @@ -675,60 +685,36 @@ */ private void spillXERRegister() { - // Set up xer register with byte count - OPT_RegisterOperand xer = new OPT_RegisterOperand(xerRegMap, VM_TypeReference.Int); - appendInstructionToCurrentBlock(Move.create(INT_MOVE, xer, - new OPT_RegisterOperand(xerRegMap_ByteCount, VM_TypeReference.Int)) + OPT_RegisterOperand xerRegMap_SO_Op = new OPT_RegisterOperand(xerRegMap_SO, VM_TypeReference.Boolean); + appendInstructionToCurrentBlock(PutField.create(PUTFIELD, xerRegMap_SO_Op, + gc.makeLocal(1,psTref), + new OPT_AddressConstantOperand(xer_soFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(xer_soFieldRef), + new OPT_TrueGuardOperand()) ); - // SO bit - OPT_RegisterOperand tempInt = getTempInt(0); - appendInstructionToCurrentBlock(CondMove.create(INT_COND_MOVE, - tempInt, - new OPT_RegisterOperand(xerRegMap_SO, VM_TypeReference.Int), - new OPT_IntConstantOperand(0), - OPT_ConditionOperand.EQUAL(), - new OPT_IntConstantOperand(0), - new OPT_IntConstantOperand(1 << 31))); - appendInstructionToCurrentBlock(Binary.create(INT_OR, xer.copyRO(), - xer.copy(), - tempInt.copyRO()) + + + OPT_RegisterOperand xerRegMap_OV_Op = new OPT_RegisterOperand(xerRegMap_OV, VM_TypeReference.Boolean); + appendInstructionToCurrentBlock(PutField.create(PUTFIELD, xerRegMap_OV_Op, + gc.makeLocal(1,psTref), + new OPT_AddressConstantOperand(xer_ovFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(xer_ovFieldRef), + new OPT_TrueGuardOperand()) ); - // OV bit - appendInstructionToCurrentBlock(CondMove.create(INT_COND_MOVE, - tempInt.copyRO(), - new OPT_RegisterOperand(xerRegMap_OV, VM_TypeReference.Int), - new OPT_IntConstantOperand(0), - OPT_ConditionOperand.EQUAL(), - new OPT_IntConstantOperand(0), - new OPT_IntConstantOperand(1 << 30))); - appendInstructionToCurrentBlock(Binary.create(INT_OR, xer.copyRO(), - xer.copy(), - tempInt.copyRO()) + + OPT_RegisterOperand xerRegMap_CA_Op = new OPT_RegisterOperand(xerRegMap_CA, VM_TypeReference.Boolean); + appendInstructionToCurrentBlock(PutField.create(PUTFIELD, xerRegMap_CA_Op, + gc.makeLocal(1,psTref), + new OPT_AddressConstantOperand(xer_caFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(xer_caFieldRef), + new OPT_TrueGuardOperand()) ); - - // CA bit - appendInstructionToCurrentBlock(CondMove.create(INT_COND_MOVE, - tempInt.copyRO(), - new OPT_RegisterOperand(xerRegMap_CA, VM_TypeReference.Boolean), - new OPT_IntConstantOperand(0), - OPT_ConditionOperand.EQUAL(), - new OPT_IntConstantOperand(0), - new OPT_IntConstantOperand(1 << 29))); - appendInstructionToCurrentBlock(Binary.create(INT_OR, xer.copyRO(), - xer.copy(), - tempInt.copyRO())); - - // Store to process space - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("xer"), - VM_Atom.findOrCreateAsciiAtom("I") - ).asFieldReference(); - appendInstructionToCurrentBlock(PutField.create(PUTFIELD, xer.copy(), + + OPT_RegisterOperand xerRegMap_ByteCountOp = new OPT_RegisterOperand(xerRegMap_ByteCount, VM_TypeReference.Byte); + appendInstructionToCurrentBlock(PutField.create(PUTFIELD, xerRegMap_ByteCountOp, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(xer_byteCountFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(xer_byteCountFieldRef), new OPT_TrueGuardOperand()) ); } @@ -748,16 +734,10 @@ else { result = new OPT_RegisterOperand(lrRegMap, VM_TypeReference.Int); } - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("lr"), - VM_Atom.findOrCreateAsciiAtom("I") - ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, result, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(lrFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(lrFieldRef), new OPT_TrueGuardOperand()) ); } @@ -769,17 +749,10 @@ private void spillLRRegister() { OPT_RegisterOperand regOp = new OPT_RegisterOperand(lrRegMap, VM_TypeReference.Int); - - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("lr"), - VM_Atom.findOrCreateAsciiAtom("I") - ).asFieldReference(); appendInstructionToCurrentBlock(PutField.create(PUTFIELD, regOp, gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(lrFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(lrFieldRef), new OPT_TrueGuardOperand()) ); } @@ -835,16 +808,10 @@ * Spill a given PC value into the process space */ private void spillPC(int pc) { - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") - ); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("pc"), - VM_Atom.findOrCreateAsciiAtom("I") - ).asFieldReference(); appendInstructionToCurrentBlock(PutField.create(PUTFIELD, new OPT_IntConstantOperand(pc), gc.makeLocal(1,psTref), - new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), - new OPT_LocationOperand(ref), + new OPT_AddressConstantOperand(pcFieldRef.peekResolvedField().getOffset()), + new OPT_LocationOperand(pcFieldRef), new OPT_TrueGuardOperand())); } // -oO Find a register Oo- @@ -925,6 +892,7 @@ default: DBT_OptimizingCompilerException.UNREACHABLE(); } + return null; // stop compiler warnings } /** @@ -960,7 +928,7 @@ */ public OPT_RegisterOperand getXER_ByteCountRegister() { xerRegInUse = true; - return new OPT_RegisterOperand (xerRegMap_ByteCount, VM_TypeReference.Int); + return new OPT_RegisterOperand (xerRegMap_ByteCount, VM_TypeReference.Byte); } /** @@ -969,7 +937,7 @@ */ public OPT_RegisterOperand getXER_SO_Register() { xerRegInUse = true; - return new OPT_RegisterOperand (xerRegMap_SO, VM_TypeReference.Int); + return new OPT_RegisterOperand (xerRegMap_SO, VM_TypeReference.Boolean); } /** @@ -978,7 +946,7 @@ */ public OPT_RegisterOperand getXER_OV_Register() { xerRegInUse = true; - return new OPT_RegisterOperand (xerRegMap_OV, VM_TypeReference.Int); + return new OPT_RegisterOperand (xerRegMap_OV, VM_TypeReference.Boolean); } /** @@ -1062,14 +1030,8 @@ if((gc.options.getOptLevel() > 0) && (DBT_Options.plantUncaughtBclrWatcher)) { // Plant call OPT_Instruction s = Call.create(CALL, null, null, null, null, 3); - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom - ("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;")); - VM_MethodReference methRef = (VM_MethodReference)VM_MemberReference.findOrCreate(psTref, - VM_Atom.findOrCreateAsciiAtom("recordUncaughtBclr"), - VM_Atom.findOrCreateAsciiAtom("(II)V")); - VM_Method method = methRef.resolve(); - OPT_MethodOperand methOp = OPT_MethodOperand.VIRTUAL(methRef, method); + VM_Method method = recordUncaughtBclrMethRef.resolve(); + OPT_MethodOperand methOp = OPT_MethodOperand.VIRTUAL(recordUncaughtBclrMethRef, method); OPT_Operand psRef = gc.makeLocal(1,psTref); Call.setParam(s, 0, psRef); // Reference to ps, sets 'this' pointer @@ -1077,7 +1039,7 @@ Call.setParam(s, 2, lr); // Link register value Call.setGuard(s, new OPT_TrueGuardOperand()); Call.setMethod(s, methOp); - Call.setAddress(s, new OPT_AddressConstantOperand(methRef.peekResolvedMethod().getOffset())); + Call.setAddress(s, new OPT_AddressConstantOperand(recordUncaughtBclrMethRef.peekResolvedMethod().getOffset())); s.position = gc.inlineSequence; s.bcIndex = 7; appendInstructionToCurrentBlock(s); @@ -1093,21 +1055,15 @@ if(DBT_Options.plantUncaughtBcctrWatcher) { // Plant call OPT_Instruction s = Call.create(CALL, null, null, null, null, 3); - VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), - VM_Atom.findOrCreateAsciiAtom - ("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;")); - VM_MethodReference methRef = (VM_MethodReference)VM_MemberReference.findOrCreate(psTref, - VM_Atom.findOrCreateAsciiAtom("recordUncaughtBcctr"), - VM_Atom.findOrCreateAsciiAtom("(II)V")); - VM_Method method = methRef.resolve(); - OPT_MethodOperand methOp = OPT_MethodOperand.VIRTUAL(methRef, method); + VM_Method method = recordUncaughtBcctrMethRef.resolve(); + OPT_MethodOperand methOp = OPT_MethodOperand.VIRTUAL(recordUncaughtBcctrMethRef, method); OPT_Operand psRef = gc.makeLocal(1,psTref); Call.setParam(s, 0, psRef); // Reference to ps, sets 'this' pointer Call.setParam(s, 1, new OPT_IntConstantOperand(pc)); // Address of bcctr instruction Call.setParam(s, 2, ctr); // Count register value Call.setGuard(s, new OPT_TrueGuardOperand()); Call.setMethod(s, methOp); - Call.setAddress(s, new OPT_AddressConstantOperand(methRef.peekResolvedMethod().getOffset())); + Call.setAddress(s, new OPT_AddressConstantOperand(recordUncaughtBcctrMethRef.peekResolvedMethod().getOffset())); s.position = gc.inlineSequence; s.bcIndex = 13; appendInstructionToCurrentBlock(s); @@ -1147,7 +1103,6 @@ unusedRegisterList.add(lrRegMap); } if(xerRegInUse == false) { - unusedRegisterList.add(xerRegMap); unusedRegisterList.add(xerRegMap_SO); unusedRegisterList.add(xerRegMap_OV); unusedRegisterList.add(xerRegMap_ByteCount); Modified: src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java =================================================================== --- src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java 2007-03-18 22:49:42 UTC (rev 4) +++ src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java 2007-03-19 16:01:57 UTC (rev 5) @@ -30,588 +30,588 @@ * implements default methods that just throw errors */ public class PPC_InstructionDecoder extends InstructionDecoder implements OPT_Operators { - /* Different instruction formats */ + /* Different instruction formats */ - /** Invalid opcode */ - protected static final int INVALID_OP = 0; - /** D form opcode */ - protected static final int D_FORM = 1; - /** B form opcode */ - protected static final int B_FORM = 2; - /** I form opcode */ - protected static final int I_FORM = 3; - /** SC form opcode */ - protected static final int SC_FORM = 4; - /** X form opcode */ - protected static final int X_FORM = 5; - /** XL form opcode */ - protected static final int XL_FORM = 6; - /** XFX form opcode */ - protected static final int XFX_FORM = 7; - /** XFL form opcode */ - protected static final int XFL_FORM = 8; - /** XO form opcode */ - protected static final int XO_FORM = 9; - /** A form opcode */ - protected static final int A_FORM = 10; - /** M form opcode */ - protected static final int M_FORM = 11; - /** Exetended form opcode */ - protected static final int EXTENDED = 12; + /** Invalid opcode */ + protected static final int INVALID_OP = 0; + /** D form opcode */ + protected static final int D_FORM = 1; + /** B form opcode */ + protected static final int B_FORM = 2; + /** I form opcode */ + protected static final int I_FORM = 3; + /** SC form opcode */ + protected static final int SC_FORM = 4; + /** X form opcode */ + protected static final int X_FORM = 5; + /** XL form opcode */ + protected static final int XL_FORM = 6; + /** XFX form opcode */ + protected static final int XFX_FORM = 7; + /** XFL form opcode */ + protected static final int XFL_FORM = 8; + /** XO form opcode */ + protected static final int XO_FORM = 9; + /** A form opcode */ + protected static final int A_FORM = 10; + /** M form opcode */ + protected static final int M_FORM = 11; + /** Exetended form opcode */ + protected static final int EXTENDED = 12; - /* Types of comparison */ + /* Types of comparison */ - /** Unsigned integer comparison */ - static final int UNSIGNED_INT_CMP=1; - /** Signed integer comparison */ - static final int SIGNED_INT_CMP=2; - /** Floating point unordered comparison */ - static final int FP_CMPU=3; + /** Unsigned integer comparison */ + static final int UNSIGNED_INT_CMP=1; + /** Signed integer comparison */ + static final int SIGNED_INT_CMP=2; + /** Floating point unordered comparison */ + static final int FP_CMPU=3; - /** - * Look up table to find instruction translator, performed using the - * instruction opcode. - */ - static final OpCodeLookUp[] opCodeLookUp = { - /* OPCD form mnemonic translator */ - /* ---- ---- -------- ---------- */ - ... [truncated message content] |
From: <cap...@us...> - 2007-03-18 22:49:42
|
Revision: 4 http://svn.sourceforge.net/pearcolator/?rev=4&view=rev Author: captain5050 Date: 2007-03-18 15:49:42 -0700 (Sun, 18 Mar 2007) Log Message: ----------- More build fixes Modified Paths: -------------- src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java src/org/binarytranslator/arch/x86/decoder/X86_Registers.java src/org/binarytranslator/generic/decoder/DecoderUtils.java src/org/binarytranslator/generic/os/process/ProcessSpace.java src/org/binarytranslator/vmInterface/DBT_ConvertBinaryToHIR.java src/org/binarytranslator/vmInterface/DBT_Trace.java Modified: src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java =================================================================== --- src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java 2007-03-16 23:59:58 UTC (rev 3) +++ src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java 2007-03-18 22:49:42 UTC (rev 4) @@ -363,7 +363,7 @@ } OPT_RegisterOperand lt = new OPT_RegisterOperand(crFieldMap_Lt[crf], VM_TypeReference.Boolean); OPT_RegisterOperand gt = new OPT_RegisterOperand(crFieldMap_Gt[crf], VM_TypeReference.Boolean); - OPT_RegisterOperand lt = new OPT_RegisterOperand(crFieldMap_Eq[crf], VM_TypeReference.Boolean); + OPT_RegisterOperand eq = new OPT_RegisterOperand(crFieldMap_Eq[crf], VM_TypeReference.Boolean); OPT_RegisterOperand so = new OPT_RegisterOperand(crFieldMap_SO[crf], VM_TypeReference.Boolean); OPT_RegisterOperand arrayref = gc.temps.makeTemp(VM_TypeReference.BooleanArray); @@ -384,9 +384,9 @@ arrayref, new OPT_IntConstantOperand(crf), new OPT_LocationOperand(VM_TypeReference.BooleanArray), new OPT_TrueGuardOperand())); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_gt"), - VM_Atom.findOrCreateAsciiAtom("[Z") - ).asFieldReference(); + ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_gt"), + VM_Atom.findOrCreateAsciiAtom("[Z") + ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, arrayref, gc.makeLocal(1,psTref), new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), @@ -397,9 +397,9 @@ arrayref, new OPT_IntConstantOperand(crf), new OPT_LocationOperand(VM_TypeReference.BooleanArray), new OPT_TrueGuardOperand())); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_eq"), - VM_Atom.findOrCreateAsciiAtom("[Z") - ).asFieldReference(); + ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_eq"), + VM_Atom.findOrCreateAsciiAtom("[Z") + ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, arrayref, gc.makeLocal(1,psTref), new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), @@ -410,9 +410,9 @@ arrayref, new OPT_IntConstantOperand(crf), new OPT_LocationOperand(VM_TypeReference.BooleanArray), new OPT_TrueGuardOperand())); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_so"), - VM_Atom.findOrCreateAsciiAtom("[Z") - ).asFieldReference(); + ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_so"), + VM_Atom.findOrCreateAsciiAtom("[Z") + ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, arrayref, gc.makeLocal(1,psTref), new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), @@ -434,7 +434,7 @@ { OPT_RegisterOperand lt = new OPT_RegisterOperand(crFieldMap_Lt[crf], VM_TypeReference.Boolean); OPT_RegisterOperand gt = new OPT_RegisterOperand(crFieldMap_Gt[crf], VM_TypeReference.Boolean); - OPT_RegisterOperand lt = new OPT_RegisterOperand(crFieldMap_Eq[crf], VM_TypeReference.Boolean); + OPT_RegisterOperand eq = new OPT_RegisterOperand(crFieldMap_Eq[crf], VM_TypeReference.Boolean); OPT_RegisterOperand so = new OPT_RegisterOperand(crFieldMap_SO[crf], VM_TypeReference.Boolean); OPT_RegisterOperand arrayref = gc.temps.makeTemp(VM_TypeReference.BooleanArray); @@ -455,9 +455,9 @@ arrayref, new OPT_IntConstantOperand(crf), new OPT_LocationOperand(VM_TypeReference.BooleanArray), new OPT_TrueGuardOperand())); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_gt"), - VM_Atom.findOrCreateAsciiAtom("[Z") - ).asFieldReference(); + ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_gt"), + VM_Atom.findOrCreateAsciiAtom("[Z") + ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, arrayref, gc.makeLocal(1,psTref), new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), @@ -468,9 +468,9 @@ arrayref, new OPT_IntConstantOperand(crf), new OPT_LocationOperand(VM_TypeReference.BooleanArray), new OPT_TrueGuardOperand())); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_eq"), - VM_Atom.findOrCreateAsciiAtom("[Z") - ).asFieldReference(); + ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_eq"), + VM_Atom.findOrCreateAsciiAtom("[Z") + ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, arrayref, gc.makeLocal(1,psTref), new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), @@ -481,9 +481,9 @@ arrayref, new OPT_IntConstantOperand(crf), new OPT_LocationOperand(VM_TypeReference.BooleanArray), new OPT_TrueGuardOperand())); - VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_so"), - VM_Atom.findOrCreateAsciiAtom("[Z") - ).asFieldReference(); + ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_so"), + VM_Atom.findOrCreateAsciiAtom("[Z") + ).asFieldReference(); appendInstructionToCurrentBlock(GetField.create(GETFIELD, arrayref, gc.makeLocal(1,psTref), new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), @@ -915,13 +915,13 @@ int crf = crb >> 2; switch(crb & 0x3) { case 0: - return ppc2ir.getCR_Lt_Register(crf); + return getCR_Lt_Register(crf); case 1: - return ppc2ir.getCR_Gt_Register(crf); + return getCR_Gt_Register(crf); case 2: - return ppc2ir.getCR_Eq_Register(crf); + return getCR_Eq_Register(crf); case 3: - return ppc2ir.getCR_SO_Register(crf); + return getCR_SO_Register(crf); default: DBT_OptimizingCompilerException.UNREACHABLE(); } Modified: src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java =================================================================== --- src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java 2007-03-16 23:59:58 UTC (rev 3) +++ src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java 2007-03-18 22:49:42 UTC (rev 4) @@ -589,7 +589,7 @@ OPT_BranchProfileOperand likelyOp = ppc2ir.getConditionalBranchProfileOperand(likely); // Grab the flag to compare - OPT_RegisterOperand flag = getCRB_Register(BI); + OPT_RegisterOperand flag = ppc2ir.getCRB_Register(BI); // The condition to test OPT_ConditionOperand condOp; Modified: src/org/binarytranslator/arch/x86/decoder/X86_Registers.java =================================================================== --- src/org/binarytranslator/arch/x86/decoder/X86_Registers.java 2007-03-16 23:59:58 UTC (rev 3) +++ src/org/binarytranslator/arch/x86/decoder/X86_Registers.java 2007-03-18 22:49:42 UTC (rev 4) @@ -8,9 +8,7 @@ */ package org.binarytranslator.arch.x86; -import org.binarytranslator.generic.memory.Registers; - -public class X86_Registers extends Registers { +public class X86_Registers { String[] name32 = {"eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi"}; private int[] GP32 = new int[8]; Modified: src/org/binarytranslator/generic/decoder/DecoderUtils.java =================================================================== --- src/org/binarytranslator/generic/decoder/DecoderUtils.java 2007-03-16 23:59:58 UTC (rev 3) +++ src/org/binarytranslator/generic/decoder/DecoderUtils.java 2007-03-18 22:49:42 UTC (rev 4) @@ -1282,71 +1282,4 @@ public OPT_RegisterOperand makeTemp(VM_TypeReference type) { return gc.temps.makeTemp(type); } - - /** - * Remove conditional moves - */ - static void eliminateConditionalMoves(OPT_IR ir) { - OPT_BasicBlock curBB = ir.gc.prologue; - while(curBB != null) { - OPT_Instruction curInstr = curBB.firstInstruction(); - loop_over_instructions: - while(BBend.conforms(curInstr) == false) { - if(CondMove.conforms(curInstr) && (curInstr.operator() == INT_COND_MOVE)) { - OPT_BasicBlock compareBlock; // block containing compare instruction - OPT_BasicBlock trueBlock; // block containing true payload - OPT_BasicBlock falseBlock; // block containing false payload - OPT_BasicBlock restOfBlock; // the rest of the block - - // Set up blocks - compareBlock = curBB; - trueBlock = new OPT_BasicBlock(0, ir.gc.inlineSequence, ir.gc.cfg); - falseBlock = new OPT_BasicBlock(0, ir.gc.inlineSequence, ir.gc.cfg); - restOfBlock = compareBlock.splitNodeAt(curInstr, ir); - ir.gc.cfg.linkInCodeOrder(compareBlock, falseBlock); - ir.gc.cfg.linkInCodeOrder(falseBlock, trueBlock); - ir.gc.cfg.linkInCodeOrder(trueBlock, restOfBlock); - - // Set up values - OPT_RegisterOperand result = CondMove.getResult(curInstr); - OPT_Operand val1 = CondMove.getVal1(curInstr); - OPT_Operand val2 = CondMove.getVal2(curInstr); - OPT_ConditionOperand cond = CondMove.getCond(curInstr); - OPT_Operand trueValue = CondMove.getTrueValue(curInstr); - OPT_Operand falseValue = CondMove.getFalseValue(curInstr); - - // Create comparison - OPT_Operator cmpType; - if(val1.isInt()){ - cmpType = INT_IFCMP; - } - else if (val1.isDouble()){ - cmpType = DOUBLE_IFCMP; - } - else { - throw new Error("Unexpected type of val1: " + val1); - } - IfCmp.mutate(curInstr, cmpType, null, val1, val2, cond, trueBlock.makeJumpTarget(), OPT_BranchProfileOperand.likely()); - compareBlock.deleteNormalOut(); - compareBlock.insertOut(trueBlock); - compareBlock.insertOut(falseBlock); - - // Create false code - falseBlock.appendInstruction(Move.create(INT_MOVE, result, falseValue)); - falseBlock.appendInstruction(Goto.create(GOTO,restOfBlock.makeJumpTarget())); - falseBlock.insertOut(restOfBlock); - - // Create true code - trueBlock.appendInstruction(Move.create(INT_MOVE, result, trueValue)); - trueBlock.insertOut(restOfBlock); - - // Move along - curBB = restOfBlock; - curInstr = curBB.firstInstruction(); - } - curInstr = curInstr.nextInstructionInCodeOrder(); - } - curBB = curBB.nextBasicBlockInCodeOrder(); - } - } } Modified: src/org/binarytranslator/generic/os/process/ProcessSpace.java =================================================================== --- src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-03-16 23:59:58 UTC (rev 3) +++ src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-03-18 22:49:42 UTC (rev 4) @@ -284,7 +284,7 @@ * system) */ public synchronized void replaceCompiledTrace(VM_CompiledMethod cm, DBT_Trace trace) { - VM_CodeArray code = cm.getInstructions(); + VM_CodeArray code = cm.getEntryCodeArray(); codeHash.put(new Integer(trace.pc), code); } @@ -304,7 +304,7 @@ trace.compile(); VM_CompiledMethod cm = trace.getCurrentCompiledMethod(); replaceCompiledTrace(cm, trace); - return cm.getInstructions(); + return cm.getEntryCodeArray(); } /** Modified: src/org/binarytranslator/vmInterface/DBT_ConvertBinaryToHIR.java =================================================================== --- src/org/binarytranslator/vmInterface/DBT_ConvertBinaryToHIR.java 2007-03-16 23:59:58 UTC (rev 3) +++ src/org/binarytranslator/vmInterface/DBT_ConvertBinaryToHIR.java 2007-03-18 22:49:42 UTC (rev 4) @@ -9,11 +9,27 @@ package org.binarytranslator.vmInterface; import org.binarytranslator.generic.decoder.DecoderUtils; import org.jikesrvm.opt.OPT_CompilerPhase; -import org.jikesrvm.opt.ir.OPT_IR; +import org.jikesrvm.VM_Configuration; + +import org.jikesrvm.opt.ir.OPT_BasicBlock; import org.jikesrvm.opt.ir.OPT_GenerationContext; import org.jikesrvm.opt.ir.OPT_HIRInfo; -import org.jikesrvm.VM_Configuration; +import org.jikesrvm.opt.ir.OPT_IR; +import org.jikesrvm.opt.ir.OPT_Instruction; +import static org.jikesrvm.opt.ir.OPT_Operators.*; +import org.jikesrvm.opt.ir.OPT_Operator; +import org.jikesrvm.opt.ir.BBend; +import org.jikesrvm.opt.ir.CondMove; +import org.jikesrvm.opt.ir.Goto; +import org.jikesrvm.opt.ir.IfCmp; +import org.jikesrvm.opt.ir.Move; + +import org.jikesrvm.opt.ir.OPT_Operand; +import org.jikesrvm.opt.ir.OPT_BranchProfileOperand; +import org.jikesrvm.opt.ir.OPT_ConditionOperand; +import org.jikesrvm.opt.ir.OPT_RegisterOperand; + /** * The OPT_CompilerPhase which translates from PowerPC machine code * into HIR. It is used in PPC_OptimizationPlanner (in place of @@ -61,10 +77,76 @@ } if (VM_Configuration.BuildForPowerPC) { - DecoderUtils.eliminateConditionalMoves(ir); + eliminateConditionalMoves(ir); } } protected abstract void generateHIR(OPT_GenerationContext gc); - protected abstract void eliminateConditionalMoves(OPT_IR ir); + + /** + * Remove conditional moves + */ + public static void eliminateConditionalMoves(OPT_IR ir) { + OPT_BasicBlock curBB = ir.gc.prologue; + while(curBB != null) { + OPT_Instruction curInstr = curBB.firstInstruction(); + loop_over_instructions: + while(BBend.conforms(curInstr) == false) { + if(CondMove.conforms(curInstr) && (curInstr.operator() == INT_COND_MOVE)) { + OPT_BasicBlock compareBlock; // block containing compare instruction + OPT_BasicBlock trueBlock; // block containing true payload + OPT_BasicBlock falseBlock; // block containing false payload + OPT_BasicBlock restOfBlock; // the rest of the block + + // Set up blocks + compareBlock = curBB; + trueBlock = new OPT_BasicBlock(0, ir.gc.inlineSequence, ir.gc.cfg); + falseBlock = new OPT_BasicBlock(0, ir.gc.inlineSequence, ir.gc.cfg); + restOfBlock = compareBlock.splitNodeAt(curInstr, ir); + ir.gc.cfg.linkInCodeOrder(compareBlock, falseBlock); + ir.gc.cfg.linkInCodeOrder(falseBlock, trueBlock); + ir.gc.cfg.linkInCodeOrder(trueBlock, restOfBlock); + + // Set up values + OPT_RegisterOperand result = CondMove.getResult(curInstr); + OPT_Operand val1 = CondMove.getVal1(curInstr); + OPT_Operand val2 = CondMove.getVal2(curInstr); + OPT_ConditionOperand cond = CondMove.getCond(curInstr); + OPT_Operand trueValue = CondMove.getTrueValue(curInstr); + OPT_Operand falseValue = CondMove.getFalseValue(curInstr); + + // Create comparison + OPT_Operator cmpType; + if(val1.isInt()){ + cmpType = INT_IFCMP; + } + else if (val1.isDouble()){ + cmpType = DOUBLE_IFCMP; + } + else { + throw new Error("Unexpected type of val1: " + val1); + } + IfCmp.mutate(curInstr, cmpType, null, val1, val2, cond, trueBlock.makeJumpTarget(), OPT_BranchProfileOperand.likely()); + compareBlock.deleteNormalOut(); + compareBlock.insertOut(trueBlock); + compareBlock.insertOut(falseBlock); + + // Create false code + falseBlock.appendInstruction(Move.create(INT_MOVE, result, falseValue)); + falseBlock.appendInstruction(Goto.create(GOTO,restOfBlock.makeJumpTarget())); + falseBlock.insertOut(restOfBlock); + + // Create true code + trueBlock.appendInstruction(Move.create(INT_MOVE, result, trueValue)); + trueBlock.insertOut(restOfBlock); + + // Move along + curBB = restOfBlock; + curInstr = curBB.firstInstruction(); + } + curInstr = curInstr.nextInstructionInCodeOrder(); + } + curBB = curBB.nextBasicBlockInCodeOrder(); + } + } } Modified: src/org/binarytranslator/vmInterface/DBT_Trace.java =================================================================== --- src/org/binarytranslator/vmInterface/DBT_Trace.java 2007-03-16 23:59:58 UTC (rev 3) +++ src/org/binarytranslator/vmInterface/DBT_Trace.java 2007-03-18 22:49:42 UTC (rev 4) @@ -67,7 +67,7 @@ */ private static VM_Class dummyRunner; private static VM_NormalMethod invokeCode; - private static int invokeCode_modifiers; + private static short invokeCode_modifiers; private static VM_TypeReference dummyRunnerTypeRef; private static VM_MemberReference dummyRunnerMemRef; private static VM_Atom invokeCodeDescriptor; @@ -125,14 +125,14 @@ invokeCode.getOperandWords(), invokeCode.bytecodes, invokeCode.getExceptionHandlerMap(), - new int[0], null, null, null, null, null, null, null); + new int[0], null, null, null, null, null); - this.offset = VM_Statics.allocateSlot(VM_Statics.METHOD) << LOG_BYTES_IN_INT; + this.offset = invokeCode.getOffset().toInt(); - this.summary |= HAS_ALLOCATION | HAS_THROW | HAS_INVOKE | - HAS_FIELD_READ | HAS_FIELD_WRITE | HAS_ARRAY_READ | HAS_ARRAY_WRITE | - HAS_COND_BRANCH | HAS_SWITCH | HAS_BACK_BRANCH | - 256; + this.summaryFlags |= HAS_ALLOCATION | HAS_THROW | HAS_INVOKE | + HAS_FIELD_READ | HAS_FIELD_WRITE | HAS_ARRAY_READ | HAS_ARRAY_WRITE | + HAS_COND_BRANCH | HAS_SWITCH | HAS_BACK_BRANCH; + this.summarySize = 256; this.ps = ps; pc = startPC; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cap...@us...> - 2007-03-18 13:35:14
|
Revision: 3 http://svn.sourceforge.net/pearcolator/?rev=3&view=rev Author: captain5050 Date: 2007-03-16 16:59:58 -0700 (Fri, 16 Mar 2007) Log Message: ----------- New build file. More fixed for new build system Modified Paths: -------------- src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java src/org/binarytranslator/arch/x86/os/process/X86_Registers.java src/org/binarytranslator/generic/os/abi/linux/LinuxStackInitializer.java src/org/binarytranslator/generic/os/process/ProcessSpace.java src/org/binarytranslator/vmInterface/DBT_ConvertBinaryToHIR.java src/org/binarytranslator/vmInterface/DBT_Trace.java src/org/binarytranslator/vmInterface/DynamicCodeRunner.java Added Paths: ----------- build.xml ext/org/jikesrvm/ppc/ ext/org/jikesrvm/ppc/PPC_Disassembler.java ext/org/jikesrvm/ppc/opcodeXX.java ext/org/jikesrvm/ppc/opcode_tab.java Added: build.xml =================================================================== --- build.xml (rev 0) +++ build.xml 2007-03-16 23:59:58 UTC (rev 3) @@ -0,0 +1,30 @@ +<project name="binarytranslator.org" default="compile" basedir="../.."> + <property name="dbt.java" location="projects/dbt/src"/> + <property name="dbt-ext.java" location="projects/dbt/ext"/> + <target name="compile" depends="compile-external"> + <javac destdir="${build.classes}" + debug="true" + debugLevel="lines,source" + source="1.5" + target="1.5" + srcdir="${dbt.java}"> + <classpath> + <pathelement location="${build.vmmagic-stub.classes}"/> + <pathelement location="${build.classes}"/> + </classpath> + </javac> + </target> + <target name="compile-external"> + <javac destdir="${build.classes}" + debug="true" + debugLevel="lines,source" + source="1.5" + target="1.5" + srcdir="${dbt-ext.java}"> + <classpath> + <pathelement location="${build.vmmagic-stub.classes}"/> + <pathelement location="${build.classes}"/> + </classpath> + </javac> + </target> +</project> \ No newline at end of file Added: ext/org/jikesrvm/ppc/PPC_Disassembler.java =================================================================== --- ext/org/jikesrvm/ppc/PPC_Disassembler.java (rev 0) +++ ext/org/jikesrvm/ppc/PPC_Disassembler.java 2007-03-16 23:59:58 UTC (rev 3) @@ -0,0 +1,1656 @@ +/* + * This file is part of Jikes RVM (http://jikesrvm.sourceforge.net). + * The Jikes RVM 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 IBM Corp. 2001 + */ +package org.jikesrvm.ppc; + +/** + * Disassembler for Rios instruction set. + * @author Ton Ngo + * + * Defined: disasm(inst, addr, buf, reg) + * INSTRUCTION inst; Address addr; CHAR *buf; CHAR reg[4][10]; + * + * 31 Jul 1990 Derek Lieber. + * Borrowed from libdbx (opcode.c, decode.c). + * + * 30 Jan 1998 Ton Ngo: + * adapted for Java debugger jdp + * + * 7 Aug 1998 John Whaley: + * rewritten in Java + * + * 26 Jan 1999 Ton Ngo: + * New instruction for PowerPC that are not in the POWER instruction set + * opcode is bit 0-5 of the instruction + * extop is the extended opcode as listed in the manual + * key is extop plus additional bits for variation on an opcode (. or o) + * form is the instruction format: I, B, SC, D, DS, X, XL, XFX, XFL, XO, A, M + * format is a local enumeration to specify how to print the instruction + * (this is specific to each decode_?? method). + * + * 18 Dec 2000 Dave Grove: + * Changed the mnemonics for POWER instructions that have + * different names on the PowerPC to use the PowerPC mnemonic. + * (Applied changes from Appendix F of PPC Architecture book). + * + * mnemonic opcode extop key form format Example + * -------- ------ --- --- ---- ------ -------- + * dcbf 31 86 172 X 6 7C0218AC + * dcbi 31 470 940 X 6 7C021BAC + * dcbst 31 54 108 X 6 7C02186C + * dcbt 31 278 556 X 6 7C021A2C + * dcbtst 31 246 492 X 6 7C0219EC + * dcbz 31 1014 2028 X 6 7C021FEC + * divw 31 491 982 XO 1 7C221BD6 + * divw. 31 491 983 XO 1 7C221BD7 + * divwo 31 491 2006 XO 1 7C221FD6 + * divwo. 31 491 2007 XO 1 7C221FD7 + * divwu 31 459 918 XO 1 7C221B96 + * divwu. 31 459 919 XO 1 7C221B97 + * divwuo 31 459 1942 XO 1 7C221F96 + * divwuo. 31 459 1943 XO 1 7C221F97 + * eieio 31 854 1708 X 1 7C0006AC + * extsb 31 954 1908 X 0 7C220774 + * extsb. 31 954 1909 X 0 7C220775 + * icbi 31 982 1964 X 6 7C021FAC + * lwarx 31 20 40 X 7 7C221828 + * mfsrin 31 659 1318 X 4 7C201526 + * mulhw 31 75 150 XO 1 7C221896 + * mulhw. 31 75 151 XO 1 7C221897 + * mulhwu 31 11 22 XO 1 7C221816 + * mulhwu. 31 11 23 XO 1 7C221817 + * stwcx. 31 150 301 X 7 7C22192D + * subf 31 40 80 XO 1 7C221850 + * subf. 31 40 81 XO 1 7C221851 + * subfo 31 40 1104 XO 1 7C221C50 + * subfo. 31 40 1105 XO 1 7C221C51 + * + * fadds 59 21 42 A 0 EC22182A + * fadds. 59 21 43 A 0 EC22182B + * fdivs 59 18 36 A 0 EC221824 + * fdivs. 59 18 37 A 0 EC221825 + * fmadds 59 29 58 A 2 EC22193A + * fmadds. 59 29 59 A 2 EC22193B + * fmsubs 59 28 56 A 2 EC221938 + * fmsubs. 59 28 57 A 2 EC221939 + * fmuls 59 25 50 A 1 EC2200F2 + * fmuls. 59 25 51 A 1 EC2200F3 + * fnmadds 59 31 62 A 2 EC22193E + * fnmadds. 59 31 63 A 2 EC22193F + * fnmsubs 59 30 60 A 2 EC22193C + * fnmsubs. 59 30 61 A 2 EC22193D + * fsubs 59 20 40 A 0 EC221828 + * fsubs. 59 20 41 A 0 EC221829 + * mfear + * mfpvw + * mfsprg + * mtear + * mtsprg + * mfdbatl + * mfdbatu + * mtdbatl + * mtdbatu + * mttb + * mttbu + * mftb + * mftbu + * mfibatl + * mfibatu + * mtibatl + * mtibatu + * + * 23 Apr 2003 Kris Venstermans: + * Added instruction decoding for 64 bit architecture. + * Use of constant definitions instead of integers. + * Cleaned up some old power instructions. + */ + +public class PPC_Disassembler { + // special register name copied from /usr/include/sys/reg.h + static final int IAR = 128; + static final int MSR = 129; + static final int CR = 130; + static final int LR = 131; + static final int CTR = 132; + static final int XER = 133; + static final int MQ = 134; + static final int TID = 135; + static final int FPSCR = 136; + static final int FPINFO = 138; + static final int FPSCRX = 148; + static final String GPR_NAMES[] = { "R0", "R1", "R2", "R3", "R4", "R5", + "R6", "R7","R8", "R9", "R10", "R11", + "R12", "R13","R14", "R15","R16", "R17", + "R18", "R19", "R20", "R21", "R22", "R23", + "R24", "R25", "R26", "R27", "R28", "R29", "R30", "R31" + }; + static final String FPR_NAMES[] = { "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7", + "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", + "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23", + "F24", "F25", "F26", "F27", "F28", "F29", "F30", "F31" + }; + + // for testing purposes + public static void main(String[] args) { + + int instr = Integer.parseInt(args[0],16); + int addr = Integer.parseInt(args[1],16); + System.out.println("instr = "+intAsHexString(instr)+" addr = "+ + intAsHexString(addr)); + System.out.println("result --> "+disasm(instr, addr)); + + } + + static int bits (int x, int n, int m) { + return ((x >> (31-m)) & ((1 << (m-n+1)) - 1)); + } + + static int signed (int x, int n, int m) { + return ((x << n) >> 31-m+n); + } + + static String rname(int n) { + String rvmName; + if (n>=0 && n<=31) + rvmName = GPR_NAMES[n]; + else if (n>=128 && n<=135) + rvmName = FPR_NAMES[n-128]; + else + switch (n) { + case IAR: rvmName = "IAR"; break; + case MSR: rvmName = "MSR"; break; + case CR: rvmName = "CR"; break; + case LR: rvmName = "LR"; break; + case CTR: rvmName = "CTR"; break; + case XER: rvmName = "XER"; break; + case MQ: rvmName = "MQ"; break; + case TID: rvmName = "TID"; break; + case FPSCR: rvmName = "FPSCR"; break; + case FPINFO: rvmName = "FPINFO"; break; + case FPSCRX: rvmName = "FPSCRX"; break; + default: rvmName = "r" + n; break; + } + return rvmName; + } + + + static final int INST_SZ = 4; + + /* Special register fields */ + static final int SPR_MQ = 0; + static final int SPR_XER = 1; + static final int SPR_LR = 8; + static final int SPR_CTR = 9; + static final int SPR_TID = 17; + static final int SPR_DSISR= 18; + static final int SPR_DAR = 19; + static final int SPR_RTCU = 20; + static final int SPR_RTCL = 21; + static final int SPR_DEC = 22; + static final int SPR_SDR0 = 24; + static final int SPR_SDR1 = 25; + static final int SPR_SRR0 = 26; + static final int SPR_SRR1 = 27; + + /* Trap Options */ + static final int TO_LT=16; + static final int TO_GT= 8; + static final int TO_EQ= 4; + static final int TO_LLT= 2; + static final int TO_LGT= 1; + + /* Different instruction formats */ + + static final int D_FORM = 0; + static final int B_FORM = 1; + static final int I_FORM= 2; + static final int SC_FORM = 3; + static final int X_FORM = 4; + static final int XL_FORM = 5; + static final int XFX_FORM = 6; + static final int XFL_FORM = 7; + static final int XO_FORM = 8; + static final int A_FORM = 9; + static final int M_FORM =10; + static final int DS_FORM =30; + static final int XS_FORM =31; + static final int MD_FORM =32; + static final int MDS_FORM =33; + + static final int EXTENDED =11; + static final int INVALID_OP=12; + + /* Condition register fields */ + static final int CR_LT=8; + static final int CR_GT=4; + static final int CR_EQ=2; + static final int CR_SO=1; + + static final int X=9; // place holder + + /* + * Instruction decoder. + */ + static int destination; + + static int[] opcode_to_form = { + /* table to convert opcode into */ + /* instruction formats */ + + /* FORM */ + INVALID_OP, /* OPCODE 00 */ + INVALID_OP, /* OPCODE 01 */ + D_FORM, /* OPCODE 02 */ + D_FORM, /* OPCODE 03 */ + D_FORM, /* OPCODE 04 */ + D_FORM, /* OPCODE 05 */ + D_FORM, /* OPCODE 06 */ + D_FORM, /* OPCODE 07 */ + D_FORM, /* OPCODE 08 */ + D_FORM, /* OPCODE 09 */ + D_FORM, /* OPCODE 10 */ + D_FORM, /* OPCODE 11 */ + D_FORM, /* OPCODE 12 */ + D_FORM, /* OPCODE 13 */ + D_FORM, /* OPCODE 14 */ + D_FORM, /* OPCODE 15 */ + B_FORM, /* OPCODE 16 */ + SC_FORM, /* OPCODE 17 */ + I_FORM, /* OPCODE 18 */ + XL_FORM, /* OPCODE 19 */ + M_FORM, /* OPCODE 20 */ + M_FORM, /* OPCODE 21 */ + M_FORM, /* OPCODE 22 */ + M_FORM, /* OPCODE 23 */ + D_FORM, /* OPCODE 24 */ + D_FORM, /* OPCODE 25 */ + D_FORM, /* OPCODE 26 */ + D_FORM, /* OPCODE 27 */ + D_FORM, /* OPCODE 28 */ + D_FORM, /* OPCODE 29 */ + EXTENDED, /* OPCODE 30 */ + EXTENDED, /* OPCODE 31 */ + D_FORM, /* OPCODE 32 */ + D_FORM, /* OPCODE 33 */ + D_FORM, /* OPCODE 34 */ + D_FORM, /* OPCODE 35 */ + D_FORM, /* OPCODE 36 */ + D_FORM, /* OPCODE 37 */ + D_FORM, /* OPCODE 38 */ + D_FORM, /* OPCODE 39 */ + D_FORM, /* OPCODE 40 */ + D_FORM, /* OPCODE 41 */ + D_FORM, /* OPCODE 42 */ + D_FORM, /* OPCODE 43 */ + D_FORM, /* OPCODE 44 */ + D_FORM, /* OPCODE 45 */ + D_FORM, /* OPCODE 46 */ + D_FORM, /* OPCODE 47 */ + D_FORM, /* OPCODE 48 */ + D_FORM, /* OPCODE 49 */ + D_FORM, /* OPCODE 50 */ + D_FORM, /* OPCODE 51 */ + D_FORM, /* OPCODE 52 */ + D_FORM, /* OPCODE 53 */ + D_FORM, /* OPCODE 54 */ + D_FORM, /* OPCODE 55 */ + INVALID_OP, /* OPCODE 56 */ + INVALID_OP, /* OPCODE 57 */ + DS_FORM, /* OPCODE 58 */ + A_FORM, /* OPCODE 59 */ + INVALID_OP, /* OPCODE 60 */ + INVALID_OP, /* OPCODE 61 */ + DS_FORM, /* OPCODE 62 */ + EXTENDED /* OPCODE 63 */ + }; + + static opcode_tab[] Dform = { + + /* Table for the D instruction format */ + + /* OPCD EO format mnemonic */ + /* ---- -- ------ -------- */ + /* 0, XXX, */ new opcode_tab ( X, "RESERVED"), + /* 1, XXX, */ new opcode_tab ( X, "RESERVED"), + /* 2, XXX, */ new opcode_tab ( 3, "tdi"), + /* 3, XXX, */ new opcode_tab ( 3, "twi" ), + /* 4, XXX, */ new opcode_tab ( X, "RESERVED"), + + /* 5, XXX, */ new opcode_tab ( X, "RESERVED"), + /* 6, XXX, */ new opcode_tab ( X, "RESERVED"), + /* 7, XXX, */ new opcode_tab ( 0, "mulli" ), + /* 8, XXX, */ new opcode_tab ( 0, "subfic" ), + /* 9, XXX, */ new opcode_tab ( X, "RESERVED"), + + /* 10, XXX, */ new opcode_tab ( 4, "cmpli" ), + /* 11, XXX, */ new opcode_tab ( 4, "cmpi" ), + /* 12, XXX, */ new opcode_tab ( 0, "addic" ), + /* 13, XXX, */ new opcode_tab ( 0, "addic." ), + /* 14, XXX, */ new opcode_tab ( 2, "addi" ), + + /* 15, XXX, */ new opcode_tab ( 0, "addis" ), + /* 16, XXX, */ new opcode_tab ( X, "RESERVED"), + /* 17, XXX, */ new opcode_tab ( X, "RESERVED"), + /* 18, XXX, */ new opcode_tab ( X, "RESERVED"), + /* 19, XXX, */ new opcode_tab ( X, "RESERVED"), + + /* 20, XXX, */ new opcode_tab ( X, "RESERVED"), + /* 21, XXX, */ new opcode_tab ( X, "RESERVED"), + /* 22, XXX, */ new opcode_tab ( X, "RESERVED"), + /* 23, XXX, */ new opcode_tab ( X, "RESERVED"), + /* 24, XXX, */ new opcode_tab ( 1, "ori" ), + + /* 25, XXX, */ new opcode_tab ( 1, "oris" ), + /* 26, XXX, */ new opcode_tab ( 1, "xori" ), + /* 27, XXX, */ new opcode_tab ( 1, "xoris" ), + /* 28, XXX, */ new opcode_tab ( 1, "andi. " ), + /* 29, XXX, */ new opcode_tab ( 1, "andis." ), + + /* 30, XXX, */ new opcode_tab ( X, "RESERVED"), + /* 31, XXX, */ new opcode_tab ( X, "RESERVED"), + /* 32, XXX, */ new opcode_tab ( 2, "lwz" ), + /* 33, XXX, */ new opcode_tab ( 2, "lwzu" ), + /* 34, XXX, */ new opcode_tab ( 2, "lbz" ), + + /* 35, XXX, */ new opcode_tab ( 2, "lbzu" ), + /* 36, XXX, */ new opcode_tab ( 2, "stw" ), + /* 37, XXX, */ new opcode_tab ( 2, "stwu" ), + /* 38, XXX, */ new opcode_tab ( 2, "stb" ), + /* 39, XXX, */ new opcode_tab ( 2, "stbu" ), + + /* 40, XXX, */ new opcode_tab ( 2, "lhz" ), + /* 41, XXX, */ new opcode_tab ( 2, "lhzu" ), + /* 42, XXX, */ new opcode_tab ( 2, "lha" ), + /* 43, XXX, */ new opcode_tab ( 2, "lhau" ), + /* 44, XXX, */ new opcode_tab ( 2, "sth" ), + + /* 45, XXX, */ new opcode_tab ( 2, "sthu" ), + /* 46, XXX, */ new opcode_tab ( 2, "lmw" ), + /* 47, XXX, */ new opcode_tab ( 2, "stmw" ), + /* 48, XXX, */ new opcode_tab ( 5, "lfs" ), + /* 49, XXX, */ new opcode_tab ( 5, "lfsu" ), + + /* 50, XXX, */ new opcode_tab ( 5, "lfd" ), + /* 51, XXX, */ new opcode_tab ( 5, "lfdu" ), + /* 52, XXX, */ new opcode_tab ( 5, "stfs" ), + /* 53, XXX, */ new opcode_tab ( 5, "stfsu" ), + /* 54, XXX, */ new opcode_tab ( 5, "stfd" ), + + /* 55, XXX, */ new opcode_tab ( 5, "stfdu" ) + }; + + + static opcode_tab[] XLform = { + + /* Table for the XL instruction format */ + + /* OPCD EO format mnemonic */ + /* ---- -- ------ -------- */ + /* 19, 0, */ new opcode_tab( 2, "mcrf" ), + /* 19, 16, */ new opcode_tab( 1, "bclr or bclrl"), + /* 19, 33, */ new opcode_tab( 3, "crnor" ), + /* 19, 50, */ new opcode_tab( 0, "rfi" ), + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, 129, */ new opcode_tab( 3, "crandc" ), + /* 19, 150, */ new opcode_tab( 0, "isync" ), + + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, 193, */ new opcode_tab( 3, "crxor" ), + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, 225, */ new opcode_tab( 3, "crnand" ), + + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, 257, */ new opcode_tab( 3, "crand" ), + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, 289, */ new opcode_tab( 3, "creqv" ), + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, 417, */ new opcode_tab( 3, "crorc" ), + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, 449, */ new opcode_tab( 3, "cror" ), + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, XXX, */ new opcode_tab( X, "RESERVED" ), + /* 19, 528, */ new opcode_tab( 1, "bcctr or bcctrl") + }; + + + + /** + * Opcode 30 table: + * The key is bits 27 through 30 of the instruction. + * "Form" is the instruction format: + * I, B, SC, D, DS, X, XL, XFX, XFL, XO, A, M, MDS, MD + * "format" is how the instruction should be printed (specific to the disassembler) + */ + + static opcodeXX[] opcode30 = { + + /* key form format mnemonic */ + /* --- ---- ------ -------- */ + new opcodeXX( 0, MD_FORM, 0, "rldicl" ), + new opcodeXX( 1, MD_FORM, 0, "rldicl" ), + new opcodeXX( 2, MD_FORM, 1, "rldicr" ), + new opcodeXX( 3, MD_FORM, 1, "rldicr" ), + new opcodeXX( 4, MD_FORM, 0, "rldic" ), + new opcodeXX( 5, MD_FORM, 0, "rldic" ), + new opcodeXX( 6, MD_FORM, 0, "rldimi" ), + new opcodeXX( 7, MD_FORM, 0, "rldimi" ), + new opcodeXX( 8, MDS_FORM, 0, "rldcl" ), + new opcodeXX( 9, MDS_FORM, 1, "rldcr" ) + }; + + + /** + * Opcode 31 table: + * The key is bits 21 through 31 of the instruction. + * "Form" is the instruction format: + * I, B, SC, D, DS, X, XL, XFX, XFL, XO, A, M + * "format" is how the instruction should be printed (specific to the disassembler) + */ + + + static opcodeXX[] opcode31 = { + + /* key form format mnemonic */ + /* --- ---- ------ -------- */ + new opcodeXX( 0, X_FORM, 22, "cmp"), + new opcodeXX( 8, X_FORM, 24, "tw"), + new opcodeXX( 16, XO_FORM, 1, "subfc"), + new opcodeXX( 17, XO_FORM, 1, "subfc."), + new opcodeXX( 20, XO_FORM, 1, "addc"), + new opcodeXX( 21, XO_FORM, 1, "addc."), + new opcodeXX( 38, X_FORM, 2, "mfcr"), + new opcodeXX( 46, X_FORM, 7, "lwzx"), + new opcodeXX( 48, X_FORM, 8, "slw"), + new opcodeXX( 49, X_FORM, 8, "slw."), + new opcodeXX( 52, X_FORM, 9, "cntlzw"), + new opcodeXX( 53, X_FORM, 9, "cntlzw."), + new opcodeXX( 56, X_FORM, 8, "and"), + new opcodeXX( 57, X_FORM, 8, "and."), + new opcodeXX( 64, X_FORM, 22, "cmpl"), + new opcodeXX( 110, X_FORM, 7, "lwzux"), + new opcodeXX( 120, X_FORM, 8, "andc"), + new opcodeXX( 121, X_FORM, 8, "andc."), + new opcodeXX( 166, X_FORM, 2, "mfmsr"), + new opcodeXX( 174, X_FORM, 7, "lbzx"), + new opcodeXX( 208, XO_FORM, 0, "neg"), + new opcodeXX( 209, XO_FORM, 0, "neg."), + new opcodeXX( 238, X_FORM, 7, "lbzux"), + new opcodeXX( 248, X_FORM, 8, "nor"), + new opcodeXX( 249, X_FORM, 8, "nor."), + new opcodeXX( 272, XO_FORM, 1, "subfe"), + new opcodeXX( 273, XO_FORM, 1, "subfe."), + new opcodeXX( 276, XO_FORM, 1, "adde"), + new opcodeXX( 277, XO_FORM, 1, "adde."), + new opcodeXX( 288, XFX_FORM, 9, "mtcrf"), + new opcodeXX( 292, X_FORM, 2, "mtmsr"), + new opcodeXX( 302, X_FORM, 7, "stwx"), + new opcodeXX( 366, X_FORM, 7, "stwux"), + new opcodeXX( 400, XO_FORM, 0, "subfze"), + new opcodeXX( 401, XO_FORM, 0, "subfze."), + new opcodeXX( 404, XO_FORM, 0, "addze"), + new opcodeXX( 405, XO_FORM, 0, "addze."), + new opcodeXX( 430, X_FORM, 7, "stbx"), + new opcodeXX( 464, XO_FORM, 0, "subfme"), + new opcodeXX( 465, XO_FORM, 0, "subfme."), + new opcodeXX( 468, XO_FORM, 0, "addme"), + new opcodeXX( 469, XO_FORM, 0, "addme."), + new opcodeXX( 470, XO_FORM, 1, "mullw"), + new opcodeXX( 471, XO_FORM, 1, "mullw."), + new opcodeXX( 494, X_FORM, 7, "stbux"), + new opcodeXX( 532, XO_FORM, 1, "add"), + new opcodeXX( 533, XO_FORM, 1, "add."), + new opcodeXX( 558, X_FORM, 7, "lhzx"), + new opcodeXX( 568, X_FORM, 8, "eqv"), + new opcodeXX( 569, X_FORM, 8, "eqv."), + new opcodeXX( 612, X_FORM, 6, "tlbie"), + new opcodeXX( 622, X_FORM, 7, "lhzux"), + new opcodeXX( 632, X_FORM, 8, "xor"), + new opcodeXX( 633, X_FORM, 8, "xor."), + new opcodeXX( 678, X_FORM, 3, "mfspr"), + new opcodeXX( 686, X_FORM, 7, "lhax"), + new opcodeXX( 750, X_FORM, 7, "lhaux"), + new opcodeXX( 814, X_FORM, 7, "sthx"), + new opcodeXX( 824, X_FORM, 8, "orc"), + new opcodeXX( 825, X_FORM, 8, "orc."), + new opcodeXX( 878, X_FORM, 7, "sthux"), + new opcodeXX( 888, X_FORM, 8, "or"), + new opcodeXX( 889, X_FORM, 8, "or."), + new opcodeXX( 934, X_FORM, 3, "mtspr"), + new opcodeXX( 952, X_FORM, 8, "nand"), + new opcodeXX( 953, X_FORM, 8, "nand."), + new opcodeXX( 1024, X_FORM, 23, "mcrxr"), + new opcodeXX( 1040, XO_FORM, 1, "subfco"), + new opcodeXX( 1041, XO_FORM, 1, "subfco."), + new opcodeXX( 1044, XO_FORM, 1, "addco"), + new opcodeXX( 1045, XO_FORM, 1, "addco."), + new opcodeXX( 1066, X_FORM, 7, "lswx"), + new opcodeXX( 1068, X_FORM, 7, "lwbrx"), + new opcodeXX( 1070, X_FORM, 12, "lfsx"), + new opcodeXX( 1072, X_FORM, 8, "srw"), + new opcodeXX( 1073, X_FORM, 8, "srw."), + new opcodeXX( 1134, X_FORM, 12, "lfsux"), + new opcodeXX( 1194, X_FORM, 10, "lswi"), + new opcodeXX( 1196, X_FORM, 1, "sync"), + new opcodeXX( 1198, X_FORM, 12, "lfdx"), + new opcodeXX( 1262, X_FORM, 12, "lfdux"), + new opcodeXX( 1232, XO_FORM, 0, "nego"), + new opcodeXX( 1233, XO_FORM, 0, "nego."), + new opcodeXX( 1296, XO_FORM, 1, "subfeo"), + new opcodeXX( 1297, XO_FORM, 1, "subfeo."), + new opcodeXX( 1300, XO_FORM, 1, "addeo"), + new opcodeXX( 1301, XO_FORM, 1, "addeo."), + new opcodeXX( 1322, X_FORM, 7, "stswx"), + new opcodeXX( 1324, X_FORM, 7, "stwbrx"), + new opcodeXX( 1326, X_FORM, 12, "stfsx"), + new opcodeXX( 1390, X_FORM, 12, "stfsux"), + new opcodeXX( 1424, XO_FORM, 0, "subfzeo"), + new opcodeXX( 1425, XO_FORM, 0, "subfzeo."), + new opcodeXX( 1428, XO_FORM, 0, "addzeo."), + new opcodeXX( 1429, XO_FORM, 0, "addzeo."), + new opcodeXX( 1450, X_FORM, 10, "stswi"), + new opcodeXX( 1454, X_FORM, 12, "stfdx"), + new opcodeXX( 1488, XO_FORM, 0, "subfmeo."), + new opcodeXX( 1489, XO_FORM, 0, "subfmeo."), + new opcodeXX( 1492, XO_FORM, 0, "addmeo"), + new opcodeXX( 1493, XO_FORM, 0, "addmeo."), + new opcodeXX( 1494, XO_FORM, 1, "mullwo."), + new opcodeXX( 1495, XO_FORM, 1, "mullwo."), + new opcodeXX( 1518, X_FORM, 12, "stfdux"), + new opcodeXX( 1556, XO_FORM, 1, "addo"), + new opcodeXX( 1557, XO_FORM, 1, "addo."), + new opcodeXX( 1580, X_FORM, 7, "lhbrx"), + new opcodeXX( 1584, X_FORM, 8, "sraw"), + new opcodeXX( 1585, X_FORM, 8, "sraw."), + new opcodeXX( 1648, X_FORM, 11, "srawi"), + new opcodeXX( 1649, X_FORM, 11, "srawi."), + new opcodeXX( 1836, X_FORM, 7, "sthbrx"), + new opcodeXX( 1844, X_FORM, 9, "extsh"), + new opcodeXX( 1845, X_FORM, 9, "extsh."), + new opcodeXX( 2028, X_FORM, 6, "dcbz"), + + // these are the addition for the PowerPC + new opcodeXX( 172, X_FORM, 6, "dcbf"), + new opcodeXX( 940, X_FORM, 6, "dcbi"), + new opcodeXX( 108, X_FORM, 6, "dcbst"), + new opcodeXX( 556, X_FORM, 6, "dcbt"), + new opcodeXX( 492, X_FORM, 6, "dcbtst"), + new opcodeXX( 982, XO_FORM, 1, "divw"), + new opcodeXX( 983, XO_FORM, 1, "divw."), + new opcodeXX( 2006, XO_FORM, 1, "divwo"), + new opcodeXX( 2007, XO_FORM, 1, "divwo."), + new opcodeXX( 918, XO_FORM, 1, "divwu"), + new opcodeXX( 919, XO_FORM, 1, "divwu."), + new opcodeXX( 1942, XO_FORM, 1, "divwuo"), + new opcodeXX( 1943, XO_FORM, 1, "divwuo."), + new opcodeXX( 1708, X_FORM, 1, "eieio"), + new opcodeXX( 1908, X_FORM, 0, "extsb"), + new opcodeXX( 1909, X_FORM, 0, "extsb."), + new opcodeXX( 1964, X_FORM, 6, "icbi"), + new opcodeXX( 40, X_FORM, 7, "lwarx"), + new opcodeXX( 150, XO_FORM, 1, "mulhw"), + new opcodeXX( 151, XO_FORM, 1, "mulhw."), + new opcodeXX( 22, XO_FORM, 1, "mulhwu"), + new opcodeXX( 23, XO_FORM, 1, "mulhwu."), + new opcodeXX( 301, X_FORM, 7, "stwcx."), + new opcodeXX( 80, XO_FORM, 1, "subf"), + new opcodeXX( 81, XO_FORM, 1, "subf."), + new opcodeXX( 1104, XO_FORM, 1, "subfo"), + new opcodeXX( 1105, XO_FORM, 1, "subfo."), + +// these are only valid for 32 bit architecture + new opcodeXX( 420, X_FORM, 17, "mtsr"), + new opcodeXX( 484, X_FORM, 7, "mtsrin"), + new opcodeXX( 1190, X_FORM, 18, "mfsr"), + new opcodeXX( 1318, X_FORM, 4, "mfsrin"), + +// these are the addition for the 64 bit specific instructions + new opcodeXX( 18, XO_FORM, 2, "mulhdu"), + new opcodeXX( 19, XO_FORM, 2, "mulhdu."), + new opcodeXX( 42, X_FORM, 7, "ldx"), + new opcodeXX( 43, X_FORM, 7, "ldx."), + new opcodeXX( 54, X_FORM, 8, "sld"), + new opcodeXX( 55, X_FORM, 8, "sld."), + new opcodeXX( 106, X_FORM, 7, "ldux"), + new opcodeXX( 107, X_FORM, 7, "ldux."), + new opcodeXX( 116, X_FORM, 9, "cntlzd"), + new opcodeXX( 117, X_FORM, 9, "cntlzd."), + new opcodeXX( 136, X_FORM, 24, "td"), + new opcodeXX( 146, XO_FORM, 1, "mulhd"), + new opcodeXX( 151, XO_FORM, 1, "mulhd."), + new opcodeXX( 168, X_FORM, 7, "ldarx"), + new opcodeXX( 298, X_FORM, 7, "stdx"), + new opcodeXX( 362, X_FORM, 7, "stdux"), + new opcodeXX( 429, X_FORM, 7, "stdcx."), + new opcodeXX( 466, XO_FORM, 1, "mulld"), + new opcodeXX( 467, XO_FORM, 1, "mulld."), + new opcodeXX( 682, X_FORM, 7, "lwax"), + new opcodeXX( 746, X_FORM, 7, "lwaux"), + new opcodeXX( 1652, XS_FORM, 0, "sradi"), + new opcodeXX( 1653, XS_FORM, 0, "sradi."), + new opcodeXX( 1654, XS_FORM, 0, "sradi"), + new opcodeXX( 1655, XS_FORM, 0, "sradi."), + new opcodeXX( 868, X_FORM, 6, "slbie"), + new opcodeXX( 914, XO_FORM, 1, "divdu"), + new opcodeXX( 915, XO_FORM, 1, "divdu."), + new opcodeXX( 978, XO_FORM, 1, "divd"), + new opcodeXX( 979, XO_FORM, 1, "divd."), + new opcodeXX( 996, X_FORM, 1, "slbia"), + new opcodeXX( 1078, X_FORM, 8, "srd"), + new opcodeXX( 1079, X_FORM, 8, "srd."), + new opcodeXX( 1588, X_FORM, 8, "srad"), + new opcodeXX( 1589, X_FORM, 8, "srad."), + new opcodeXX( 1972, X_FORM, 9, "extsw"), + new opcodeXX( 1973, X_FORM, 9, "extsw.") + }; + + static opcode_tab[] opcode58 = { + /* Table for the instruction format of opcode 58*/ + + /* EO format mnemonic */ + /* ---- ------ -------- */ + /* 0, */ new opcode_tab ( 0, "ld"), + /* 1, */ new opcode_tab ( 0, "ldu"), + /* 2, */ new opcode_tab ( 0, "lwa"), + /* 3, */ new opcode_tab ( X, "RESERVED") + }; + + static opcode_tab[] opcode62 = { + /* Table for the instruction format of opcode 58*/ + + /* EO format mnemonic */ + /* ---- ------ -------- */ + /* 0, */ new opcode_tab ( 1, "std"), + /* 1, */ new opcode_tab ( 1, "stdu"), + /* 2, */ new opcode_tab ( X, "RESERVED"), + /* 3, */ new opcode_tab ( X, "RESERVED") + }; + +/* Opcode 63 table: The key is computed by taking + * bits 21 through 31 of the instruction. "Form" is + * the instruction format and "format" is how the + * instruction should be printed. */ + + static opcodeXX[] opcode63 = { + + /* key form format mnemonic */ + /* --- ---- ------ -------- */ + new opcodeXX( 0, X_FORM, 19, "fcmpu"), + new opcodeXX( 24, X_FORM, 21, "frsp"), + new opcodeXX( 25, X_FORM, 21, "frsp."), + new opcodeXX( 28, X_FORM, 21, "fctiw"), + new opcodeXX( 29, X_FORM, 21, "fctiw."), + new opcodeXX( 30, X_FORM, 21, "fctiwz"), + new opcodeXX( 31, X_FORM, 21, "fctiwz."), + new opcodeXX( 64, X_FORM, 19, "fcmpo"), + new opcodeXX( 76, X_FORM, 16, "mtfsb1"), + new opcodeXX( 77, X_FORM, 16, "mtfsb1."), + new opcodeXX( 80, X_FORM, 21, "fneg"), + new opcodeXX( 81, X_FORM, 21, "fneg."), + new opcodeXX( 128, X_FORM, 14, "mcrfs"), + new opcodeXX( 140, X_FORM, 16, "mtfsb0"), + new opcodeXX( 141, X_FORM, 16, "mtfsb0."), + new opcodeXX( 144, X_FORM, 21, "fmr"), + new opcodeXX( 145, X_FORM, 21, "fmr."), + new opcodeXX( 268, X_FORM, 15, "mtfsfi"), + new opcodeXX( 269, X_FORM, 15, "mtfsfi."), + new opcodeXX( 272, X_FORM, 21, "fnabs"), + new opcodeXX( 273, X_FORM, 21, "fnabs."), + new opcodeXX( 528, X_FORM, 21, "fabs"), + new opcodeXX( 529, X_FORM, 21, "fabs."), + new opcodeXX( 1166, X_FORM, 13, "mffs"), + new opcodeXX( 1167, X_FORM, 13, "mffs."), + new opcodeXX( 1422, XFL_FORM, 9, "mtfsf"), + new opcodeXX( 1423, XFL_FORM, 9, "mtfsf."), + + // these are only valid for 32 bit architecture + new opcodeXX( 1628, X_FORM, 21, "fctid"), + new opcodeXX( 1629, X_FORM, 21, "fctid."), + new opcodeXX( 1630, X_FORM, 21, "fctidz"), + new opcodeXX( 1631, X_FORM, 21, "fctidz."), + new opcodeXX( 1692, X_FORM, 21, "fcfid"), + new opcodeXX( 1693, X_FORM, 21, "fcfid.") + }; + + static opcodeXX[] opcode59 = { + + /* opcode59 table: These are the addition for the PowerPC set + * Key is bits 26 through 31 of the instruction. + * "Form" is the instruction format and "format" is how the + * instruction should be printed (the enumeration is specific + * to each decode method) + */ + + /* key form format mnemonic */ + new opcodeXX( 42, A_FORM, 0, "fadds"), + new opcodeXX( 43, A_FORM, 0, "fadds."), + new opcodeXX( 36, A_FORM, 0, "fdivs"), + new opcodeXX( 37, A_FORM, 0, "fdivs."), + new opcodeXX( 58, A_FORM, 2, "fmadds"), + new opcodeXX( 59, A_FORM, 2, "fmadds."), + new opcodeXX( 56, A_FORM, 2, "fmsubs"), + new opcodeXX( 57, A_FORM, 2, "fmsubs."), + new opcodeXX( 50, A_FORM, 1, "fmuls"), + new opcodeXX( 51, A_FORM, 1, "fmuls."), + new opcodeXX( 62, A_FORM, 2, "fnmadds"), + new opcodeXX( 63, A_FORM, 2, "fnmadds."), + new opcodeXX( 60, A_FORM, 2, "fnmsubs"), + new opcodeXX( 61, A_FORM, 2, "fnmsubs."), + new opcodeXX( 40, A_FORM, 0, "fsubs"), + new opcodeXX( 41, A_FORM, 0, "fsubs.") + }; + + static opcodeXX[] Aform = { + + /* Aform table: The key is computed by taking + * bits 26 through 31 of the instruction. "Form" is + * the instruction format and "format" is how the + * instruction should be printed. */ + + /* key form format mnemonic */ + new opcodeXX( 36, A_FORM, 0, "fdiv"), + new opcodeXX( 37, A_FORM, 0, "fdiv."), + new opcodeXX( 40, A_FORM, 0, "fsub"), + new opcodeXX( 41, A_FORM, 0, "fsub."), + new opcodeXX( 42, A_FORM, 0, "fadd"), + new opcodeXX( 43, A_FORM, 0, "fadd."), + new opcodeXX( 50, A_FORM, 1, "fm"), + new opcodeXX( 51, A_FORM, 1, "fm."), + new opcodeXX( 56, A_FORM, 2, "fmsub"), + new opcodeXX( 57, A_FORM, 2, "fmsub."), + new opcodeXX( 58, A_FORM, 2, "fmadd"), + new opcodeXX( 59, A_FORM, 2, "fmadd."), + new opcodeXX( 60, A_FORM, 2, "fnmsub"), + new opcodeXX( 61, A_FORM, 2, "fnmsub."), + new opcodeXX( 62, A_FORM, 2, "fnmadd"), + new opcodeXX( 63, A_FORM, 2, "fnmadd.") + }; + + /* + * SPR_name - common special purpose register names options + */ + static String SPR_name(int SPR) + { + switch (SPR) { + case SPR_MQ: return("mq"); + case SPR_XER: return("xer"); + case SPR_LR: return("lr"); + case SPR_CTR: return("ctr"); + case SPR_TID: return("tid"); + case SPR_DSISR: return("dsisr"); + case SPR_DAR: return("dar"); + case SPR_RTCU: return("rtcu"); + case SPR_RTCL: return("rtcu"); + case SPR_DEC: return("dec"); + case SPR_SDR0: return("sdr0"); + case SPR_SDR1: return("sdr1"); + case SPR_SRR0: return("srr0"); + case SPR_SRR1: return("srr1"); + default: return null; + } + } + + /* + * TO_ext - common trap options + */ + static String TO_ext(int TO) + { + switch (TO) { + case TO_LT: return("lt"); + case (TO_LT | TO_EQ): return("le"); + case (TO_LT | TO_GT): return("ne"); + case TO_GT: return("gt"); + case (TO_GT | TO_EQ): return("ge"); + case TO_LLT: return("llt"); + case (TO_LLT | TO_EQ): return("lle"); + case (TO_LLT | TO_LGT): return("lne"); + case TO_LGT: return("lgt"); + case (TO_LGT | TO_EQ): return("lge"); + case TO_EQ: return("eq"); + default:return null; + } + } + + /* + * Translate an instruction from its + * numeric form into something more + * readable. + */ + + public static String disasm(int inst, int addr) + { + int opcode; + int form; + + opcode = bits(inst,0,5); /* Determine opcode */ + form = opcode_to_form[opcode]; /* Determine instruction format */ + + switch(form) /* decode known instruction format */ + { + case D_FORM: + return decode_Dform(inst, opcode); + case DS_FORM: + return decode_DSform(inst, opcode); + case B_FORM: + return decode_Bform(addr, inst, opcode); + case I_FORM: + return decode_Iform(addr,inst, opcode); + case SC_FORM: + return decode_SCform(inst, opcode); + case XL_FORM: + return decode_XLform(inst, opcode); + case M_FORM: + return decode_Mform(inst, opcode); + case A_FORM: + return decode_opcode59(inst); + case EXTENDED: /* More work to do... */ + switch(opcode) /* Switch off of opcode and process from there */ + { + case 30: + return decode_opcode30(inst); + case 31: + return decode_opcode31(inst); + case 63: + return decode_opcode63(inst); + default: + return " Invalid opcode"; + } + case INVALID_OP: /* More work to do... */ + default: + return " Invalid opcode"; + } + } + + /* Decode the D instruction format */ + + static String decode_Dform(int inst, int opcode) + { + int rt, RA, TO, BF, FRT,ufield; + int sfield; + opcode_tab opcode_info; + String datafield, mnemonic, asm_mnemonic, common_opt; + + rt = TO = FRT = bits(inst, 6, 10); + RA = bits(inst, 11, 15); + BF = bits(inst,6,8); + ufield = inst & 0xffff; + sfield = (inst << 16) >> 16; + if (sfield < 0) { + datafield = ""+sfield; + } else { + datafield = intAsHexString(sfield); + } + opcode_info = Dform[opcode]; + mnemonic = opcode_info.mnemonic; + + switch(opcode_info.format) + { + case 0: + if (opcode != 15) { + return " ".substring(mnemonic.length()) + mnemonic + + " "+rname(rt)+","+rname(RA)+","+datafield; + } else { + if (RA != 0) { + return " ".substring(mnemonic.length()) + mnemonic + + " "+rname(rt)+","+rname(RA)+","+intAsHexString(ufield); + } else { + return " liu "+ + rname(rt)+","+intAsHexString(ufield); + } + } + case 1: + return " ".substring(mnemonic.length()) + mnemonic + + " "+rname(RA)+","+rname(rt)+","+intAsHexString(ufield); + case 2: + if ((opcode == 14) && (RA == 0)) { + return " lil" + + " "+rname(rt)+","+datafield; + } else { + return " ".substring(mnemonic.length()) + mnemonic + + " "+rname(rt)+","+datafield+"("+rname(RA)+")"; + } + case 3: /* Trap immediate */ + common_opt = TO_ext(TO); + asm_mnemonic = ((opcode == 2) ? "td" : "tw")+common_opt+"i"; + if (common_opt!=null) { + return " ".substring(asm_mnemonic.length()) + asm_mnemonic + + " "+rname(RA)+","+datafield; + } else { + return " ".substring(mnemonic.length()) + mnemonic + + " "+TO+","+rname(RA)+","+datafield; + } + case 4: + int L = inst & 0x00200000; + if (opcode == 11) { + return " ".substring(mnemonic.length()) + mnemonic + ((L==0)?"W":"D") + + " cr"+BF+","+rname(RA)+","+datafield; + } else { + return " ".substring(mnemonic.length()) + mnemonic + ((L==0)?"W":"D") + + " cr"+BF+","+rname(RA)+","+ufield; + } + case 5: + return " ".substring(mnemonic.length()) + mnemonic + + " fr"+FRT+","+rname(RA)+","+datafield; + default: + return " Invalid opcode"; + } + } + + /* Decode the DS instruction format */ + + static String decode_DSform(int inst, int opcode) + { + int XO, RT, RA, sfield; + String datafield, mnemonic; + + XO = bits(inst,30,31); + RT = bits(inst,6,10); + RA = bits(inst,11,15); + sfield = (((inst) & 0xfffc) << 16) >> 16; + datafield = intAsHexString(sfield); + + switch(opcode) { + case 58: + mnemonic = opcode58[XO].mnemonic; + if (mnemonic == "RESERVED") return " Invalid opcode"; + return " ".substring(mnemonic.length()) + mnemonic + + " " + rname(RT)+ ", "+ datafield + "(" + rname(RA) + ")"; + case 62: + mnemonic = opcode62[XO].mnemonic; + if (mnemonic == "RESERVED") return " Invalid opcode"; + return " ".substring(mnemonic.length()) + mnemonic + + " " + rname(RT)+ ", "+ datafield + "(" + rname(RA) + ")"; + default: + return " Invalid opcode"; + } + } + + /* Decode the B instruction format */ + + static String decode_Bform(int addr, int inst, int opcode) + { + int AA, LK, BO, BI; + String mnemonic; + int cr_field; + int target; + + AA = bits(inst,30,30); + LK = bits(inst,31,31); + BO = bits(inst,6,10); + BI = bits(inst,11,15); + target = (((inst) & 0xfffc) << 16) >> 16; + if (AA == 0) + target += addr; + mnemonic = build_branch_op(BO,1 << (3 - (BI&3)),LK,AA,0); + destination = target; + cr_field = (BI>>2); + /* Build disassembly without target, added on later... */ + if (cr_field != 0) {/* Not CR 0 ? */ + return " ".substring(mnemonic.length()) + mnemonic + + " "+cr_field + " " + Integer.toHexString(destination); + } else { + return " ".substring(mnemonic.length()) + mnemonic + + " " + Integer.toHexString(destination); + } + } + + /* Decode the I instruction format */ + + static String decode_Iform(int addr, int inst, int opcode) + { + int target; + int AA, LK; + String mnemonic; + + AA = bits(inst,30,30); + LK = bits(inst,31,31); + target = (((inst) & ~3) << 6) >> 6; + if (AA!=0) { + mnemonic = (LK!=0) ? "bla" : "ba"; + } else { + target += addr; + mnemonic = (LK!=0) ? "bl" : "b"; + } + destination = target; + return " ".substring(mnemonic.length()) + mnemonic + " " + Integer.toHexString(destination); + } + + /* Decode the SC instruction format */ + + static String decode_SCform(int inst, int opcode) + { + int SA, LK, LEV, FL1, FL2, SV; + + SA = bits(inst,30,30); + LK = bits(inst,31,31); + if (SA != 0) + { + SV = bits(inst,16,29); + String mnemonic = (LK!=0) ? "svcla" : "svca"; + return " ".substring(mnemonic.length()) + mnemonic + + " "+intAsHexString(SV); + } + else + { + LEV = bits(inst,20,26); + FL1 = bits(inst,16,19); + FL2 = bits(inst,27,29); + String mnemonic = (LK!=0) ? "svcl" : "svc"; + return " ".substring(mnemonic.length()) + mnemonic + + " "+intAsHexString(LEV)+","+intAsHexString(FL1)+","+ + intAsHexString(FL2); + } + } + + /* Decode the XL instruction format */ + + static String decode_XLform(int inst, int opcode) + { + String mnemonic; + int ext_opcode; + int LK, BO, BI, BB; + int BF, BFA, BT, BA; + opcode_tab opcode_info; + int cr_field; + String branch_name; + + ext_opcode = bits(inst,21,30); + opcode_info = XLform[ext_opcode >> 4]; /* shift to get XL table index */ + mnemonic = opcode_info.mnemonic; + switch(opcode_info.format) + { + case 0: + return " ".substring(mnemonic.length()) + mnemonic; + case 1: + BO = bits(inst,6,10); + BI = bits(inst,11,15); + LK = bits(inst,31,31); + cr_field = (byte) (BI>>2); + branch_name = build_branch_op(BO,1 << (3 - (BI&3)),LK,0,ext_opcode); + if (cr_field!=0) {/* Not CR 0 ? */ + return " ".substring(branch_name.length()) + branch_name + + " "+cr_field; + } else { + return " ".substring(branch_name.length()) + branch_name; + } + case 2: + BF = bits(inst,6,10); + BFA = bits(inst,11,13); + return " ".substring(mnemonic.length()) + mnemonic + + " cr"+BF+","+intAsHexString(BFA); + case 3: + BT = bits(inst,6,10); + BA = bits(inst,11,15); + BB = bits(inst,16,20); + return " ".substring(mnemonic.length()) + mnemonic + + " "+intAsHexString(BT)+","+intAsHexString(BA)+","+ + intAsHexString(BB); + default: + return " Invalid opcode"; + } + } + + static String[] Mforms = { "rlimi", "rlimi.", "rlinm", "rlinm.", + "rlmi", "rlmi.", "rlnm", "rlnm."}; + + /* Decode the M instruction format */ + + static String decode_Mform(int inst, int opcode) + { + int RS, RA; + int MB, ME, Rc; + int SH_RB; + String asm_mnemonic; + + RS = bits(inst,6,10); + RA = bits(inst,11,15); + SH_RB = bits(inst,16,20); + MB = bits(inst,21,25); + ME = bits(inst,26,30); + Rc = inst & 1; + + asm_mnemonic = Mforms[(opcode - 20) * 2 + Rc]; + if ((opcode < 20) || ((opcode >>> 23)!=0)) { + return " Invalid opcode"; + } else { + if (opcode == 21) { /* sri and sli are special forms of rlmni */ + if ((ME == 32) && (MB == (31-SH_RB))) { + String mnemonic = (Rc!=0) ? "sri." : "sri"; + return " ".substring(mnemonic.length()) + mnemonic + + " "+rname(RA)+","+rname(RS)+","+intAsHexString(MB); + } else if ((MB == 0) && (SH_RB == (31-ME))) { + String mnemonic = (Rc!=0) ? "sli." : "sli"; + return " ".substring(mnemonic.length()) + mnemonic + + " "+rname(RA)+","+rname(RS)+","+intAsHexString(SH_RB); + } else { + return " ".substring(asm_mnemonic.length()) + asm_mnemonic + + " "+rname(RA)+","+rname(RS)+","+intAsHexString(SH_RB)+","+ + intAsHexString(MB)+","+intAsHexString(ME) ; + } + } else { + return " ".substring(asm_mnemonic.length()) + asm_mnemonic + + " "+rname(RA)+","+rname(RS)+","+intAsHexString(SH_RB)+","+ + intAsHexString(MB)+","+intAsHexString(ME) ; + } + } + } + + static opcodeXX searchXX(int key, opcodeXX[] where) { + + for (opcodeXX opxx : where) { + if (opxx.key == key) return opxx; + } + + return null; + + } + + /* Decode opcode 30 and then the relevent format */ + + static String decode_opcode30(int inst) + { + opcodeXX search_results; + String mnemonic; + + int testkey = bits(inst,27,30); + search_results = searchXX(testkey, opcode30); + + if (search_results == null) { + return " Invalid opcode"; + } + + mnemonic = search_results.mnemonic; + + switch(search_results.form) + { + case MDS_FORM: + return decode_MDSform(inst, mnemonic); + case MD_FORM: + return decode_MDform(inst, mnemonic); + default: + return " Invalid opcode"; + } + } + + /* Decode the MD instruction format */ + static String decode_MDform(int inst, String mnemonic) + { + int RS, RA, SH, MB; + + RS = bits(inst,6,10); + RA = bits(inst,11,15); + SH = ((inst&0x2) >> 4) | bits(inst,16,20); + MB = (inst&0x20) | bits(inst,21,25); + return " ".substring(mnemonic.length()) + mnemonic + + rname(RA) + ", " + rname(RS) + ", " + SH + ", " + MB; + } + + /* Decode the MDS instruction format */ + static String decode_MDSform(int inst, String mnemonic) + { + int RS, RA, RB, MB; + + RS = bits(inst,6,10); + RA = bits(inst,11,15); + RB = bits(inst,16,20); + MB = (inst&0x20) | bits(inst,21,25); + return " ".substring(mnemonic.length()) + mnemonic + + rname(RA) + ", " + rname(RS) + ", " + rname(RB) + ", " + MB; + } + + /* Decode the A instruction format */ + /* Decode opcode 31 and then the relevent format */ + + static String decode_opcode31(int inst) + { + opcodeXX search_results; + int format; + String mnemonic; + + + int testkey = bits(inst,21,31); + search_results = searchXX(testkey, opcode31); + + if (search_results == null) { + return " Invalid opcode"; + } + + mnemonic = search_results.mnemonic; + format = search_results.format; + switch(search_results.form) + { + case X_FORM: + return decode_Xform(inst,mnemonic,format,testkey); + case XFX_FORM: + return decode_XFXform(inst); + case XO_FORM: + return decode_XOform(inst,mnemonic,format); + case XS_FORM: + return decode_XSform(inst,mnemonic,format); + default: + return " Invalid opcode"; + } + } + + /* Decode the X instruction format */ + + static String decode_Xform(int inst, String mnemonic, int format, int ext_op) + { + int rt,RA,RB,NB,SH,FRS,SPR,FRT; + int BF,BFA,I,BT,SR,FRA,FRB,TO; + String asm_mnemonic, common_opt; + + FRS = FRT = TO = BT = rt = bits(inst,6,10); + FRB = NB = SH = RB = I = bits(inst,16,20); + FRA = SPR = SR = RA = bits(inst,11,15); + BFA = bits(inst,11,13); + I = bits(inst,16,19); + BF = bits(inst,6,8); + + switch(format) + { + case 0: + return " ".substring(mnemonic.length()) + mnemonic + + " "+rname(RA)+","+rname(rt); + case 1: + return " ".substring(mnemonic.length()) + mnemonic; + case 2: + return " ".substring(mnemonic.length()) + mnemonic + + " "+rname(rt); + case 3: + common_opt = SPR_name(SPR); + if (common_opt != null) { + asm_mnemonic = mnemonic.substring(0, 2) + common_opt; + return " ".substring(asm_mnemonic.length()) + asm_mnemonic + + " "+rname(rt); + } else {/* reserved register? */ + return " ".substring(mnemonic.length()) + mnemonic + + " "+intAsHexString(SPR)+","+rname(rt); + } + case 4: + return " ".substring(mnemonic.length()) + mnemonic + + " "+rname(rt)+","+rname(RB); + case 5: + return " ".substring(mnemonic.length()) + mnemonic + + " "+rname(rt)+","+rname(RA); + case 6: + return " ".substring(mnemonic.length()) + mnemonic + + " "+rname(RA)+","+rname(RB); + case 7: + return " ".substring(mnemonic.length()) + mnemonic + + " "+rname(rt)+","+rname(RA)+","+rname(RB); + case 8: + if ((ext_op == 888) || (ext_op == 889)) { + if (rt == RB) { + String mne = (ext_op == 889) ? "mr." : "mr"; + return " ".substring(mne.length()) + mne + + " "+rname(RA)+","+rname(rt); + } + } + return " ".substring(mnemonic.length()) + mnemonic + + " "+rname(RA)+","+rname(rt)+","+rname(RB); + case 9: + return " ".substring(mnemonic.length()) + mnemonic + + " "+rname(RA)+","+rname(rt); + case 10: + return " ".substring(mnemonic.length()) + mnemonic + + " "+rname(rt)+","+rname(RA)+","+intAsHexString(NB); + case 11: + return " ".substring(mnemonic.length()) + mnemonic + + " "+rname(RA)+","+rname(rt)+","+intAsHexString(SH); + case 12: + return " ".substring(mnemonic.length()) + mnemonic + + " fr"+FRS+","+rname(RA)+","+rname(RB); + case 13: + return " ".substring(mnemonic.length()) + mnemonic + + " fr"+FRT; + case 14: + return " ".substring(mnemonic.length()) + mnemonic + + " cr"+BF+","+intAsHexString(BFA); + case 15: + return " ".substring(mnemonic.length()) + mnemonic + + " cr"+BF+","+intAsHexString(I); + c... [truncated message content] |
From: <cap...@us...> - 2007-03-16 15:33:15
|
Revision: 2 http://svn.sourceforge.net/pearcolator/?rev=2&view=rev Author: captain5050 Date: 2007-03-16 08:33:01 -0700 (Fri, 16 Mar 2007) Log Message: ----------- Restructure files and imports following Jikes RVM restructuring Modified Paths: -------------- src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java src/org/binarytranslator/arch/ppc/decoder/PPC_Laziness.java src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java src/org/binarytranslator/arch/x86/decoder/X862IR.java src/org/binarytranslator/arch/x86/decoder/X86_DecodedOperand.java src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java src/org/binarytranslator/generic/decoder/DecoderUtils.java src/org/binarytranslator/generic/memory/CallBasedMemory.java src/org/binarytranslator/generic/memory/IntAddressedPreSwappedMemory.java src/org/binarytranslator/generic/memory/Memory.java src/org/binarytranslator/generic/os/process/ProcessSpace.java src/org/binarytranslator/vmInterface/DBT_ConvertBinaryToHIR.java src/org/binarytranslator/vmInterface/DBT_OptimizingCompilerException.java src/org/binarytranslator/vmInterface/DBT_Trace.java src/org/binarytranslator/vmInterface/DynamicCodeRunner.java src/org/binarytranslator/vmInterface/TranslationHelper.java Added Paths: ----------- LICENSE.txt ext/org/ ext/org/jikesrvm/ ext/org/jikesrvm/opt/ ext/org/jikesrvm/opt/ir/ ext/org/jikesrvm/opt/ir/OPT_HIRGenerator.java Removed Paths: ------------- LICENSE ext/com/ Deleted: LICENSE =================================================================== --- LICENSE 2006-12-07 14:54:50 UTC (rev 1) +++ LICENSE 2007-03-16 15:33:01 UTC (rev 2) @@ -1,247 +0,0 @@ - Common Public License - v 1.0 - - THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON - PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF - THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. - - 1. DEFINITIONS - - "Contribution" means: - - a) in the case of the initial Contributor, the initial code and - documentation distributed under this Agreement, and - - b) in the case of each subsequent Contributor: - - i) changes to the Program, and - - ii) additions to the Program; - - where such changes and/or additions to the Program originate from - and are distributed by that particular Contributor. A Contribution - 'originates' from a Contributor if it was added to the Program by - such Contributor itself or anyone acting on such Contributor's - behalf. Contributions do not include additions to the Program - which: (i) are separate modules of software distributed in - conjunction with the Program under their own license agreement, and - (ii) are not derivative works of the Program. - - "Contributor" means any person or entity that distributes the - Program. - - "Licensed Patents" mean patent claims licensable by a Contributor - which are necessarily infringed by the use or sale of its - Contribution alone or when combined with the Program. - - "Program" means the Contributions distributed in accordance with - this Agreement. - - "Recipient" means anyone who receives the Program under this - Agreement, including all Contributors. - - - 2. GRANT OF RIGHTS - - a) Subject to the terms of this Agreement, each Contributor hereby - grants Recipient a non-exclusive, worldwide, royalty-free - copyright license to reproduce, prepare derivative works of, - publicly display, publicly perform, distribute and sublicense - the Contribution of such Contributor, if any, and such - derivative works, in source code and object code form. - - b) Subject to the terms of this Agreement, each Contributor hereby - grants Recipient a non-exclusive, worldwide, royalty-free - patent license under Licensed Patents to make, use, sell, offer - to sell, import and otherwise transfer the Contribution of such - Contributor, if any, in source code and object code form. This - patent license shall apply to the combination of the - Contribution and the Program if, at the time the Contribution - is added by the Contributor, such addition of the Contribution - causes such combination to be covered by the Licensed - Patents. The patent license shall not apply to any other - combinations which include the Contribution. No hardware per se - is licensed hereunder. - - c) Recipient understands that although each Contributor grants the - licenses to its Contributions set forth herein, no assurances - are provided by any Contributor that the Program does not - infringe the patent or other intellectual property rights of - any other entity. Each Contributor disclaims any liability to - Recipient for claims brought by any other entity based on - infringement of intellectual property rights or otherwise. As - a condition to exercising the rights and licenses granted - hereunder, each Recipient hereby assumes sole responsibility to - secure any other intellectual property rights needed, if any. - For example, if a third party patent license is required to - allow Recipient to distribute the Program, it is Recipient's - responsibility to acquire that license before distributing the - Program. - - d) Each Contributor represents that to its knowledge it has - sufficient copyright rights in its Contribution, if any, to - grant the copyright license set forth in this Agreement. - - 3. REQUIREMENTS - - A Contributor may choose to distribute the Program in object code - form under its own license agreement, provided that: - - a) it complies with the terms and conditions of this Agreement; and - - b) its license agreement: - - i) effectively disclaims on behalf of all Contributors all - warranties and conditions, express and implied, including - warranties or conditions of title and non-infringement, and - implied warranties or conditions of merchantability and fitness - for a particular purpose; - - ii) effectively excludes on behalf of all Contributors all - liability for damages, including direct, indirect, special, - incidental and consequential damages, such as lost profits; - - iii) states that any provisions which differ from this Agreement - are offered by that Contributor alone and not by any other - party; and - - iv) states that source code for the Program is available from such - Contributor, and informs licensees how to obtain it in a - reasonable manner on or through a medium customarily used for - software exchange. - - When the Program is made available in source code form: - - a) it must be made available under this Agreement; and - - b) a copy of this Agreement must be included with each copy of the - Program. - - Contributors may not remove or alter any copyright notices - contained within the Program. - - Each Contributor must identify itself as the originator of its - Contribution, if any, in a manner that reasonably allows subsequent - Recipients to identify the originator of the Contribution. - - 4. COMMERCIAL DISTRIBUTION - - Commercial distributors of software may accept certain - responsibilities with respect to end users, business partners and - the like. While this license is intended to facilitate the - commercial use of the Program, the Contributor who includes the - Program in a commercial product offering should do so in a manner - which does not create potential liability for other - Contributors. Therefore, if a Contributor includes the Program in a - commercial product offering, such Contributor ("Commercial - Contributor") hereby agrees to defend and indemnify every other - Contributor ("Indemnified Contributor") against any losses, damages - and costs (collectively "Losses") arising from claims, lawsuits and - other legal actions brought by a third party against the - Indemnified Contributor to the extent caused by the acts or - omissions of such Commercial Contributor in connection with its - distribution of the Program in a commercial product offering. The - obligations in this section do not apply to any claims or Losses - relating to any actual or alleged intellectual property - infringement. In order to qualify, an Indemnified Contributor - must: a) promptly notify the Commercial Contributor in writing of - such claim, and b) allow the Commercial Contributor to control, and - cooperate with the Commercial Contributor in, the defense and any - related settlement negotiations. The Indemnified Contributor may - participate in any such claim at its own expense. - - For example, a Contributor might include the Program in a - commercial product offering, Product X. That Contributor is then a - Commercial Contributor. If that Commercial Contributor then makes - performance claims, or offers warranties related to Product X, - those performance claims and warranties are such Commercial - Contributor's responsibility alone. Under this section, the - Commercial Contributor would have to defend claims against the - other Contributors related to those performance claims and - warranties, and if a court requires any other Contributor to pay - any damages as a result, the Commercial Contributor must pay those - damages. - - 5. NO WARRANTY - - EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS - PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF - ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, - ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, - MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each - Recipient is solely responsible for determining the appropriateness - of using and distributing the Program and assumes all risks - associated with its exercise of rights under this Agreement, - including but not limited to the risks and costs of program errors, - compliance with applicable laws, damage to or loss of data, - programs or equipment, and unavailability or interruption of - operations. - - 6. DISCLAIMER OF LIABILITY - - EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT - NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY - RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF - SUCH DAMAGES. - - 7. GENERAL - - If any provision of this Agreement is invalid or unenforceable - under applicable law, it shall not affect the validity or - enforceability of the remainder of the terms of this Agreement, and - without further action by the parties hereto, such provision shall - be reformed to the minimum extent necessary to make such provision - valid and enforceable. - - If Recipient institutes patent litigation against a Contributor - with respect to a patent applicable to software (including a - cross-claim or counterclaim in a lawsuit), then any patent licenses - granted by that Contributor to such Recipient under this Agreement - shall terminate as of the date such litigation is filed. In - addition, if Recipient institutes patent litigation against any - entity (including a cross-claim or counterclaim in a lawsuit) - alleging that the Program itself (excluding combinations of the - Program with other software or hardware) infringes such Recipient's - patent(s), then such Recipient's rights granted under Section 2(b) - shall terminate as of the date such litigation is filed. - - All Recipient's rights under this Agreement shall terminate if it - fails to comply with any of the material terms or conditions of - this Agreement and does not cure such failure in a reasonable - period of time after becoming aware of such noncompliance. If all - Recipient's rights under this Agreement terminate, Recipient agrees - to cease use and distribution of the Program as soon as reasonably - practicable. However, Recipient's obligations under this Agreement - and any licenses granted by Recipient relating to the Program shall - continue and survive. - - Everyone is permitted to copy and distribute copies of this - Agreement, but in order to avoid inconsistency the Agreement is - copyrighted and may only be modified in the following manner. The - Agreement Steward reserves the right to publish new versions - (including revisions) of this Agreement from time to time. No one - other than the Agreement Steward has the right to modify this - Agreement. IBM is the initial Agreement Steward. IBM may assign - the responsibility to serve as the Agreement Steward to a suitable - separate entity. Each new version of the Agreement will be given a - distinguishing version number. The Program (including - Contributions) may always be distributed subject to the version of - the Agreement under which it was received. In addition, after a new - version of the Agreement is published, Contributor may elect to - distribute the Program (including its Contributions) under the new - version. Except as expressly stated in Sections 2(a) and 2(b) - above, Recipient receives no rights or licenses to the intellectual - property of any Contributor under this Agreement, whether - expressly, by implication, estoppel or otherwise. All rights in the - Program not expressly granted under this Agreement are reserved. - - This Agreement is governed by the laws of the State of New York and - the intellectual property laws of the United States of America. No - party to this Agreement will bring a legal action under this - Agreement more than one year after the cause of action arose. Each - party waives its rights to a jury trial in any resulting - litigation. Copied: LICENSE.txt (from rev 1, LICENSE) =================================================================== --- LICENSE.txt (rev 0) +++ LICENSE.txt 2007-03-16 15:33:01 UTC (rev 2) @@ -0,0 +1,247 @@ + Common Public License - v 1.0 + + THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON + PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF + THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + + 1. DEFINITIONS + + "Contribution" means: + + a) in the case of the initial Contributor, the initial code and + documentation distributed under this Agreement, and + + b) in the case of each subsequent Contributor: + + i) changes to the Program, and + + ii) additions to the Program; + + where such changes and/or additions to the Program originate from + and are distributed by that particular Contributor. A Contribution + 'originates' from a Contributor if it was added to the Program by + such Contributor itself or anyone acting on such Contributor's + behalf. Contributions do not include additions to the Program + which: (i) are separate modules of software distributed in + conjunction with the Program under their own license agreement, and + (ii) are not derivative works of the Program. + + "Contributor" means any person or entity that distributes the + Program. + + "Licensed Patents" mean patent claims licensable by a Contributor + which are necessarily infringed by the use or sale of its + Contribution alone or when combined with the Program. + + "Program" means the Contributions distributed in accordance with + this Agreement. + + "Recipient" means anyone who receives the Program under this + Agreement, including all Contributors. + + + 2. GRANT OF RIGHTS + + a) Subject to the terms of this Agreement, each Contributor hereby + grants Recipient a non-exclusive, worldwide, royalty-free + copyright license to reproduce, prepare derivative works of, + publicly display, publicly perform, distribute and sublicense + the Contribution of such Contributor, if any, and such + derivative works, in source code and object code form. + + b) Subject to the terms of this Agreement, each Contributor hereby + grants Recipient a non-exclusive, worldwide, royalty-free + patent license under Licensed Patents to make, use, sell, offer + to sell, import and otherwise transfer the Contribution of such + Contributor, if any, in source code and object code form. This + patent license shall apply to the combination of the + Contribution and the Program if, at the time the Contribution + is added by the Contributor, such addition of the Contribution + causes such combination to be covered by the Licensed + Patents. The patent license shall not apply to any other + combinations which include the Contribution. No hardware per se + is licensed hereunder. + + c) Recipient understands that although each Contributor grants the + licenses to its Contributions set forth herein, no assurances + are provided by any Contributor that the Program does not + infringe the patent or other intellectual property rights of + any other entity. Each Contributor disclaims any liability to + Recipient for claims brought by any other entity based on + infringement of intellectual property rights or otherwise. As + a condition to exercising the rights and licenses granted + hereunder, each Recipient hereby assumes sole responsibility to + secure any other intellectual property rights needed, if any. + For example, if a third party patent license is required to + allow Recipient to distribute the Program, it is Recipient's + responsibility to acquire that license before distributing the + Program. + + d) Each Contributor represents that to its knowledge it has + sufficient copyright rights in its Contribution, if any, to + grant the copyright license set forth in this Agreement. + + 3. REQUIREMENTS + + A Contributor may choose to distribute the Program in object code + form under its own license agreement, provided that: + + a) it complies with the terms and conditions of this Agreement; and + + b) its license agreement: + + i) effectively disclaims on behalf of all Contributors all + warranties and conditions, express and implied, including + warranties or conditions of title and non-infringement, and + implied warranties or conditions of merchantability and fitness + for a particular purpose; + + ii) effectively excludes on behalf of all Contributors all + liability for damages, including direct, indirect, special, + incidental and consequential damages, such as lost profits; + + iii) states that any provisions which differ from this Agreement + are offered by that Contributor alone and not by any other + party; and + + iv) states that source code for the Program is available from such + Contributor, and informs licensees how to obtain it in a + reasonable manner on or through a medium customarily used for + software exchange. + + When the Program is made available in source code form: + + a) it must be made available under this Agreement; and + + b) a copy of this Agreement must be included with each copy of the + Program. + + Contributors may not remove or alter any copyright notices + contained within the Program. + + Each Contributor must identify itself as the originator of its + Contribution, if any, in a manner that reasonably allows subsequent + Recipients to identify the originator of the Contribution. + + 4. COMMERCIAL DISTRIBUTION + + Commercial distributors of software may accept certain + responsibilities with respect to end users, business partners and + the like. While this license is intended to facilitate the + commercial use of the Program, the Contributor who includes the + Program in a commercial product offering should do so in a manner + which does not create potential liability for other + Contributors. Therefore, if a Contributor includes the Program in a + commercial product offering, such Contributor ("Commercial + Contributor") hereby agrees to defend and indemnify every other + Contributor ("Indemnified Contributor") against any losses, damages + and costs (collectively "Losses") arising from claims, lawsuits and + other legal actions brought by a third party against the + Indemnified Contributor to the extent caused by the acts or + omissions of such Commercial Contributor in connection with its + distribution of the Program in a commercial product offering. The + obligations in this section do not apply to any claims or Losses + relating to any actual or alleged intellectual property + infringement. In order to qualify, an Indemnified Contributor + must: a) promptly notify the Commercial Contributor in writing of + such claim, and b) allow the Commercial Contributor to control, and + cooperate with the Commercial Contributor in, the defense and any + related settlement negotiations. The Indemnified Contributor may + participate in any such claim at its own expense. + + For example, a Contributor might include the Program in a + commercial product offering, Product X. That Contributor is then a + Commercial Contributor. If that Commercial Contributor then makes + performance claims, or offers warranties related to Product X, + those performance claims and warranties are such Commercial + Contributor's responsibility alone. Under this section, the + Commercial Contributor would have to defend claims against the + other Contributors related to those performance claims and + warranties, and if a court requires any other Contributor to pay + any damages as a result, the Commercial Contributor must pay those + damages. + + 5. NO WARRANTY + + EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS + PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF + ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, + ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, + MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each + Recipient is solely responsible for determining the appropriateness + of using and distributing the Program and assumes all risks + associated with its exercise of rights under this Agreement, + including but not limited to the risks and costs of program errors, + compliance with applicable laws, damage to or loss of data, + programs or equipment, and unavailability or interruption of + operations. + + 6. DISCLAIMER OF LIABILITY + + EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT + NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY + RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGES. + + 7. GENERAL + + If any provision of this Agreement is invalid or unenforceable + under applicable law, it shall not affect the validity or + enforceability of the remainder of the terms of this Agreement, and + without further action by the parties hereto, such provision shall + be reformed to the minimum extent necessary to make such provision + valid and enforceable. + + If Recipient institutes patent litigation against a Contributor + with respect to a patent applicable to software (including a + cross-claim or counterclaim in a lawsuit), then any patent licenses + granted by that Contributor to such Recipient under this Agreement + shall terminate as of the date such litigation is filed. In + addition, if Recipient institutes patent litigation against any + entity (including a cross-claim or counterclaim in a lawsuit) + alleging that the Program itself (excluding combinations of the + Program with other software or hardware) infringes such Recipient's + patent(s), then such Recipient's rights granted under Section 2(b) + shall terminate as of the date such litigation is filed. + + All Recipient's rights under this Agreement shall terminate if it + fails to comply with any of the material terms or conditions of + this Agreement and does not cure such failure in a reasonable + period of time after becoming aware of such noncompliance. If all + Recipient's rights under this Agreement terminate, Recipient agrees + to cease use and distribution of the Program as soon as reasonably + practicable. However, Recipient's obligations under this Agreement + and any licenses granted by Recipient relating to the Program shall + continue and survive. + + Everyone is permitted to copy and distribute copies of this + Agreement, but in order to avoid inconsistency the Agreement is + copyrighted and may only be modified in the following manner. The + Agreement Steward reserves the right to publish new versions + (including revisions) of this Agreement from time to time. No one + other than the Agreement Steward has the right to modify this + Agreement. IBM is the initial Agreement Steward. IBM may assign + the responsibility to serve as the Agreement Steward to a suitable + separate entity. Each new version of the Agreement will be given a + distinguishing version number. The Program (including + Contributions) may always be distributed subject to the version of + the Agreement under which it was received. In addition, after a new + version of the Agreement is published, Contributor may elect to + distribute the Program (including its Contributions) under the new + version. Except as expressly stated in Sections 2(a) and 2(b) + above, Recipient receives no rights or licenses to the intellectual + property of any Contributor under this Agreement, whether + expressly, by implication, estoppel or otherwise. All rights in the + Program not expressly granted under this Agreement are reserved. + + This Agreement is governed by the laws of the State of New York and + the intellectual property laws of the United States of America. No + party to this Agreement will bring a legal action under this + Agreement more than one year after the cause of action arose. Each + party waives its rights to a jury trial in any resulting + litigation. Copied: ext/org/jikesrvm/opt/ir/OPT_HIRGenerator.java (from rev 1, ext/com/ibm/jikesrvm/opt/ir/OPT_HIRGenerator.java) =================================================================== --- ext/org/jikesrvm/opt/ir/OPT_HIRGenerator.java (rev 0) +++ ext/org/jikesrvm/opt/ir/OPT_HIRGenerator.java 2007-03-16 15:33:01 UTC (rev 2) @@ -0,0 +1,15 @@ +/* + * (C) The University of Manchester 2003 - 2006 + */ +package org.jikesrvm.opt.ir; + +/** + * Interface implemented by all optimizing compiler HIR generators + * such as OPT_BC2HIR and DBT_HIRGenerator + */ +public interface OPT_HIRGenerator { + /** + * Method to create the HIR + */ + public void generateHIR(); +} Modified: src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java =================================================================== --- src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java 2007-03-16 15:33:01 UTC (rev 2) @@ -16,53 +16,53 @@ import org.binarytranslator.generic.decoder.DecoderUtils; import org.binarytranslator.generic.decoder.Laziness; // General VM class -import com.ibm.jikesrvm.VM; +import org.jikesrvm.VM; // Classes to get at class types -import com.ibm.jikesrvm.classloader.VM_Class; -import com.ibm.jikesrvm.classloader.VM_Method; -import com.ibm.jikesrvm.classloader.VM_TypeReference; -import com.ibm.jikesrvm.classloader.VM_MethodReference; -import com.ibm.jikesrvm.classloader.VM_MemberReference; -import com.ibm.jikesrvm.classloader.VM_FieldReference; -import com.ibm.jikesrvm.classloader.VM_BootstrapClassLoader; -import com.ibm.jikesrvm.classloader.VM_Atom; +import org.jikesrvm.classloader.VM_Class; +import org.jikesrvm.classloader.VM_Method; +import org.jikesrvm.classloader.VM_TypeReference; +import org.jikesrvm.classloader.VM_MethodReference; +import org.jikesrvm.classloader.VM_MemberReference; +import org.jikesrvm.classloader.VM_FieldReference; +import org.jikesrvm.classloader.VM_BootstrapClassLoader; +import org.jikesrvm.classloader.VM_Atom; // OPT interface -import com.ibm.jikesrvm.opt.OPT_Constants; -import com.ibm.jikesrvm.opt.ir.OPT_GenerationContext; -import com.ibm.jikesrvm.opt.ir.OPT_HIRGenerator; -import com.ibm.jikesrvm.opt.ir.OPT_IR; +import org.jikesrvm.opt.OPT_Constants; +import org.jikesrvm.opt.ir.OPT_GenerationContext; +import org.jikesrvm.opt.ir.OPT_HIRGenerator; +import org.jikesrvm.opt.ir.OPT_IR; // Instructions -import com.ibm.jikesrvm.opt.ir.OPT_Instruction; -import com.ibm.jikesrvm.opt.ir.OPT_Operator; -import com.ibm.jikesrvm.opt.ir.OPT_Operators; -import com.ibm.jikesrvm.opt.ir.Athrow; -import com.ibm.jikesrvm.opt.ir.Binary; -import com.ibm.jikesrvm.opt.ir.BBend; -import com.ibm.jikesrvm.opt.ir.BooleanCmp; -import com.ibm.jikesrvm.opt.ir.Call; -import com.ibm.jikesrvm.opt.ir.CondMove; -import com.ibm.jikesrvm.opt.ir.GetField; -import com.ibm.jikesrvm.opt.ir.Goto; -import com.ibm.jikesrvm.opt.ir.IfCmp; -import com.ibm.jikesrvm.opt.ir.Move; -import com.ibm.jikesrvm.opt.ir.New; -import com.ibm.jikesrvm.opt.ir.LookupSwitch; -import com.ibm.jikesrvm.opt.ir.PutField; -import com.ibm.jikesrvm.opt.ir.Unary; +import org.jikesrvm.opt.ir.OPT_Instruction; +import org.jikesrvm.opt.ir.OPT_Operator; +import org.jikesrvm.opt.ir.OPT_Operators; +import org.jikesrvm.opt.ir.Athrow; +import org.jikesrvm.opt.ir.Binary; +import org.jikesrvm.opt.ir.BBend; +import org.jikesrvm.opt.ir.BooleanCmp; +import org.jikesrvm.opt.ir.Call; +import org.jikesrvm.opt.ir.CondMove; +import org.jikesrvm.opt.ir.GetField; +import org.jikesrvm.opt.ir.Goto; +import org.jikesrvm.opt.ir.IfCmp; +import org.jikesrvm.opt.ir.Move; +import org.jikesrvm.opt.ir.New; +import org.jikesrvm.opt.ir.LookupSwitch; +import org.jikesrvm.opt.ir.PutField; +import org.jikesrvm.opt.ir.Unary; // Operands -import com.ibm.jikesrvm.opt.ir.OPT_AddressConstantOperand; -import com.ibm.jikesrvm.opt.ir.OPT_BasicBlock; -import com.ibm.jikesrvm.opt.ir.OPT_BranchOperand; -import com.ibm.jikesrvm.opt.ir.OPT_BranchProfileOperand; -import com.ibm.jikesrvm.opt.ir.OPT_ConditionOperand; -import com.ibm.jikesrvm.opt.ir.OPT_IntConstantOperand; -import com.ibm.jikesrvm.opt.ir.OPT_LocationOperand; -import com.ibm.jikesrvm.opt.ir.OPT_MethodOperand; -import com.ibm.jikesrvm.opt.ir.OPT_Operand; -import com.ibm.jikesrvm.opt.ir.OPT_Register; -import com.ibm.jikesrvm.opt.ir.OPT_RegisterOperand; -import com.ibm.jikesrvm.opt.ir.OPT_TrueGuardOperand; -import com.ibm.jikesrvm.opt.ir.OPT_TypeOperand; +import org.jikesrvm.opt.ir.OPT_AddressConstantOperand; +import org.jikesrvm.opt.ir.OPT_BasicBlock; +import org.jikesrvm.opt.ir.OPT_BranchOperand; +import org.jikesrvm.opt.ir.OPT_BranchProfileOperand; +import org.jikesrvm.opt.ir.OPT_ConditionOperand; +import org.jikesrvm.opt.ir.OPT_IntConstantOperand; +import org.jikesrvm.opt.ir.OPT_LocationOperand; +import org.jikesrvm.opt.ir.OPT_MethodOperand; +import org.jikesrvm.opt.ir.OPT_Operand; +import org.jikesrvm.opt.ir.OPT_Register; +import org.jikesrvm.opt.ir.OPT_RegisterOperand; +import org.jikesrvm.opt.ir.OPT_TrueGuardOperand; +import org.jikesrvm.opt.ir.OPT_TypeOperand; // Java utilities import java.util.Enumeration; import java.util.NoSuchElementException; Modified: src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java =================================================================== --- src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java 2007-03-16 15:33:01 UTC (rev 2) @@ -14,10 +14,10 @@ import org.binarytranslator.generic.fault.BadInstructionException; import org.binarytranslator.generic.decoder.InstructionDecoder; -import com.ibm.jikesrvm.opt.ir.*; -import com.ibm.jikesrvm.*; -import com.ibm.jikesrvm.classloader.*; -import com.ibm.jikesrvm.opt.*; +import org.jikesrvm.opt.ir.*; +import org.jikesrvm.*; +import org.jikesrvm.classloader.*; +import org.jikesrvm.opt.*; import java.util.Enumeration; import java.util.NoSuchElementException; Modified: src/org/binarytranslator/arch/ppc/decoder/PPC_Laziness.java =================================================================== --- src/org/binarytranslator/arch/ppc/decoder/PPC_Laziness.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/arch/ppc/decoder/PPC_Laziness.java 2007-03-16 15:33:01 UTC (rev 2) @@ -10,8 +10,6 @@ import org.binarytranslator.generic.decoder.Laziness; -import com.ibm.jikesrvm.VM; - /** * A representation of the lazy state. This and a PC address define * what a block of code is good for. We don't use lazy evaluation for Modified: src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java 2007-03-16 15:33:01 UTC (rev 2) @@ -8,8 +8,8 @@ */ package org.binarytranslator.arch.ppc.os.process; -import com.ibm.jikesrvm.opt.ir.OPT_GenerationContext; -import com.ibm.jikesrvm.opt.ir.OPT_HIRGenerator; +import org.jikesrvm.opt.ir.OPT_GenerationContext; +import org.jikesrvm.opt.ir.OPT_HIRGenerator; import org.binarytranslator.DBT_Options; import org.binarytranslator.arch.ppc.os.process.linux.PPC_LinuxProcessSpace; import org.binarytranslator.arch.ppc.decoder.PPC2IR; Modified: src/org/binarytranslator/arch/x86/decoder/X862IR.java =================================================================== --- src/org/binarytranslator/arch/x86/decoder/X862IR.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/arch/x86/decoder/X862IR.java 2007-03-16 15:33:01 UTC (rev 2) @@ -21,59 +21,59 @@ import org.binarytranslator.generic.decoder.DecoderUtils; import org.binarytranslator.generic.decoder.Laziness; -import com.ibm.jikesrvm.opt.ir.OPT_HIRGenerator; -import com.ibm.jikesrvm.classloader.VM_TypeReference; -import com.ibm.jikesrvm.classloader.VM_Atom; +import org.jikesrvm.opt.ir.OPT_HIRGenerator; +import org.jikesrvm.classloader.VM_TypeReference; +import org.jikesrvm.classloader.VM_Atom; // General VM class -import com.ibm.jikesrvm.VM; +import org.jikesrvm.VM; // Classes to get at class types -import com.ibm.jikesrvm.classloader.VM_Class; -import com.ibm.jikesrvm.classloader.VM_Method; -import com.ibm.jikesrvm.classloader.VM_TypeReference; -import com.ibm.jikesrvm.classloader.VM_MethodReference; -import com.ibm.jikesrvm.classloader.VM_MemberReference; -import com.ibm.jikesrvm.classloader.VM_FieldReference; -import com.ibm.jikesrvm.classloader.VM_BootstrapClassLoader; -import com.ibm.jikesrvm.classloader.VM_Atom; +import org.jikesrvm.classloader.VM_Class; +import org.jikesrvm.classloader.VM_Method; +import org.jikesrvm.classloader.VM_TypeReference; +import org.jikesrvm.classloader.VM_MethodReference; +import org.jikesrvm.classloader.VM_MemberReference; +import org.jikesrvm.classloader.VM_FieldReference; +import org.jikesrvm.classloader.VM_BootstrapClassLoader; +import org.jikesrvm.classloader.VM_Atom; // OPT interface -import com.ibm.jikesrvm.opt.OPT_Constants; -import com.ibm.jikesrvm.opt.ir.OPT_GenerationContext; -import com.ibm.jikesrvm.opt.ir.OPT_HIRGenerator; -import com.ibm.jikesrvm.opt.ir.OPT_IR; -import com.ibm.jikesrvm.opt.ir.OPT_BasicBlock; +import org.jikesrvm.opt.OPT_Constants; +import org.jikesrvm.opt.ir.OPT_GenerationContext; +import org.jikesrvm.opt.ir.OPT_HIRGenerator; +import org.jikesrvm.opt.ir.OPT_IR; +import org.jikesrvm.opt.ir.OPT_BasicBlock; // Instructions -import com.ibm.jikesrvm.opt.ir.OPT_Instruction; -import com.ibm.jikesrvm.opt.ir.OPT_Operator; -import com.ibm.jikesrvm.opt.ir.OPT_Operators; -import com.ibm.jikesrvm.opt.ir.ALoad; -import com.ibm.jikesrvm.opt.ir.AStore; -import com.ibm.jikesrvm.opt.ir.Athrow; -import com.ibm.jikesrvm.opt.ir.Binary; -import com.ibm.jikesrvm.opt.ir.BBend; -import com.ibm.jikesrvm.opt.ir.Call; -import com.ibm.jikesrvm.opt.ir.CondMove; -import com.ibm.jikesrvm.opt.ir.GetField; -import com.ibm.jikesrvm.opt.ir.Goto; -import com.ibm.jikesrvm.opt.ir.IfCmp; -import com.ibm.jikesrvm.opt.ir.Move; -import com.ibm.jikesrvm.opt.ir.New; -import com.ibm.jikesrvm.opt.ir.LookupSwitch; -import com.ibm.jikesrvm.opt.ir.PutField; -import com.ibm.jikesrvm.opt.ir.Unary; +import org.jikesrvm.opt.ir.OPT_Instruction; +import org.jikesrvm.opt.ir.OPT_Operator; +import org.jikesrvm.opt.ir.OPT_Operators; +import org.jikesrvm.opt.ir.ALoad; +import org.jikesrvm.opt.ir.AStore; +import org.jikesrvm.opt.ir.Athrow; +import org.jikesrvm.opt.ir.Binary; +import org.jikesrvm.opt.ir.BBend; +import org.jikesrvm.opt.ir.Call; +import org.jikesrvm.opt.ir.CondMove; +import org.jikesrvm.opt.ir.GetField; +import org.jikesrvm.opt.ir.Goto; +import org.jikesrvm.opt.ir.IfCmp; +import org.jikesrvm.opt.ir.Move; +import org.jikesrvm.opt.ir.New; +import org.jikesrvm.opt.ir.LookupSwitch; +import org.jikesrvm.opt.ir.PutField; +import org.jikesrvm.opt.ir.Unary; // Operands -import com.ibm.jikesrvm.opt.ir.OPT_AddressConstantOperand; -import com.ibm.jikesrvm.opt.ir.OPT_BranchOperand; -import com.ibm.jikesrvm.opt.ir.OPT_BranchProfileOperand; -import com.ibm.jikesrvm.opt.ir.OPT_ConditionOperand; -import com.ibm.jikesrvm.opt.ir.OPT_IntConstantOperand; -import com.ibm.jikesrvm.opt.ir.OPT_LocationOperand; -import com.ibm.jikesrvm.opt.ir.OPT_MethodOperand; -import com.ibm.jikesrvm.opt.ir.OPT_Operand; -import com.ibm.jikesrvm.opt.ir.OPT_Register; -import com.ibm.jikesrvm.opt.ir.OPT_RegisterOperand; -import com.ibm.jikesrvm.opt.ir.OPT_TrueGuardOperand; -import com.ibm.jikesrvm.opt.ir.OPT_TypeOperand; +import org.jikesrvm.opt.ir.OPT_AddressConstantOperand; +import org.jikesrvm.opt.ir.OPT_BranchOperand; +import org.jikesrvm.opt.ir.OPT_BranchProfileOperand; +import org.jikesrvm.opt.ir.OPT_ConditionOperand; +import org.jikesrvm.opt.ir.OPT_IntConstantOperand; +import org.jikesrvm.opt.ir.OPT_LocationOperand; +import org.jikesrvm.opt.ir.OPT_MethodOperand; +import org.jikesrvm.opt.ir.OPT_Operand; +import org.jikesrvm.opt.ir.OPT_Register; +import org.jikesrvm.opt.ir.OPT_RegisterOperand; +import org.jikesrvm.opt.ir.OPT_TrueGuardOperand; +import org.jikesrvm.opt.ir.OPT_TypeOperand; public class X862IR extends DecoderUtils implements OPT_HIRGenerator, OPT_Operators, OPT_Constants { Modified: src/org/binarytranslator/arch/x86/decoder/X86_DecodedOperand.java =================================================================== --- src/org/binarytranslator/arch/x86/decoder/X86_DecodedOperand.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/arch/x86/decoder/X86_DecodedOperand.java 2007-03-16 15:33:01 UTC (rev 2) @@ -12,13 +12,13 @@ import org.binarytranslator.arch.x86.os.process.X86_Registers; -import com.ibm.jikesrvm.opt.ir.OPT_Operators; -import com.ibm.jikesrvm.opt.ir.Binary; -import com.ibm.jikesrvm.opt.ir.Move; +import org.jikesrvm.opt.ir.OPT_Operators; +import org.jikesrvm.opt.ir.Binary; +import org.jikesrvm.opt.ir.Move; -import com.ibm.jikesrvm.opt.ir.OPT_Operand; -import com.ibm.jikesrvm.opt.ir.OPT_IntConstantOperand; -import com.ibm.jikesrvm.opt.ir.OPT_RegisterOperand; +import org.jikesrvm.opt.ir.OPT_Operand; +import org.jikesrvm.opt.ir.OPT_IntConstantOperand; +import org.jikesrvm.opt.ir.OPT_RegisterOperand; /** * Wrapper for X86 decoded operands that are either in memory, Modified: src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java =================================================================== --- src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java 2007-03-16 15:33:01 UTC (rev 2) @@ -19,29 +19,29 @@ import org.binarytranslator.arch.x86.os.process.X86_ProcessSpace; import org.binarytranslator.arch.x86.os.process.X86_Registers; -import com.ibm.jikesrvm.classloader.VM_TypeReference; +import org.jikesrvm.classloader.VM_TypeReference; -import com.ibm.jikesrvm.opt.ir.Binary; -import com.ibm.jikesrvm.opt.ir.BooleanCmp; -import com.ibm.jikesrvm.opt.ir.BooleanCmp2; -import com.ibm.jikesrvm.opt.ir.CondMove; -import com.ibm.jikesrvm.opt.ir.IfCmp; -import com.ibm.jikesrvm.opt.ir.Goto; -import com.ibm.jikesrvm.opt.ir.Move; -import com.ibm.jikesrvm.opt.ir.Unary; +import org.jikesrvm.opt.ir.Binary; +import org.jikesrvm.opt.ir.BooleanCmp; +import org.jikesrvm.opt.ir.BooleanCmp2; +import org.jikesrvm.opt.ir.CondMove; +import org.jikesrvm.opt.ir.IfCmp; +import org.jikesrvm.opt.ir.Goto; +import org.jikesrvm.opt.ir.Move; +import org.jikesrvm.opt.ir.Unary; -import com.ibm.jikesrvm.opt.ir.OPT_Operator; -import com.ibm.jikesrvm.opt.ir.OPT_Operators; +import org.jikesrvm.opt.ir.OPT_Operator; +import org.jikesrvm.opt.ir.OPT_Operators; -import com.ibm.jikesrvm.opt.ir.OPT_BasicBlock; -import com.ibm.jikesrvm.opt.ir.OPT_Instruction; +import org.jikesrvm.opt.ir.OPT_BasicBlock; +import org.jikesrvm.opt.ir.OPT_Instruction; -import com.ibm.jikesrvm.opt.ir.OPT_Operand; -import com.ibm.jikesrvm.opt.ir.OPT_BranchOperand; -import com.ibm.jikesrvm.opt.ir.OPT_BranchProfileOperand; -import com.ibm.jikesrvm.opt.ir.OPT_ConditionOperand; -import com.ibm.jikesrvm.opt.ir.OPT_IntConstantOperand; -import com.ibm.jikesrvm.opt.ir.OPT_RegisterOperand; +import org.jikesrvm.opt.ir.OPT_Operand; +import org.jikesrvm.opt.ir.OPT_BranchOperand; +import org.jikesrvm.opt.ir.OPT_BranchProfileOperand; +import org.jikesrvm.opt.ir.OPT_ConditionOperand; +import org.jikesrvm.opt.ir.OPT_IntConstantOperand; +import org.jikesrvm.opt.ir.OPT_RegisterOperand; /** * Decoder for X86 instructions Modified: src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java 2007-03-16 15:33:01 UTC (rev 2) @@ -10,8 +10,8 @@ import java.io.*; -import com.ibm.jikesrvm.opt.ir.OPT_GenerationContext; -import com.ibm.jikesrvm.opt.ir.OPT_HIRGenerator; +import org.jikesrvm.opt.ir.OPT_GenerationContext; +import org.jikesrvm.opt.ir.OPT_HIRGenerator; import org.binarytranslator.DBT_Options; import org.binarytranslator.generic.os.process.ProcessSpace; Modified: src/org/binarytranslator/generic/decoder/DecoderUtils.java =================================================================== --- src/org/binarytranslator/generic/decoder/DecoderUtils.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/generic/decoder/DecoderUtils.java 2007-03-16 15:33:01 UTC (rev 2) @@ -19,48 +19,48 @@ import org.binarytranslator.generic.os.process.ProcessSpace; import org.binarytranslator.DBT_Options; -import com.ibm.jikesrvm.VM; +import org.jikesrvm.VM; -import com.ibm.jikesrvm.classloader.VM_Atom; -import com.ibm.jikesrvm.classloader.VM_BootstrapClassLoader; -import com.ibm.jikesrvm.classloader.VM_Class; -import com.ibm.jikesrvm.classloader.VM_MemberReference; -import com.ibm.jikesrvm.classloader.VM_Method; -import com.ibm.jikesrvm.classloader.VM_MethodReference; -import com.ibm.jikesrvm.classloader.VM_TypeReference; +import org.jikesrvm.classloader.VM_Atom; +import org.jikesrvm.classloader.VM_BootstrapClassLoader; +import org.jikesrvm.classloader.VM_Class; +import org.jikesrvm.classloader.VM_MemberReference; +import org.jikesrvm.classloader.VM_Method; +import org.jikesrvm.classloader.VM_MethodReference; +import org.jikesrvm.classloader.VM_TypeReference; -import com.ibm.jikesrvm.opt.OPT_Constants; -import com.ibm.jikesrvm.opt.ir.OPT_GenerationContext; -import com.ibm.jikesrvm.opt.ir.OPT_HIRGenerator; -import com.ibm.jikesrvm.opt.ir.OPT_IR; -import com.ibm.jikesrvm.opt.ir.OPT_BasicBlock; +import org.jikesrvm.opt.OPT_Constants; +import org.jikesrvm.opt.ir.OPT_GenerationContext; +import org.jikesrvm.opt.ir.OPT_HIRGenerator; +import org.jikesrvm.opt.ir.OPT_IR; +import org.jikesrvm.opt.ir.OPT_BasicBlock; -import com.ibm.jikesrvm.opt.ir.OPT_Instruction; -import com.ibm.jikesrvm.opt.ir.OPT_Operators; -import com.ibm.jikesrvm.opt.ir.OPT_Operator; -import com.ibm.jikesrvm.opt.ir.Athrow; -import com.ibm.jikesrvm.opt.ir.BBend; -import com.ibm.jikesrvm.opt.ir.Call; -import com.ibm.jikesrvm.opt.ir.CondMove; -import com.ibm.jikesrvm.opt.ir.Goto; -import com.ibm.jikesrvm.opt.ir.GetField; -import com.ibm.jikesrvm.opt.ir.IfCmp; -import com.ibm.jikesrvm.opt.ir.LookupSwitch; -import com.ibm.jikesrvm.opt.ir.Move; -import com.ibm.jikesrvm.opt.ir.New; -import com.ibm.jikesrvm.opt.ir.PutField; +import org.jikesrvm.opt.ir.OPT_Instruction; +import org.jikesrvm.opt.ir.OPT_Operators; +import org.jikesrvm.opt.ir.OPT_Operator; +import org.jikesrvm.opt.ir.Athrow; +import org.jikesrvm.opt.ir.BBend; +import org.jikesrvm.opt.ir.Call; +import org.jikesrvm.opt.ir.CondMove; +import org.jikesrvm.opt.ir.Goto; +import org.jikesrvm.opt.ir.GetField; +import org.jikesrvm.opt.ir.IfCmp; +import org.jikesrvm.opt.ir.LookupSwitch; +import org.jikesrvm.opt.ir.Move; +import org.jikesrvm.opt.ir.New; +import org.jikesrvm.opt.ir.PutField; -import com.ibm.jikesrvm.opt.ir.OPT_Operand; -import com.ibm.jikesrvm.opt.ir.OPT_AddressConstantOperand; -import com.ibm.jikesrvm.opt.ir.OPT_BranchOperand; -import com.ibm.jikesrvm.opt.ir.OPT_BranchProfileOperand; -import com.ibm.jikesrvm.opt.ir.OPT_ConditionOperand; -import com.ibm.jikesrvm.opt.ir.OPT_IntConstantOperand; -import com.ibm.jikesrvm.opt.ir.OPT_MethodOperand; -import com.ibm.jikesrvm.opt.ir.OPT_Register; -import com.ibm.jikesrvm.opt.ir.OPT_RegisterOperand; -import com.ibm.jikesrvm.opt.ir.OPT_TrueGuardOperand; -import com.ibm.jikesrvm.opt.ir.OPT_TypeOperand; +import org.jikesrvm.opt.ir.OPT_Operand; +import org.jikesrvm.opt.ir.OPT_AddressConstantOperand; +import org.jikesrvm.opt.ir.OPT_BranchOperand; +import org.jikesrvm.opt.ir.OPT_BranchProfileOperand; +import org.jikesrvm.opt.ir.OPT_ConditionOperand; +import org.jikesrvm.opt.ir.OPT_IntConstantOperand; +import org.jikesrvm.opt.ir.OPT_MethodOperand; +import org.jikesrvm.opt.ir.OPT_Register; +import org.jikesrvm.opt.ir.OPT_RegisterOperand; +import org.jikesrvm.opt.ir.OPT_TrueGuardOperand; +import org.jikesrvm.opt.ir.OPT_TypeOperand; /** * A collection of common tools used by decoders. The public entry Modified: src/org/binarytranslator/generic/memory/CallBasedMemory.java =================================================================== --- src/org/binarytranslator/generic/memory/CallBasedMemory.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/generic/memory/CallBasedMemory.java 2007-03-16 15:33:01 UTC (rev 2) @@ -8,26 +8,26 @@ */ package org.binarytranslator.generic.memory; -import com.ibm.jikesrvm.VM; -import com.ibm.jikesrvm.classloader.VM_Atom; -import com.ibm.jikesrvm.classloader.VM_BootstrapClassLoader; -import com.ibm.jikesrvm.classloader.VM_FieldReference; -import com.ibm.jikesrvm.classloader.VM_MemberReference; -import com.ibm.jikesrvm.classloader.VM_Method; -import com.ibm.jikesrvm.classloader.VM_MethodReference; -import com.ibm.jikesrvm.classloader.VM_TypeReference; -import com.ibm.jikesrvm.opt.ir.Call; -import com.ibm.jikesrvm.opt.ir.GetField; -import com.ibm.jikesrvm.opt.ir.Unary; -import com.ibm.jikesrvm.opt.ir.OPT_AddressConstantOperand; -import com.ibm.jikesrvm.opt.ir.OPT_GenerationContext; -import com.ibm.jikesrvm.opt.ir.OPT_Instruction; -import com.ibm.jikesrvm.opt.ir.OPT_LocationOperand; -import com.ibm.jikesrvm.opt.ir.OPT_MethodOperand; -import com.ibm.jikesrvm.opt.ir.OPT_Operators; -import com.ibm.jikesrvm.opt.ir.OPT_Register; -import com.ibm.jikesrvm.opt.ir.OPT_RegisterOperand; -import com.ibm.jikesrvm.opt.ir.OPT_TrueGuardOperand; +import org.jikesrvm.VM; +import org.jikesrvm.classloader.VM_Atom; +import org.jikesrvm.classloader.VM_BootstrapClassLoader; +import org.jikesrvm.classloader.VM_FieldReference; +import org.jikesrvm.classloader.VM_MemberReference; +import org.jikesrvm.classloader.VM_Method; +import org.jikesrvm.classloader.VM_MethodReference; +import org.jikesrvm.classloader.VM_TypeReference; +import org.jikesrvm.opt.ir.Call; +import org.jikesrvm.opt.ir.GetField; +import org.jikesrvm.opt.ir.Unary; +import org.jikesrvm.opt.ir.OPT_AddressConstantOperand; +import org.jikesrvm.opt.ir.OPT_GenerationContext; +import org.jikesrvm.opt.ir.OPT_Instruction; +import org.jikesrvm.opt.ir.OPT_LocationOperand; +import org.jikesrvm.opt.ir.OPT_MethodOperand; +import org.jikesrvm.opt.ir.OPT_Operators; +import org.jikesrvm.opt.ir.OPT_Register; +import org.jikesrvm.opt.ir.OPT_RegisterOperand; +import org.jikesrvm.opt.ir.OPT_TrueGuardOperand; import org.binarytranslator.generic.decoder.DecoderUtils; /** Modified: src/org/binarytranslator/generic/memory/IntAddressedPreSwappedMemory.java =================================================================== --- src/org/binarytranslator/generic/memory/IntAddressedPreSwappedMemory.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/generic/memory/IntAddressedPreSwappedMemory.java 2007-03-16 15:33:01 UTC (rev 2) @@ -8,24 +8,24 @@ */ package org.binarytranslator.generic.memory; -import com.ibm.jikesrvm.classloader.VM_Atom; -import com.ibm.jikesrvm.classloader.VM_FieldReference; -import com.ibm.jikesrvm.classloader.VM_MemberReference; -import com.ibm.jikesrvm.classloader.VM_TypeReference; -import com.ibm.jikesrvm.opt.ir.ALoad; -import com.ibm.jikesrvm.opt.ir.Binary; -import com.ibm.jikesrvm.opt.ir.GetField; -import com.ibm.jikesrvm.opt.ir.Goto; -import com.ibm.jikesrvm.opt.ir.IfCmp; -import com.ibm.jikesrvm.opt.ir.OPT_AddressConstantOperand; -import com.ibm.jikesrvm.opt.ir.OPT_BasicBlock; -import com.ibm.jikesrvm.opt.ir.OPT_ConditionOperand; -import com.ibm.jikesrvm.opt.ir.OPT_IntConstantOperand; -import com.ibm.jikesrvm.opt.ir.OPT_LocationOperand; -import com.ibm.jikesrvm.opt.ir.OPT_Register; -import com.ibm.jikesrvm.opt.ir.OPT_RegisterOperand; -import com.ibm.jikesrvm.opt.ir.OPT_TrueGuardOperand; -import com.ibm.jikesrvm.opt.ir.Unary; +import org.jikesrvm.classloader.VM_Atom; +import org.jikesrvm.classloader.VM_FieldReference; +import org.jikesrvm.classloader.VM_MemberReference; +import org.jikesrvm.classloader.VM_TypeReference; +import org.jikesrvm.opt.ir.ALoad; +import org.jikesrvm.opt.ir.Binary; +import org.jikesrvm.opt.ir.GetField; +import org.jikesrvm.opt.ir.Goto; +import org.jikesrvm.opt.ir.IfCmp; +import org.jikesrvm.opt.ir.OPT_AddressConstantOperand; +import org.jikesrvm.opt.ir.OPT_BasicBlock; +import org.jikesrvm.opt.ir.OPT_ConditionOperand; +import org.jikesrvm.opt.ir.OPT_IntConstantOperand; +import org.jikesrvm.opt.ir.OPT_LocationOperand; +import org.jikesrvm.opt.ir.OPT_Register; +import org.jikesrvm.opt.ir.OPT_RegisterOperand; +import org.jikesrvm.opt.ir.OPT_TrueGuardOperand; +import org.jikesrvm.opt.ir.Unary; import java.io.RandomAccessFile; import org.binarytranslator.generic.memory.IntAddressedMemory; import org.binarytranslator.vmInterface.TranslationHelper; Modified: src/org/binarytranslator/generic/memory/Memory.java =================================================================== --- src/org/binarytranslator/generic/memory/Memory.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/generic/memory/Memory.java 2007-03-16 15:33:01 UTC (rev 2) @@ -8,7 +8,7 @@ */ package org.binarytranslator.generic.memory; -import com.ibm.jikesrvm.opt.ir.OPT_RegisterOperand; +import org.jikesrvm.opt.ir.OPT_RegisterOperand; import org.binarytranslator.generic.decoder.DecoderUtils; import java.io.RandomAccessFile; Modified: src/org/binarytranslator/generic/os/process/ProcessSpace.java =================================================================== --- src/org/binarytranslator/generic/os/process/ProcessSpace.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-03-16 15:33:01 UTC (rev 2) @@ -11,10 +11,10 @@ import java.util.Hashtable; import java.io.*; -import com.ibm.jikesrvm.VM_CompiledMethod; -import com.ibm.jikesrvm.VM_CodeArray; -import com.ibm.jikesrvm.opt.ir.OPT_GenerationContext; -import com.ibm.jikesrvm.opt.ir.OPT_HIRGenerator; +import org.jikesrvm.VM_CompiledMethod; +import org.jikesrvm.VM_CodeArray; +import org.jikesrvm.opt.ir.OPT_GenerationContext; +import org.jikesrvm.opt.ir.OPT_HIRGenerator; import org.binarytranslator.vmInterface.DBT_Trace; import org.binarytranslator.vmInterface.DynamicCodeRunner; Modified: src/org/binarytranslator/vmInterface/DBT_ConvertBinaryToHIR.java =================================================================== --- src/org/binarytranslator/vmInterface/DBT_ConvertBinaryToHIR.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/vmInterface/DBT_ConvertBinaryToHIR.java 2007-03-16 15:33:01 UTC (rev 2) @@ -7,7 +7,7 @@ * (C) Copyright Ian Rogers, The University of Manchester 2003-2006 */ package org.binarytranslator.vmInterface; -import com.ibm.jikesrvm.opt.OPT_CompilerPhase; +import org.jikesrvm.opt.OPT_CompilerPhase; /** * The OPT_CompilerPhase which translates from PowerPC machine code Modified: src/org/binarytranslator/vmInterface/DBT_OptimizingCompilerException.java =================================================================== --- src/org/binarytranslator/vmInterface/DBT_OptimizingCompilerException.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/vmInterface/DBT_OptimizingCompilerException.java 2007-03-16 15:33:01 UTC (rev 2) @@ -8,7 +8,7 @@ */ package org.binarytranslator.vmInterface; -import com.ibm.jikesrvm.opt.OPT_OptimizingCompilerException; +import org.jikesrvm.opt.OPT_OptimizingCompilerException; /** * Use this exception if we encounter a runtime error in the binary translator Modified: src/org/binarytranslator/vmInterface/DBT_Trace.java =================================================================== --- src/org/binarytranslator/vmInterface/DBT_Trace.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/vmInterface/DBT_Trace.java 2007-03-16 15:33:01 UTC (rev 2) @@ -9,17 +9,17 @@ package org.binarytranslator.vmInterface; import org.binarytranslator.DBT_Options; import org.binarytranslator.generic.os.process.ProcessSpace; -import com.ibm.jikesrvm.classloader.VM_BootstrapClassLoader; -import com.ibm.jikesrvm.VM_CompiledMethod; -import com.ibm.jikesrvm.VM_CompiledMethods; -import com.ibm.jikesrvm.classloader.VM_NormalMethod; -import com.ibm.jikesrvm.classloader.VM_Class; -import com.ibm.jikesrvm.classloader.VM_TypeReference; -import com.ibm.jikesrvm.classloader.VM_MemberReference; -import com.ibm.jikesrvm.classloader.VM_Atom; -import com.ibm.jikesrvm.VM_Statics; -import com.ibm.jikesrvm.opt.ir.OPT_GenerationContext; -import com.ibm.jikesrvm.opt.ir.OPT_HIRGenerator; +import org.jikesrvm.classloader.VM_BootstrapClassLoader; +import org.jikesrvm.VM_CompiledMethod; +import org.jikesrvm.VM_CompiledMethods; +import org.jikesrvm.classloader.VM_NormalMethod; +import org.jikesrvm.classloader.VM_Class; +import org.jikesrvm.classloader.VM_TypeReference; +import org.jikesrvm.classloader.VM_MemberReference; +import org.jikesrvm.classloader.VM_Atom; +import org.jikesrvm.VM_Statics; +import org.jikesrvm.opt.ir.OPT_GenerationContext; +import org.jikesrvm.opt.ir.OPT_HIRGenerator; /** * A method class which can be used in place of a VM_NormalMethod but @@ -84,7 +84,7 @@ public static void configure() { VM_Atom clsDescriptor = VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/vmInterface/DummyDynamicCodeRunner;"); VM_Atom memName = VM_Atom.findOrCreateAsciiAtom("invokeCode"); - invokeCodeDescriptor = VM_Atom.findOrCreateAsciiAtom("(Lcom.ibm.jikesrvm/VM_CodeArray;Lorg/binarytranslator/generic/os/process/ProcessSpace;)I"); + invokeCodeDescriptor = VM_Atom.findOrCreateAsciiAtom("(Lorg/jikesrvm/VM_CodeArray;Lorg/binarytranslator/generic/os/process/ProcessSpace;)I"); VM_TypeReference tRef = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), clsDescriptor); dummyRunnerTypeRef = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), Modified: src/org/binarytranslator/vmInterface/DynamicCodeRunner.java =================================================================== --- src/org/binarytranslator/vmInterface/DynamicCodeRunner.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/vmInterface/DynamicCodeRunner.java 2007-03-16 15:33:01 UTC (rev 2) @@ -7,10 +7,10 @@ * (C) Copyright Ian Rogers, The University of Manchester 2003-2006 */ package org.binarytranslator.vmInterface; -import com.ibm.jikesrvm.VM; -import com.ibm.jikesrvm.VM_DynamicBridge; -import com.ibm.jikesrvm.VM_CodeArray; -import com.ibm.jikesrvm.VM_Magic; +import org.jikesrvm.VM; +import org.jikesrvm.VM_DynamicBridge; +import org.jikesrvm.VM_CodeArray; +import org.jikesrvm.VM_Magic; import org.vmmagic.pragma.Uninterruptible; import org.vmmagic.pragma.NoInlinePragma; import org.binarytranslator.DBT_Options; Modified: src/org/binarytranslator/vmInterface/TranslationHelper.java =================================================================== --- src/org/binarytranslator/vmInterface/TranslationHelper.java 2006-12-07 14:54:50 UTC (rev 1) +++ src/org/binarytranslator/vmInterface/TranslationHelper.java 2007-03-16 15:33:01 UTC (rev 2) @@ -8,13 +8,13 @@ */ package org.binarytranslator.vmInterface; -import com.ibm.jikesrvm.classloader.VM_Method; -import com.ibm.jikesrvm.classloader.VM_TypeReference; -import com.ibm.jikesrvm.opt.ir.OPT_BasicBlock; -import com.ibm.jikesrvm.opt.ir.OPT_BranchProfileOperand; -import com.ibm.jikesrvm.opt.ir.OPT_GenerationContext; -import com.ibm.jikesrvm.opt.ir.OPT_Instruction; -import com.ibm.jikesrvm.opt.ir.OPT_RegisterOperand; +import org.jikesrvm.classloader.VM_Method; +import org.jikesrvm.classloader.VM_TypeReference; +import org.jikesrvm.opt.ir.OPT_BasicBlock; +import org.jikesrvm.opt.ir.OPT_BranchProfileOperand; +import org.jikesrvm.opt.ir.OPT_GenerationContext; +import org.jikesrvm.opt.ir.OPT_Instruction; +import org.jikesrvm.opt.ir.OPT_RegisterOperand; /** * Translation helper interface This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Mohammad M. A. <an...@cs...> - 2006-12-08 08:53:57
|
------- Forwarded message ------- From: "Mohammad Momin Ansari" <an...@cs...> To: cap...@us... Cc: Subject: Re: [Pearcolator-devel] SF.net SVN: pearcolator: [1] src/org Date: Fri, 08 Dec 2006 08:47:18 -0000 Hi list! My first comment of the list. So the initial import has a lot of copyright Ian Rogers going on. Does it also have copyright John Bircham, etc? -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ |
From: <cap...@us...> - 2006-12-07 14:55:42
|
Revision: 1 http://svn.sourceforge.net/pearcolator/?rev=1&view=rev Author: captain5050 Date: 2006-12-07 06:54:50 -0800 (Thu, 07 Dec 2006) Log Message: ----------- Initial import Added Paths: ----------- LICENSE bin/ bin/dbt bin/jconfigure ext/ ext/com/ ext/com/ibm/ ext/com/ibm/jikesrvm/ ext/com/ibm/jikesrvm/opt/ ext/com/ibm/jikesrvm/opt/ir/ ext/com/ibm/jikesrvm/opt/ir/OPT_HIRGenerator.java src/ src/org/ src/org/binarytranslator/ src/org/binarytranslator/DBT_Options.java src/org/binarytranslator/Main.java src/org/binarytranslator/arch/ src/org/binarytranslator/arch/ppc/ src/org/binarytranslator/arch/ppc/decoder/ src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java src/org/binarytranslator/arch/ppc/decoder/PPC_Constants.java src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java src/org/binarytranslator/arch/ppc/decoder/PPC_Laziness.java src/org/binarytranslator/arch/ppc/os/ src/org/binarytranslator/arch/ppc/os/abi/ src/org/binarytranslator/arch/ppc/os/abi/linux/ src/org/binarytranslator/arch/ppc/os/abi/linux/PPC_LinuxSystemCalls.java src/org/binarytranslator/arch/ppc/os/process/ src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java src/org/binarytranslator/arch/ppc/os/process/linux/ src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java src/org/binarytranslator/arch/x86/ src/org/binarytranslator/arch/x86/decoder/ src/org/binarytranslator/arch/x86/decoder/X862IR.java src/org/binarytranslator/arch/x86/decoder/X86_Constants.java src/org/binarytranslator/arch/x86/decoder/X86_DecodedOperand.java src/org/binarytranslator/arch/x86/decoder/X86_FlagLaziness.java src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java src/org/binarytranslator/arch/x86/decoder/X86_Laziness.java src/org/binarytranslator/arch/x86/decoder/X86_ModRM_Decoder.java src/org/binarytranslator/arch/x86/decoder/X86_RegisterSyncLaziness.java src/org/binarytranslator/arch/x86/decoder/X86_Registers.java src/org/binarytranslator/arch/x86/decoder/X86_SIB_Decoder.java src/org/binarytranslator/arch/x86/os/ src/org/binarytranslator/arch/x86/os/abi/ src/org/binarytranslator/arch/x86/os/abi/linux/ src/org/binarytranslator/arch/x86/os/abi/linux/X86_LinuxSystemCalls.java src/org/binarytranslator/arch/x86/os/process/ src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java src/org/binarytranslator/arch/x86/os/process/X86_Registers.java src/org/binarytranslator/arch/x86/os/process/linux/ src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java src/org/binarytranslator/generic/ src/org/binarytranslator/generic/branch/ src/org/binarytranslator/generic/branch/BranchLogic.java src/org/binarytranslator/generic/branch/CallAndReturnAddress.java src/org/binarytranslator/generic/branch/ProcedureInformation.java src/org/binarytranslator/generic/branch/ProcedureInformationComparator.java src/org/binarytranslator/generic/decoder/ src/org/binarytranslator/generic/decoder/DecoderUtils.java src/org/binarytranslator/generic/decoder/InstructionDecoder.java src/org/binarytranslator/generic/decoder/Laziness.java src/org/binarytranslator/generic/fault/ src/org/binarytranslator/generic/fault/BadInstructionException.java src/org/binarytranslator/generic/gdbstub/ src/org/binarytranslator/generic/gdbstub/GDBStub.java src/org/binarytranslator/generic/memory/ src/org/binarytranslator/generic/memory/ByteAddressedByteSwapMemory.java src/org/binarytranslator/generic/memory/ByteAddressedMemory.java src/org/binarytranslator/generic/memory/ByteAddressedReversedMemory.java src/org/binarytranslator/generic/memory/CallBasedMemory.java src/org/binarytranslator/generic/memory/IntAddressedByteSwapMemory.java src/org/binarytranslator/generic/memory/IntAddressedMemory.java src/org/binarytranslator/generic/memory/IntAddressedPreSwappedMemory.java src/org/binarytranslator/generic/memory/IntAddressedReversedMemory.java src/org/binarytranslator/generic/memory/Memory.java src/org/binarytranslator/generic/memory/MemoryMapException.java src/org/binarytranslator/generic/os/ src/org/binarytranslator/generic/os/abi/ src/org/binarytranslator/generic/os/abi/linux/ src/org/binarytranslator/generic/os/abi/linux/LinuxStackInitializer.java src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCallGenerator.java src/org/binarytranslator/generic/os/abi/linux/LinuxSystemCalls.java src/org/binarytranslator/generic/os/loader/ src/org/binarytranslator/generic/os/loader/Loader.java src/org/binarytranslator/generic/os/loader/elf/ src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java src/org/binarytranslator/generic/os/process/ src/org/binarytranslator/generic/os/process/ProcessSpace.java src/org/binarytranslator/vmInterface/ src/org/binarytranslator/vmInterface/DBT_ConvertBinaryToHIR.java src/org/binarytranslator/vmInterface/DBT_OptimizingCompilerException.java src/org/binarytranslator/vmInterface/DBT_Trace.java src/org/binarytranslator/vmInterface/DynamicCodeRunner.java src/org/binarytranslator/vmInterface/TranslationHelper.java Added: LICENSE =================================================================== --- LICENSE (rev 0) +++ LICENSE 2006-12-07 14:54:50 UTC (rev 1) @@ -0,0 +1,247 @@ + Common Public License - v 1.0 + + THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON + PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF + THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + + 1. DEFINITIONS + + "Contribution" means: + + a) in the case of the initial Contributor, the initial code and + documentation distributed under this Agreement, and + + b) in the case of each subsequent Contributor: + + i) changes to the Program, and + + ii) additions to the Program; + + where such changes and/or additions to the Program originate from + and are distributed by that particular Contributor. A Contribution + 'originates' from a Contributor if it was added to the Program by + such Contributor itself or anyone acting on such Contributor's + behalf. Contributions do not include additions to the Program + which: (i) are separate modules of software distributed in + conjunction with the Program under their own license agreement, and + (ii) are not derivative works of the Program. + + "Contributor" means any person or entity that distributes the + Program. + + "Licensed Patents" mean patent claims licensable by a Contributor + which are necessarily infringed by the use or sale of its + Contribution alone or when combined with the Program. + + "Program" means the Contributions distributed in accordance with + this Agreement. + + "Recipient" means anyone who receives the Program under this + Agreement, including all Contributors. + + + 2. GRANT OF RIGHTS + + a) Subject to the terms of this Agreement, each Contributor hereby + grants Recipient a non-exclusive, worldwide, royalty-free + copyright license to reproduce, prepare derivative works of, + publicly display, publicly perform, distribute and sublicense + the Contribution of such Contributor, if any, and such + derivative works, in source code and object code form. + + b) Subject to the terms of this Agreement, each Contributor hereby + grants Recipient a non-exclusive, worldwide, royalty-free + patent license under Licensed Patents to make, use, sell, offer + to sell, import and otherwise transfer the Contribution of such + Contributor, if any, in source code and object code form. This + patent license shall apply to the combination of the + Contribution and the Program if, at the time the Contribution + is added by the Contributor, such addition of the Contribution + causes such combination to be covered by the Licensed + Patents. The patent license shall not apply to any other + combinations which include the Contribution. No hardware per se + is licensed hereunder. + + c) Recipient understands that although each Contributor grants the + licenses to its Contributions set forth herein, no assurances + are provided by any Contributor that the Program does not + infringe the patent or other intellectual property rights of + any other entity. Each Contributor disclaims any liability to + Recipient for claims brought by any other entity based on + infringement of intellectual property rights or otherwise. As + a condition to exercising the rights and licenses granted + hereunder, each Recipient hereby assumes sole responsibility to + secure any other intellectual property rights needed, if any. + For example, if a third party patent license is required to + allow Recipient to distribute the Program, it is Recipient's + responsibility to acquire that license before distributing the + Program. + + d) Each Contributor represents that to its knowledge it has + sufficient copyright rights in its Contribution, if any, to + grant the copyright license set forth in this Agreement. + + 3. REQUIREMENTS + + A Contributor may choose to distribute the Program in object code + form under its own license agreement, provided that: + + a) it complies with the terms and conditions of this Agreement; and + + b) its license agreement: + + i) effectively disclaims on behalf of all Contributors all + warranties and conditions, express and implied, including + warranties or conditions of title and non-infringement, and + implied warranties or conditions of merchantability and fitness + for a particular purpose; + + ii) effectively excludes on behalf of all Contributors all + liability for damages, including direct, indirect, special, + incidental and consequential damages, such as lost profits; + + iii) states that any provisions which differ from this Agreement + are offered by that Contributor alone and not by any other + party; and + + iv) states that source code for the Program is available from such + Contributor, and informs licensees how to obtain it in a + reasonable manner on or through a medium customarily used for + software exchange. + + When the Program is made available in source code form: + + a) it must be made available under this Agreement; and + + b) a copy of this Agreement must be included with each copy of the + Program. + + Contributors may not remove or alter any copyright notices + contained within the Program. + + Each Contributor must identify itself as the originator of its + Contribution, if any, in a manner that reasonably allows subsequent + Recipients to identify the originator of the Contribution. + + 4. COMMERCIAL DISTRIBUTION + + Commercial distributors of software may accept certain + responsibilities with respect to end users, business partners and + the like. While this license is intended to facilitate the + commercial use of the Program, the Contributor who includes the + Program in a commercial product offering should do so in a manner + which does not create potential liability for other + Contributors. Therefore, if a Contributor includes the Program in a + commercial product offering, such Contributor ("Commercial + Contributor") hereby agrees to defend and indemnify every other + Contributor ("Indemnified Contributor") against any losses, damages + and costs (collectively "Losses") arising from claims, lawsuits and + other legal actions brought by a third party against the + Indemnified Contributor to the extent caused by the acts or + omissions of such Commercial Contributor in connection with its + distribution of the Program in a commercial product offering. The + obligations in this section do not apply to any claims or Losses + relating to any actual or alleged intellectual property + infringement. In order to qualify, an Indemnified Contributor + must: a) promptly notify the Commercial Contributor in writing of + such claim, and b) allow the Commercial Contributor to control, and + cooperate with the Commercial Contributor in, the defense and any + related settlement negotiations. The Indemnified Contributor may + participate in any such claim at its own expense. + + For example, a Contributor might include the Program in a + commercial product offering, Product X. That Contributor is then a + Commercial Contributor. If that Commercial Contributor then makes + performance claims, or offers warranties related to Product X, + those performance claims and warranties are such Commercial + Contributor's responsibility alone. Under this section, the + Commercial Contributor would have to defend claims against the + other Contributors related to those performance claims and + warranties, and if a court requires any other Contributor to pay + any damages as a result, the Commercial Contributor must pay those + damages. + + 5. NO WARRANTY + + EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS + PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF + ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, + ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, + MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each + Recipient is solely responsible for determining the appropriateness + of using and distributing the Program and assumes all risks + associated with its exercise of rights under this Agreement, + including but not limited to the risks and costs of program errors, + compliance with applicable laws, damage to or loss of data, + programs or equipment, and unavailability or interruption of + operations. + + 6. DISCLAIMER OF LIABILITY + + EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT + NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY + RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGES. + + 7. GENERAL + + If any provision of this Agreement is invalid or unenforceable + under applicable law, it shall not affect the validity or + enforceability of the remainder of the terms of this Agreement, and + without further action by the parties hereto, such provision shall + be reformed to the minimum extent necessary to make such provision + valid and enforceable. + + If Recipient institutes patent litigation against a Contributor + with respect to a patent applicable to software (including a + cross-claim or counterclaim in a lawsuit), then any patent licenses + granted by that Contributor to such Recipient under this Agreement + shall terminate as of the date such litigation is filed. In + addition, if Recipient institutes patent litigation against any + entity (including a cross-claim or counterclaim in a lawsuit) + alleging that the Program itself (excluding combinations of the + Program with other software or hardware) infringes such Recipient's + patent(s), then such Recipient's rights granted under Section 2(b) + shall terminate as of the date such litigation is filed. + + All Recipient's rights under this Agreement shall terminate if it + fails to comply with any of the material terms or conditions of + this Agreement and does not cure such failure in a reasonable + period of time after becoming aware of such noncompliance. If all + Recipient's rights under this Agreement terminate, Recipient agrees + to cease use and distribution of the Program as soon as reasonably + practicable. However, Recipient's obligations under this Agreement + and any licenses granted by Recipient relating to the Program shall + continue and survive. + + Everyone is permitted to copy and distribute copies of this + Agreement, but in order to avoid inconsistency the Agreement is + copyrighted and may only be modified in the following manner. The + Agreement Steward reserves the right to publish new versions + (including revisions) of this Agreement from time to time. No one + other than the Agreement Steward has the right to modify this + Agreement. IBM is the initial Agreement Steward. IBM may assign + the responsibility to serve as the Agreement Steward to a suitable + separate entity. Each new version of the Agreement will be given a + distinguishing version number. The Program (including + Contributions) may always be distributed subject to the version of + the Agreement under which it was received. In addition, after a new + version of the Agreement is published, Contributor may elect to + distribute the Program (including its Contributions) under the new + version. Except as expressly stated in Sections 2(a) and 2(b) + above, Recipient receives no rights or licenses to the intellectual + property of any Contributor under this Agreement, whether + expressly, by implication, estoppel or otherwise. All rights in the + Program not expressly granted under this Agreement are reserved. + + This Agreement is governed by the laws of the State of New York and + the intellectual property laws of the United States of America. No + party to this Agreement will bring a legal action under this + Agreement more than one year after the cause of action arose. Each + party waives its rights to a jury trial in any resulting + litigation. Added: bin/dbt =================================================================== --- bin/dbt (rev 0) +++ bin/dbt 2006-12-07 14:54:50 UTC (rev 1) @@ -0,0 +1,11 @@ +#! /usr/bin/env bash +# +# 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 +# +# Run the org.binarytranslator emulator aka PearColator +$RVM_ROOT/rvm/bin/rvm org.binarytranslator.Main $@ Property changes on: bin/dbt ___________________________________________________________________ Name: svn:executable + Added: bin/jconfigure =================================================================== --- bin/jconfigure (rev 0) +++ bin/jconfigure 2006-12-07 14:54:50 UTC (rev 1) @@ -0,0 +1,352 @@ +#! /usr/bin/env bash +# +# 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 +# +# Configure the Jikes RVM with binary translation support +# +# This script is organized into the following sections: +# 0 - Simple checks +# 1 - Run RVM jconfigure +# 2 - Patch RVM.sources so that jbuild.copy copies DBT files +# 3 - Create jbuild.dbt to patch copied RVM files that require DBT modifications +# 4 - Modify jbuild to call jbuild.dbt +# +# @author Ian Rogers +# @date 24/06/2005 + +# What is our name? +# Bash internal shorthand that works like the "basename" command. +ME="${0##*/}" + +#-------------------------------------- +echo "Step 0: Simple checks" +if [[ ! -x ${RVM_ROOT}/rvm/bin/jconfigure ]]; then + echo >&2 "$ME: ERROR: Unable to find Jikes RVM jconfigure. Make sure RVM_ROOT is set correctly." + exit 2 +fi + +if [[ $1 = "" ]]; then + echo >&2 "$ME: ERROR: You must specify a Jikes RVM build configuration" + exit 2 +fi + +#-------------------------------------- +echo "Step 1: Run Jikes RVM jconfigure" + +cd ${RVM_ROOT}/rvm/bin +./jconfigure $1 +cd ${RVM_ROOT}/dbt/bin + +if [[ ! -f ${RVM_BUILD}/RVM.sources ]]; then + echo >&2 "$ME: ERROR: Unable to find valid RVM.sources in RVM_BUILD directory. Did Jikes RVM jconfigure fail?" + exit 2 +fi + +#-------------------------------------- +echo "Step 2: Patch RVM.sources" + +function emitDBTdirectories (){ + find ${RVM_ROOT}/dbt/src -type d | grep -v CVS + find ${RVM_ROOT}/dbt/ext -type d | grep -v CVS + echo ${RVM_ROOT}/rvm/src/vm/arch/powerPC/disassembler +} + +emitDBTdirectories >> ${RVM_BUILD}/RVM.sources + +#-------------------------------------- +echo "Step 3: Create jbuild.dbt" + +function emitDBT (){ + cat <<EOF2 +#! /usr/bin/env bash +# +# This file patches the copied Jikes RVM sources to make them suitable for use inside a DBT. + +# What is our name? +# Bash internal shorthand that works like the "basename" command. +ME="\${0##*/}" +. ${RVM_ROOT}/rvm/bin/libjconfigure.bash + +while (( \$# > 0 )); do + arg="\$1" + if [[ \$arg = -- ]]; then + shift # The end of the flag arguments + break; + fi + [[ \$arg != --?* ]] || arg="\${arg#-}" + if [[ \$arg == -trace* ]]; then + TRACE_FLAG="\$arg" + elif [[ \$arg = -v ]]; then + VFLAG=-v + elif [[ \$arg = -x ]]; then + XFLAG=-x + elif [[ \$arg = -clean ]]; then + CLEAN_FLAG=-clean + else + show_mesg >&2 "Unknown argument: \$arg" + trap '' EXIT + exit 33 + fi + shift +done + +if [[ ! \$CLEAN_FLAG ]]; then + if tracing jbuild; then + echo "\$ME: Modifying source files to make them amenable to building as a DBT" + fi + cd RVM.classes + # --- VM_NormalMethod --- + file=com/ibm/JikesRVM/classloader/VM_NormalMethod.java + # Make HIR generation phase alterable + run patch -u -p0 -l <<EOF +--- \$file ++++ \$file +@@ -5,6 +5,9 @@ + package com.ibm.JikesRVM.classloader; + + import com.ibm.JikesRVM.*; ++import com.ibm.JikesRVM.opt.ir.OPT_HIRGenerator; ++import com.ibm.JikesRVM.opt.ir.OPT_BC2IR; ++import com.ibm.JikesRVM.opt.ir.OPT_GenerationContext; + import java.io.DataInputStream; + import java.io.IOException; + import org.vmmagic.pragma.*; +@@ -324,6 +327,24 @@ + } + //-#endif RVM_WITH_OSR + ++ /** ++ * Create an optimizing compiler HIR code generator for this type of ++ * method ++ * @param context the generation context for the HIR generation ++ * @return a HIR generator ++ */ ++ public OPT_HIRGenerator createHIRGenerator(OPT_GenerationContext context){ ++ return new OPT_BC2IR(context); ++ } ++ ++ /** ++ * Must this method be OPT compiled? ++ * @param context the generation context for the HIR generation ++ * @return a HIR generator ++ */ ++ public boolean optCompileOnly() { ++ return false; ++ } + + /* + * Methods to access and compute method summary information +EOF + # Make VM_NormalMethod HAS fields accessible to DBT_Trace + run sed -i -e's/private static final int HAS_/protected static final int HAS_/g' \$file + # Make VM_NormalMethod non-final + run sed -i -e's/public final class VM_NormalMethod/public class VM_NormalMethod/g' \$file + # Make constructor public + run sed -i -e's/VM_NormalMethod(VM_TypeReference dc, VM_MemberReference mr,/public VM_NormalMethod(VM_TypeReference dc, VM_MemberReference mr,/g' \$file + # Make summary protected + run sed -i -e's/private int summary;/protected int summary;/g' \$file + # Make bytecodes public + run sed -i -e's/private final byte\[\] bytecodes;/public final byte\[\] bytecodes;/g' \$file + # Make genCode public + run sed -i -e's/protected VM_CompiledMethod genCode() throws VerifyError/public VM_CompiledMethod genCode() throws VerifyError/g' \$file + + # --- VM_RuntimeCompiler --- + file=com/ibm/JikesRVM/VM_RuntimeCompiler.java + # Make HIR generation phase alterable + run patch -u -p0 -l <<EOF +--- \$file ++++ \$file +@@ -792,3 +792,3 @@ + } +- if (VM_Controller.options.optIRC()) { ++ if (VM_Controller.options.optIRC() || method.optCompileOnly()) { + if (// will only run once: don't bother optimizing +@@ -811,3 +811,18 @@ + } +- cm = optCompileWithFallBack(method, compPlan); ++ if(!method.optCompileOnly()) { ++ cm = optCompileWithFallBack(method, compPlan); ++ } ++ else { ++ compilationInProgress = true; ++ try { ++ cm = optCompile(method, compPlan); ++ } catch (OPT_OptimizingCompilerException e) { ++ String msg = "Optimizing compiler " ++ +"(on method that can only be optimizing compiler compiled): " ++ +"can't optimize \"" + method + "\""; ++ throw new Error(msg, e); ++ } finally { ++ compilationInProgress = false; ++ } ++ } + } +EOF + # --- OPT_BC2IR --- + file=com/ibm/JikesRVM/opt/ir/OPT_BC2IR.java + # Make HIR generation phase alterable + run patch -u -p0 -l <<EOF +--- \$file ++++ \$file +@@ -61 +61,2 @@ +- OPT_Constants ++ OPT_Constants, ++ OPT_HIRGenerator +EOF + # Make OPT_BC2IR 'generateHIR' method public + run sed -i -e's/private void generateHIR()/public void generateHIR()/' \$file + # Make OPT_BC2IR constructor public + run sed -i -e's/private OPT_BC2IR(OPT_GenerationContext context)/public OPT_BC2IR(OPT_GenerationContext context)/' \$file + + # --- OPT_ConvertBCtoHIR --- + file=com/ibm/JikesRVM/opt/ir/OPT_ConvertBCtoHIR.java + # Make HIR generation phase alterable + run patch -u -p0 -l <<EOF +--- \$file ++++ \$file +@@ -28,7 +28,7 @@ + OPT_GenerationContext gc = + new OPT_GenerationContext(ir.method, ir.compiledMethod, + ir.options, ir.inlinePlan); +- OPT_BC2IR.generateHIR(gc); ++ ir.method.createHIRGenerator(gc).generateHIR(); + // Transfer HIR and misc state from gc to the ir object + ir.gc = gc; + ir.cfg = gc.cfg; +EOF + + # --- VM_Member --- + file=com/ibm/JikesRVM/classloader/VM_Member.java + # Make modifiers public + run sed -i -e's/protected final int modifiers;/public final int modifiers;/g' \$file + + # --- VM_Method --- + file=com/ibm/JikesRVM/classloader/VM_Method.java + # Make replaceCompiledMethod non-final + run sed -i -e's/public final synchronized void replaceCompiledMethod/public synchronized void replaceCompiledMethod/g' \$file + + # --- VM_DynamicBridge --- + file=com/ibm/JikesRVM/VM_DynamicBridge.java + # Make VM_DynamicBridge accessible to DynamicCodeRunner + run sed -i -e's/interface VM_DynamicBridge/public interface VM_DynamicBridge/' \$file + + # --- OPT_GenerationContext --- + file=com/ibm/JikesRVM/opt/ir/OPT_GenerationContext.java + # Make OPT_GenerationContext 'method' field public + run sed -i -e's/VM_NormalMethod method/public VM_NormalMethod method/' \$file + # Make OPT_GenerationContext 'temps' field public + run sed -i -e's/OPT_RegisterPool temps/public OPT_RegisterPool temps/' \$file + # Make OPT_GenerationContext 'arguments' field public + run sed -i -e's/OPT_Operand\[\] arguments/public OPT_Operand\[\] arguments/' \$file + # Make OPT_GenerationContext 'options' field public + run sed -i -e's/OPT_Options options/public OPT_Options options/' \$file + # Make OPT_GenerationContext 'epilogue' field public + run sed -i -e's/OPT_BasicBlock epilogue/public OPT_BasicBlock epilogue/' \$file + # Make OPT_GenerationContext 'prologue' field public + run sed -i -e's/OPT_BasicBlock prologue/public OPT_BasicBlock prologue/' \$file + # Make OPT_GenerationContext 'cfg' field public + run sed -i -e's/OPT_ControlFlowGraph cfg/public OPT_ControlFlowGraph cfg/' \$file + # Make OPT_GenerationContext 'resultReg' field public + run sed -i -e's/OPT_Register resultReg/public OPT_Register resultReg/' \$file + + # --- OPT_ConditionOperand --- + # Direct creation of floating point compares required by DBT + file=com/ibm/JikesRVM/opt/ir/OPT_ConditionOperand.java + run patch -u -p0 -l <<EOF +--- \$file ++++ \$file +@@ -150,6 +150,51 @@ + } + + /** ++ * Create the condition code operand for CMPL_EQUAL ++ * ++ * @return a newly created condition code operand ++ */ ++ public static OPT_ConditionOperand CMPL_EQUAL() { ++ return new OPT_ConditionOperand(CMPL_EQUAL); ++ } ++ ++ /** ++ * Create the condition code operand for CMPL_NOT_EQUAL ++ * ++ * @return a newly created condition code operand ++ */ ++ public static OPT_ConditionOperand CMPL_NOT_EQUAL() { ++ return new OPT_ConditionOperand(CMPL_NOT_EQUAL); ++ } ++ ++ /** ++ * Create the condition code operand for CMPL_GREATER ++ * ++ * @return a newly created condition code operand ++ */ ++ public static OPT_ConditionOperand CMPL_GREATER() { ++ return new OPT_ConditionOperand(CMPL_GREATER); ++ } ++ ++ /** ++ * Create the condition code operand for CMPL_GREATER_EQUAL ++ * ++ * @return a newly created condition code operand ++ */ ++ public static OPT_ConditionOperand CMPL_GREATER_EQUAL() { ++ return new OPT_ConditionOperand(CMPL_GREATER_EQUAL); ++ } ++ ++ /** ++ * Create the condition code operand for CMPG_LESS ++ * ++ * @return a newly created condition code operand ++ */ ++ public static OPT_ConditionOperand CMPG_LESS() { ++ return new OPT_ConditionOperand(CMPG_LESS); ++ } ++ ++ /** + * Is the condition code EQUAL? + * + * @return <code>true</code> if it is or <code>false</code> if it is not +EOF + + # --- PPC_Disassembler --- + # Allow disassembler to exist outside of PPC backend + file=com/ibm/JikesRVM/PPC_Disassembler.java + run patch -u -p0 -l <<EOF +--- \$file ++++ \$file +@@ -121,2 +121,13 @@ + static final int FPSCRX = 148; ++ static final String GPR_NAMES[] = { "R0", "R1", "R2", "R3", "R4", "R5", ++ "R6", "R7","R8", "R9", "R10", "R11", ++ "R12", "R13","R14", "R15","R16", "R17", ++ "R18", "R19", "R20", "R21", "R22", "R23", ++ "R24", "R25", "R26", "R27", "R28", "R29", "R30", "R31" ++ }; ++ static final String FPR_NAMES[] = { "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7", ++ "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", ++ "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23", ++ "F24", "F25", "F26", "F27", "F28", "F29", "F30", "F31" ++ }; + +EOF +fi + +trap '' EXIT +EOF2 +} + +emitDBT > ${RVM_BUILD}/jbuild.dbt +chmod +x ${RVM_BUILD}/jbuild.dbt +#-------------------------------------- +echo "Step 4: Patch jbuild" + +# Add jbuild.dbt to be performed after all cases of jbuild.copy +sed -i -e's/\(.*\)jbuild.copy\(.*\)/\1jbuild.copy\2\n\1jbuild.dbt\2/g' ${RVM_BUILD}/jbuild +# Add binary translator main to the list of jikes compiled sources +sed -i -e's/Dummy.java/Dummy.java org\/binarytranslator\/Main.java/' ${RVM_BUILD}/jbuild.compile Property changes on: bin/jconfigure ___________________________________________________________________ Name: svn:executable + Added: ext/com/ibm/jikesrvm/opt/ir/OPT_HIRGenerator.java =================================================================== --- ext/com/ibm/jikesrvm/opt/ir/OPT_HIRGenerator.java (rev 0) +++ ext/com/ibm/jikesrvm/opt/ir/OPT_HIRGenerator.java 2006-12-07 14:54:50 UTC (rev 1) @@ -0,0 +1,15 @@ +/* + * (C) The University of Manchester 2003 - 2006 + */ +package com.ibm.jikesrvm.opt.ir; + +/** + * Interface implemented by all optimizing compiler HIR generators + * such as OPT_BC2HIR and DBT_HIRGenerator + */ +public interface OPT_HIRGenerator { + /** + * Method to create the HIR + */ + public void generateHIR(); +} Added: src/org/binarytranslator/DBT_Options.java =================================================================== --- src/org/binarytranslator/DBT_Options.java (rev 0) +++ src/org/binarytranslator/DBT_Options.java 2006-12-07 14:54:50 UTC (rev 1) @@ -0,0 +1,222 @@ +/* + * 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; + +/** + * Options for controlling the emulator + */ +public class DBT_Options { + // -oO Runtime settings Oo- + + /** + * Debug binary loading + */ + public final static boolean debugLoader=true; + + /** + * Are unimplemented system calls are fatal? + */ + public final static boolean unimplementedSystemCallsFatal = true; + + // -oO Translation settings Oo- + + /** + * The initial optimisation level + */ + public static int initialOptLevel=0; + + /** + * Instructions to translate for an optimisation level 0 trace + */ + public static int instrOpt0 = 684; + + /** + * Instructions to translate for an optimisation level 1 trace + */ + public static int instrOpt1 = 1500; + + /** + * Instructions to translate for an optimisation level 2 trace + */ + public static int instrOpt2 = 1500; + + /** + * Favour backward branch optimization. Translate backward branch + * addresses before the next instructions (this is the manner of the + * 601's branch predictor). + */ + public final static boolean optimizeBackwardBranches = true; + + /** + * Set this to true to record uncaught bclr instructions + */ + public static boolean plantUncaughtBclrWatcher = false; + + /** + * Set this to true to record uncaught bcctr instructions + */ + public static boolean plantUncaughtBcctrWatcher = true; + + /** + * Should all branches (excluding to lr and ctr) be resolved in one + * big go or one at at a time + */ + public static boolean resolveBranchesAtOnce = true; + + /** + * Should procedures (branches to ctr and lr) be given precedent over + * more local branches + */ + public static boolean resolveProceduresBeforeBranches = true; + + /** + * Use global branch information rather than local (within the + * trace) information when optimisation level is greater than or + * equal to this value + */ + public static int globalBranchLevel = 3; + + /** + * Set this to true to translate only one instruction at a + * time. + */ + public static boolean singleInstrTranslation=true; + + /** + * Eliminate unneeded filling of register + */ + public final static boolean eliminateRegisterFills = true; + + // -oO Translation debugging options Oo- + + /** + * Print dissassembly of translated instructions. + */ + public static boolean debugInstr=true; + + /** + * In PPC2IR, print information about lazy resolution... + */ + public final static boolean debugLazy=false; + + /** + * In PPC2IR, print cfg. + */ + public final static boolean debugCFG=false; + + // -oO Runtime debugging options Oo- + + /** + * Debug using GDB? + */ + public static boolean gdbStub = false; + + /** + * GDB stub port + */ + public static int gdbStubPort = 1234; + + /** + * In ProcessSpace, print syscall numbers. + */ + public static boolean debugSyscall=false; + + /** + * In ProcessSpace, print syscall numbers. + */ + public static boolean debugSyscallMore=false; + + /** + * Print out various messages about the emulator starting. + */ + public static boolean debugRuntime=true; + + /** + * Print out messages from the memory system + */ + public static boolean debugMemory=false; + + /** + * Print out process space between instructions + */ + public final static boolean debugPS=false; + + /** + * When printing process space, omit floating point registers. + */ + public final static boolean debugPS_OmitFP=false; + + /** + * The user ID for the user running the command + */ + public final static int UID = 1000; + + /** + * The group ID for the user running the command + */ + public final static int GID = 100; + + /** + * Process a command line option + * @arg the command line argument starting "-X:dbt:" + */ + public static void processArgument(String arg) { + if(arg.startsWith("-X:dbt:debugInstr=true")) { + debugInstr = true; + } + else if(arg.startsWith("-X:dbt:debugRuntime=true")) { + debugRuntime = true; + } + else if(arg.startsWith("-X:dbt:debugSyscall=true")) { + debugSyscall = true; + } + else if(arg.startsWith("-X:dbt:debugSyscallMore=true")) { + debugSyscallMore = true; + } + else if(arg.startsWith("-X:dbt:globalBranchLevel=")) { + globalBranchLevel = Integer.parseInt(arg.substring(25)); + } + else if(arg.startsWith("-X:dbt:initialOptLevel=")) { + initialOptLevel = Integer.parseInt(arg.substring(23)); + } + else if(arg.startsWith("-X:dbt:instrOpt0=")) { + instrOpt0 = Integer.parseInt(arg.substring(17)); + } + else if(arg.startsWith("-X:dbt:instrOpt1=")) { + instrOpt1 = Integer.parseInt(arg.substring(17)); + } + else if(arg.startsWith("-X:dbt:instrOpt2=")) { + instrOpt2 = Integer.parseInt(arg.substring(17)); + } + else if(arg.startsWith("-X:dbt:singleInstrTranslation=true")) { + singleInstrTranslation = true; + } + else if(arg.startsWith("-X:dbt:resolveBranchesAtOnce=true")) { + resolveBranchesAtOnce = true; + } + else if(arg.startsWith("-X:dbt:resolveBranchesAtOnce=false")) { + resolveBranchesAtOnce = false; + } + else if(arg.startsWith("-X:dbt:resolveProceduresBeforeBranches=true")) { + resolveProceduresBeforeBranches = true; + } + else if(arg.startsWith("-X:dbt:resolveProceduresBeforeBranches=false")) { + resolveProceduresBeforeBranches = false; + } + else if(arg.startsWith("-X:dbt:gdbStub=true")) { + gdbStub = true; + } + else if(arg.startsWith("-X:dbt:gdbStubPort=")) { + gdbStubPort = Integer.parseInt(arg.substring(19)); + } + else { + throw new Error("DBT Options: Unrecongised emulator option " + arg); + } + } +} Added: src/org/binarytranslator/Main.java =================================================================== --- src/org/binarytranslator/Main.java (rev 0) +++ src/org/binarytranslator/Main.java 2006-12-07 14:54:50 UTC (rev 1) @@ -0,0 +1,106 @@ +/* + * 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; + +import org.binarytranslator.generic.os.process.ProcessSpace; +import org.binarytranslator.generic.os.loader.Loader; + +/** + * The runtime system for the emulator. + * + * @author Ian Rogers, Richard Matley, Jon Burcham + * + */ +public class Main +{ + /* + * Variables required for an instance of the emulator + */ + + /** + * A process space encapsulating the execution of a process + */ + ProcessSpace ps; + + /* + * Utility functions + */ + + /** + * Debug information + * @param s string of debug information + */ + private static void report(String s){ + if (DBT_Options.debugRuntime) { + System.out.print("Main:"); + System.out.println(s); + } + } + + /** + * Usage + */ + public static void usage () + { + System.out.println("org.binarytranslator.Main [-X:dbt:...] <program> <args...>"); + } + + /** + * Constructor - should only be run from main + * @param args command line arguments. args[0] is the program to load. + */ + private Main(String[] args) { + // Check we have a file to load + if(args.length < 1) { + usage(); + } + else { + // Set up and load the process space + try { + report("Loading " + args[0]); + Loader loader = Loader.getLoader(args[0]); + ps = loader.readBinary(args); + } + catch(java.io.IOException e) { + usage(); + throw new Error("Error accessing file: " + args[0], e); + } + report ("Sucessfully created process"); + } + } + + /** + * Main method + * + * @param args command line arguments (see usage()) + */ + public static void main(String[] args) { + // Process any arguments for the emulator + for (int i=0; i < args.length; i++) { + if(args[i].startsWith("-X:dbt:")) { + DBT_Options.processArgument(args[i]); + } + else { + if (i != 0) { + String new_args[] = new String[args.length-i]; + for (int j=0; j < (args.length-i); j++) { + new_args[j]=args[i+j]; + } + args = new_args; + } + break; + } + } + Main runtime = new Main(args); + for (int i=0; i < args.length; i++) { + report("Argument " + i + ": " + args[i]); + } + runtime.ps.run(); + } +} Added: src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java =================================================================== --- src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java (rev 0) +++ src/org/binarytranslator/arch/ppc/decoder/PPC2IR.java 2006-12-07 14:54:50 UTC (rev 1) @@ -0,0 +1,1172 @@ +/* + * 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.arch.ppc.decoder; + +// DBT classes +import org.binarytranslator.arch.ppc.os.process.PPC_ProcessSpace; +import org.binarytranslator.vmInterface.TranslationHelper; +import org.binarytranslator.vmInterface.DBT_Trace; +import org.binarytranslator.DBT_Options; +import org.binarytranslator.generic.decoder.DecoderUtils; +import org.binarytranslator.generic.decoder.Laziness; +// General VM class +import com.ibm.jikesrvm.VM; +// Classes to get at class types +import com.ibm.jikesrvm.classloader.VM_Class; +import com.ibm.jikesrvm.classloader.VM_Method; +import com.ibm.jikesrvm.classloader.VM_TypeReference; +import com.ibm.jikesrvm.classloader.VM_MethodReference; +import com.ibm.jikesrvm.classloader.VM_MemberReference; +import com.ibm.jikesrvm.classloader.VM_FieldReference; +import com.ibm.jikesrvm.classloader.VM_BootstrapClassLoader; +import com.ibm.jikesrvm.classloader.VM_Atom; +// OPT interface +import com.ibm.jikesrvm.opt.OPT_Constants; +import com.ibm.jikesrvm.opt.ir.OPT_GenerationContext; +import com.ibm.jikesrvm.opt.ir.OPT_HIRGenerator; +import com.ibm.jikesrvm.opt.ir.OPT_IR; +// Instructions +import com.ibm.jikesrvm.opt.ir.OPT_Instruction; +import com.ibm.jikesrvm.opt.ir.OPT_Operator; +import com.ibm.jikesrvm.opt.ir.OPT_Operators; +import com.ibm.jikesrvm.opt.ir.Athrow; +import com.ibm.jikesrvm.opt.ir.Binary; +import com.ibm.jikesrvm.opt.ir.BBend; +import com.ibm.jikesrvm.opt.ir.BooleanCmp; +import com.ibm.jikesrvm.opt.ir.Call; +import com.ibm.jikesrvm.opt.ir.CondMove; +import com.ibm.jikesrvm.opt.ir.GetField; +import com.ibm.jikesrvm.opt.ir.Goto; +import com.ibm.jikesrvm.opt.ir.IfCmp; +import com.ibm.jikesrvm.opt.ir.Move; +import com.ibm.jikesrvm.opt.ir.New; +import com.ibm.jikesrvm.opt.ir.LookupSwitch; +import com.ibm.jikesrvm.opt.ir.PutField; +import com.ibm.jikesrvm.opt.ir.Unary; +// Operands +import com.ibm.jikesrvm.opt.ir.OPT_AddressConstantOperand; +import com.ibm.jikesrvm.opt.ir.OPT_BasicBlock; +import com.ibm.jikesrvm.opt.ir.OPT_BranchOperand; +import com.ibm.jikesrvm.opt.ir.OPT_BranchProfileOperand; +import com.ibm.jikesrvm.opt.ir.OPT_ConditionOperand; +import com.ibm.jikesrvm.opt.ir.OPT_IntConstantOperand; +import com.ibm.jikesrvm.opt.ir.OPT_LocationOperand; +import com.ibm.jikesrvm.opt.ir.OPT_MethodOperand; +import com.ibm.jikesrvm.opt.ir.OPT_Operand; +import com.ibm.jikesrvm.opt.ir.OPT_Register; +import com.ibm.jikesrvm.opt.ir.OPT_RegisterOperand; +import com.ibm.jikesrvm.opt.ir.OPT_TrueGuardOperand; +import com.ibm.jikesrvm.opt.ir.OPT_TypeOperand; +// Java utilities +import java.util.Enumeration; +import java.util.NoSuchElementException; +import java.util.ArrayList; +import java.util.Set; +import java.util.Iterator; +import java.util.HashSet; + +/** + * Translation from PPC machine code to HIR. + * + * @author Richard Matley, Ian Rogers + */ +public final class PPC2IR extends DecoderUtils implements OPT_HIRGenerator, OPT_Operators, OPT_Constants { + + /** + * Construct the PPC2IR object for the generation context; then + * we'll be ready to start generating the HIR. + */ + public PPC2IR(OPT_GenerationContext context) { + super(context); + // Create register maps PPC -> OPT_Register + intRegMap = new OPT_Register[32]; + intRegInUseMap = new boolean[32]; + fpRegMap = new OPT_Register[32]; + fpRegInUseMap = new boolean[32]; + crFieldMap_Lt = new OPT_Register[8]; + crFieldMap_Gt = new OPT_Register[8]; + crFieldMap_Eq = new OPT_Register[8]; + crFieldMap_SO = new OPT_Register[8]; + crFieldInUseMap = new boolean[8]; + + // Debug + if(DBT_Options.debugCFG) { + report("CFG at end of constructor:\n" + gc.cfg); + } + } + + /** + * Translate the instruction at the given pc + * @param lazy the status of the lazy evaluation + * @param pc the program counter for the instruction + * @return the next instruction address or -1 + */ + protected int translateInstruction(Laziness lazy, int pc) { + return PPC_InstructionDecoder.translateInstruction(this, (PPC_ProcessSpace)ps, (PPC_Laziness)lazy, pc); + } + + // -oO Creations for being a PPC translator Oo- + + // -oO PPC register to HIR register mappings Oo- + + /** + * The mapping of PPC general purpose registers to HIR + * registers. All GP registers are loaded into these by the preFill + * block. This avoids potential inconsistencies caused by using lazy + * allocation and backward branches. + */ + private OPT_Register intRegMap[]; + /** + * Which PPC general purpose registers are in use + */ + private boolean intRegInUseMap[]; + + /** + * The mapping of PPC floating point registers to HIR registers. + */ + private OPT_Register fpRegMap[]; + /** + * Which PPC floating point registers are in use + */ + private boolean fpRegInUseMap[]; + + /** + * The HIR register holding the PPC FPSCR register. + */ + private OPT_Register fpscrRegMap; + /** + * Is the PPC FPSCR register in use + */ + private boolean fpscrRegInUse; + + /** + * The HIR register holding the PPC CTR register. + */ + private OPT_Register ctrRegMap; + /** + * Is the PPC CTR register in use + */ + private boolean ctrRegInUse; + + /** + * The HIR register holding the PPC LR register. + */ + private OPT_Register lrRegMap; + /** + * Is the PPC LR register in use + */ + private boolean lrRegInUse; + + /** + * The HIR register holding the PPC XER register when it is combined + * in a fillAll or spillAll block + */ + private OPT_Register xerRegMap; + + /** + * The HIR register holding the PPC XER register's byte count (bits + * 25 to 31) + */ + private OPT_Register xerRegMap_ByteCount; + + /** + * The HIR boolean register holding thr PPC XER CA (carry) bit. + */ + private OPT_Register xerRegMap_CA; + + /** + * The HIR register holding thr PPC XER OV (overflow) bit. If this + * register is non-zero then the OV bit should be set. + */ + private OPT_Register xerRegMap_OV; + /** + * The HIR register holding thr PPC XER SO (summary overflow) + * bit. If this register is non-zero then the SO bit should be set. + */ + private OPT_Register xerRegMap_SO; + /** + * Is the PPC XER register in use + */ + private boolean xerRegInUse; + + /** + * These 8 registers hold a zero or non-zero value depending on the + * value of the corresponding condition register field's SO + * bit. + */ + private OPT_Register crFieldMap_Lt[]; + + /** + * These 8 registers hold a zero or non-zero value depending on the + * value of the corresponding condition register field's SO + * bit. + */ + private OPT_Register crFieldMap_Gt[]; + + /** + * These 8 registers hold a zero or non-zero value depending on the + * value of the corresponding condition register field's SO + * bit. + */ + private OPT_Register crFieldMap_Eq[]; + + /** + * These 8 registers hold a zero or non-zero value depending on the + * value of the corresponding condition register field's SO + * bit. + */ + private OPT_Register crFieldMap_SO[]; + + /** + * What condition register fields are in use? + */ + private boolean crFieldInUseMap[]; + + // -oO Fill/spill registers between OPT_Registers and the PPC_ProcessSpace Oo- + + /** + * Copy the value of a general purpose (int) register into its + * temporary location from the PPC_ProcessSpace. + * @param r the number of the register to fill. + */ + private void fillGPRegister(int r) { + if (VM.VerifyAssertions) VM._assert(r < 32); + + OPT_RegisterOperand result; + if (intRegMap[r] == null) { + result = gc.temps.makeTempInt(); + intRegMap[r]=result.register; // Set mapping + } + else { + result = new OPT_RegisterOperand(intRegMap[r], VM_TypeReference.Int); + } + + VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), + VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") + ); + VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("r"+r), + VM_Atom.findOrCreateAsciiAtom("I") + ).asFieldReference(); + appendInstructionToCurrentBlock(GetField.create(GETFIELD, result, + gc.makeLocal(1,psTref), + new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), + new OPT_LocationOperand(ref), + new OPT_TrueGuardOperand()) + ); + } + + + /** + * Copy the value of a general purpose (int) register into the + * PPC_ProcessSpace from its temporary location. + * @param r the number of the register to spill. + */ + private void spillGPRegister(int r) { + if (VM.VerifyAssertions) VM._assert(r < 32); + if (VM.VerifyAssertions) VM._assert(intRegMap[r] != null); + + OPT_RegisterOperand regOp = new OPT_RegisterOperand(intRegMap[r], VM_TypeReference.Int); + + VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), + VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") + ); + VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("r"+r), + VM_Atom.findOrCreateAsciiAtom("I") + ).asFieldReference(); + appendInstructionToCurrentBlock(PutField.create(PUTFIELD, regOp, + gc.makeLocal(1,psTref), + new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), + new OPT_LocationOperand(ref), + new OPT_TrueGuardOperand()) + ); + } + + + /** + * Copy the value of a floating point register into its temporary + * location from the PPC_ProcessSpace. + * @param r the number of the register to fill. + */ + private void fillFPRegister(int r) { + if (VM.VerifyAssertions) VM._assert(r < 32); + + OPT_RegisterOperand result; + if (fpRegMap[r] == null) { + result = gc.temps.makeTempDouble(); + fpRegMap[r]=result.register; // Set mapping + } + else { + result = new OPT_RegisterOperand(fpRegMap[r], VM_TypeReference.Double); + } + + VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), + VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") + ); + VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("f"+r), + VM_Atom.findOrCreateAsciiAtom("D") + ).asFieldReference(); + appendInstructionToCurrentBlock(GetField.create(GETFIELD, result, + gc.makeLocal(1,psTref), + new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), + new OPT_LocationOperand(ref), + new OPT_TrueGuardOperand()) + ); + } + + + /** + * Copy the value of a floating point register into the + * PPC_ProcessSpace from its temporary location. + * @param r the number of the register to spill. + */ + private void spillFPRegister(int r) { + if (VM.VerifyAssertions) VM._assert(r < 32); + if (VM.VerifyAssertions) VM._assert(fpRegMap[r] != null); + + OPT_RegisterOperand regOp = new OPT_RegisterOperand(fpRegMap[r], VM_TypeReference.Double); + + VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), + VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") + ); + VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("f"+r), + VM_Atom.findOrCreateAsciiAtom("D") + ).asFieldReference(); + appendInstructionToCurrentBlock(PutField.create(PUTFIELD, regOp, + gc.makeLocal(1,psTref), + new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), + new OPT_LocationOperand(ref), + new OPT_TrueGuardOperand()) + ); + } + + /** + * Copy the values of the condition register field into its + * temporary locations from the PPC_ProcessSpace. + * @param crf the condition register field to copy + */ + private void fillCRRegister(int crf) + { + if (crFieldMap_Lt[crf] == null) { + crFieldMap_Lt[crf] = gc.temps.getReg(VM_TypeReference.Boolean); + crFieldMap_Gt[crf] = gc.temps.getReg(VM_TypeReference.Boolean); + crFieldMap_Eq[crf] = gc.temps.getReg(VM_TypeReference.Boolean); + crFieldMap_SO[crf] = gc.temps.getReg(VM_TypeReference.Boolean); + } + OPT_RegisterOperand lt = new OPT_RegisterOperand(crFieldMap_Lt[crf], VM_TypeReference.Boolean); + OPT_RegisterOperand gt = new OPT_RegisterOperand(crFieldMap_Gt[crf], VM_TypeReference.Boolean); + OPT_RegisterOperand lt = new OPT_RegisterOperand(crFieldMap_Eq[crf], VM_TypeReference.Boolean); + OPT_RegisterOperand so = new OPT_RegisterOperand(crFieldMap_SO[crf], VM_TypeReference.Boolean); + + OPT_RegisterOperand arrayref = gc.temps.makeTemp(VM_TypeReference.BooleanArray); + + VM_TypeReference psTref = VM_TypeReference.findOrCreate(VM_BootstrapClassLoader.getBootstrapClassLoader(), + VM_Atom.findOrCreateAsciiAtom("Lorg/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace;") + ); + VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_lt"), + VM_Atom.findOrCreateAsciiAtom("[Z") + ).asFieldReference(); + appendInstructionToCurrentBlock(GetField.create(GETFIELD, arrayref, + gc.makeLocal(1,psTref), + new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), + new OPT_LocationOperand(ref), + new OPT_TrueGuardOperand()) + ); + appendInstructionToCurrentBlock(ALoad.create(UBYTE_ALOAD, lt, + arrayref, new OPT_IntegerConstantOperand(crf), + new OPT_LocationOperand(VM_TypeReference.BooleanArray), + new OPT_TrueGuardOperand())); + VM_FieldReference ref = VM_MemberReference.findOrCreate(psTref,VM_Atom.findOrCreateAsciiAtom("crf_gt"), + VM_Atom.findOrCreateAsciiAtom("[Z") + ).asFieldReference(); + appendInstructionToCurrentBlock(GetField.create(GETFIELD, arrayref, + gc.makeLocal(1,psTref), + new OPT_AddressConstantOperand(ref.peekResolvedField().getOffset()), + new OPT_LocationOperand(ref), + ... [truncated message content] |