LOGIN   :::   RECOVER PASS   :::   GET ACCOUNT    
Browse
  • Projects
  • Code (CVS)
  • Forums
  • News
  • Articles
  • Polls
  •  
    OpenCores
  • FAQ
  • CVS HowTo
  • Mission
  • Media
  • Tools
  • Advertise
  • Mirrors
  • Logos
  • Contact us
  • Job Opportunity
  •  
    Tools
  • Search
      
  • Download Cores (CVSGet)
  •  
    More
  • Wishbone
  • Perlilog
  • EDA tools
  • OpenTech CD
  •  
    Navigation: All forums > Cvs-checkins > Message List > Message Post

    Message

    Reply | Reply all
    Date Prev | Date Next | Thread Prev | Thread Next Date Index | Thread Index

    From: cvs at opencores.org<cvs@o...>
    Date: Tue Jul 24 14:56:43 CEST 2007
    Subject: [cvs-checkins] MODIFIED: jop ...
    Top
    Date: 00/07/07 24:14:56

    Added: jop/java/tools/src/wcet/components/graphbuilder/methodgb
    InsnImplFilter.java JOPSystemMethodCache.java
    MBCacheVisitor.java MethodBlock.java
    MethodGraphBuilder.java MethodKey.java
    Log:



    Revision Changes Path
    1.1 jop/java/tools/src/wcet/components/graphbuilder/methodgb/InsnImplFilter.java

    http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/components/graphbuilder/methodgb/InsnImplFilter.java?rev=1.1&content-type=text/x-cvsweb-markup

    Index: InsnImplFilter.java
    ===================================================================
    /**
    *
    */
    package wcet.components.graphbuilder.methodgb;

    import java.util.Arrays;
    import java.util.List;

    import org.objectweb.asm.AnnotationVisitor;
    import org.objectweb.asm.Attribute;
    import org.objectweb.asm.ClassVisitor;
    import org.objectweb.asm.FieldVisitor;
    import org.objectweb.asm.Label;
    import org.objectweb.asm.MethodVisitor;
    import org.objectweb.asm.Type;

    import com.jopdesign.wcet.WCETInstruction;

    import wcet.components.graphbuilder.IGraphBuilderConstants;
    import wcet.framework.exceptions.InitException;
    import wcet.framework.interfaces.general.IAnalyserComponent;
    import wcet.framework.interfaces.general.IDataStore;
    import wcet.framework.interfaces.general.IGlobalComponentOrder;
    import wcet.framework.interfaces.instruction.IImplementationConfig;
    import wcet.framework.interfaces.instruction.IJOPMethodVisitor;
    import wcet.framework.interfaces.instruction.OpCodes;

    /**
    * @author Elena Axamitova
    * @version 0.3 03.03.2007
    *
    * Precedes java bytecodes that are implemented in java with the implementing
    * method.
    */
    public class InsnImplFilter implements ClassVisitor, IAnalyserComponent {

    /**
    * Shared datastore
    */
    private IDataStore datastore;

    /**
    * Next visitor in the chain to which delegate calls
    */
    private ClassVisitor lastVisitor;

    /**
    * metod visitor of this class
    */
    private InsnImplFilterVisitor myVisitor;

    public InsnImplFilter(IDataStore ds) {
    this.datastore = ds;
    }

    /*
    * (non-Javadoc)
    *
    * @see wcet.framework.interfaces.general.IAnalyserComponent#getOnlyOne()
    */
    public boolean getOnlyOne() {
    return false;
    }

    /*
    * (non-Javadoc)
    *
    * @see wcet.framework.interfaces.general.IAnalyserComponent#getOrder()
    */
    public int getOrder() {
    return IGlobalComponentOrder.NOT_EXECUTED;
    }

    /*
    * (non-Javadoc)
    *
    * @see wcet.framework.interfaces.general.IAnalyserComponent#init()
    */
    public void init() throws InitException {
    // get the last class visitore from the datastore and save me there
    // instead of it.
    this.lastVisitor = (ClassVisitor) this.datastore
    .getObject(IGraphBuilderConstants.LAST_MB_CLASS_VISITOR_KEY);
    this.datastore.storeObject(
    IGraphBuilderConstants.LAST_MB_CLASS_VISITOR_KEY, this);
    // since the InsnImplFilterVisitor is stateless, it is enough to have // only one this.myVisitor = new InsnImplFilterVisitor(); } /* * (non-Javadoc) * * @see java.util.concurrent.Callable#call() */ public String call() throws Exception { // this component is not executed explicitly, it is called in the chain // from method graph builder return null; } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visitMethod(int, * java.lang.String, java.lang.String, java.lang.String, * java.lang.String[]) */ public MethodVisitor visitMethod(int arg0, String arg1, String arg2, String arg3, String[] arg4) { if (this.lastVisitor != null) { this.myVisitor.mv = this.lastVisitor.visitMethod(arg0, arg1, arg2, arg3, arg4); } else { this.myVisitor.mv = null; } // InsnImplFilterVisitor is stateless, so there is no need to create for // every // visited method a new one return this.myVisitor; } /** * @author Elena Axamitova * @version 0.1 05.06.2007 * * Method visitor that does nearly all the work. */ class InsnImplFilterVisitor implements IJOPMethodVisitor { // -1 not set, 0 implemented in java, 1 not implemented in java /** * bytecode implementation not set yet */ // private static final int IMPL_NOT_SET = -1; /** * bytecode implemented in java */ // private static final int IMPL_IN_JAVA = 0; /** * bytecode not implemented in java (hw, mc, not implemented) */ // private static final int NOT_IMPL_IN_JAVA = 1; /** * next method visitor in chain */ private MethodVisitor mv; public InsnImplFilterVisitor() { } /** * If an instruction is implemeted in java, this method inserts a call * to the corresponding method. * * @param opCode - * opcode of the instruction */ private void handleJOPInstruction(int opCode) { // setting in the xml config file take preference if (IImplementationConfig.JOP_INSN_IMPL_DEFAULT[opCode] == IImplementationConfig.JAVA) { // if(WCETInstruction.isInJava(opCode)){ // call the method String name = "f_" + OpCodes.OPCODE_NAMES[opCode]; // QUESTION invokestatic or invoke special (private) this.mv.visitMethodInsn(OpCodes.INVOKESTATIC, IGraphBuilderConstants.JOP_SYSTEM_PACKAGE_NAME + IGraphBuilderConstants.JVMCLASS_NAME, name, IImplementationConfig.JOP_METHOD_IMPL_DESCR[opCode]); } } /** * Get the opcode of a corresponding bytecode for a Native method call. * * @param name - * Native method name * @param desc - * Native method desriptor * @return - jop system bytecode opcode */ private int jopNativeMethodToOpcode(String name, String desc) { int result; String lowerCaseName = name.toLowerCase(); List<String> opCodesList = Arrays.asList(OpCodes.OPCODE_NAMES); if (name.equalsIgnoreCase("int2extMem")) { lowerCaseName = "int2ext"; } else if (name.equalsIgnoreCase("ext2intMem")) { lowerCaseName = "ext2int"; } else if (name.equalsIgnoreCase("rdIntMem")) { lowerCaseName = "rdint"; } else if (name.equalsIgnoreCase("wrIntMem")) { lowerCaseName = "wrint"; } result = opCodesList.indexOf("jopsys_" + lowerCaseName); if (result != -1) { return result; } else { // TODO implement other mappings return OpCodes.JOPSYS_NOP; } } // in the methods bellow the method handleJOPInstruction is called first // and then is the call delegated to the next visitor // if it exists /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitFieldInsn(int, * java.lang.String, java.lang.String, java.lang.String) */ public void visitFieldInsn(int arg0, String arg1, String arg2, String arg3) { this.handleJOPInstruction(arg0); if (this.mv != null) this.mv.visitFieldInsn(arg0, arg1, arg2, arg3); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitIincInsn(int, int) */ public void visitIincInsn(int arg0, int arg1) { this.handleJOPInstruction(arg0); if (this.mv != null) this.mv.visitIincInsn(arg0, arg1); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitInsn(int) */ public void visitInsn(int arg0) { this.handleJOPInstruction(arg0); if (this.mv != null) this.mv.visitInsn(arg0); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitIntInsn(int, int) */ public void visitIntInsn(int arg0, int arg1) { this.handleJOPInstruction(arg0); if (this.mv != null) this.mv.visitIntInsn(arg0, arg1); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitJumpInsn(int, * org.objectweb.asm.Label) */ public void visitJumpInsn(int arg0, Label arg1) { this.handleJOPInstruction(arg0); if (this.mv != null) this.mv.visitJumpInsn(arg0, arg1); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitLdcInsn(java.lang.Object) */ public void visitLdcInsn(Object cnst) { if ((cnst instanceof Integer) || (cnst instanceof Float) || (cnst instanceof String) || (cnst instanceof Type)) { this.handleJOPInstruction(OpCodes.LDC_W); } else { this.handleJOPInstruction(OpCodes.LDC2_W); } if (this.mv != null) this.mv.visitLdcInsn(cnst); // TODO LDC or LDC_W } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitLookupSwitchInsn(org.objectweb.asm.Label, * int[], org.objectweb.asm.Label[]) */ public void visitLookupSwitchInsn(Label arg0, int[] arg1, Label[] arg2) { this.handleJOPInstruction(OpCodes.LOOKUPSWITCH); if (this.mv != null) this.mv.visitLookupSwitchInsn(arg0, arg1, arg2); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitMethodInsn(int, * java.lang.String, java.lang.String, java.lang.String) */ public void visitMethodInsn(int oc, String owner, String name, String desc) { int opCode = oc; if (owner.equals(IGraphBuilderConstants.JOP_SYSTEM_PACKAGE_NAME + IGraphBuilderConstants.NATIVECLASS_NAME)) { opCode = this.jopNativeMethodToOpcode(name, desc); if (opCode != -1) this.visitJOPInsn(opCode); } else { this.handleJOPInstruction(oc); // TODO bad - infinite loop - log in JVM - WORKAROUND /* * if ((owner.endsWith("JVMHelp") && (name.equals("wr")) && * (desc .equals("(Ljava/lang/String;)V")))) return; */ if (this.mv != null) // if (!owner // .equals(IGraphBuilderConstants.JOP_SYSTEM_PACKAGE_NAME+IGraphBuilderConstants.NATIVECLASS_NAME)) this.mv.visitMethodInsn(oc, owner, name, desc); } } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitMultiANewArrayInsn(java.lang.String, * int) */ public void visitMultiANewArrayInsn(String arg0, int arg1) { this.handleJOPInstruction(OpCodes.MULTIANEWARRAY); if (this.mv != null) this.mv.visitMultiANewArrayInsn(arg0, arg1); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitTableSwitchInsn(int, int, * org.objectweb.asm.Label, org.objectweb.asm.Label[]) */ public void visitTableSwitchInsn(int arg0, int arg1, Label arg2, Label[] arg3) { this.handleJOPInstruction(arg0); if (this.mv != null) this.mv.visitTableSwitchInsn(arg0, arg1, arg2, arg3); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitTypeInsn(int, * java.lang.String) */ public void visitTypeInsn(int arg0, String arg1) { this.handleJOPInstruction(arg0); if (this.mv != null) this.mv.visitTypeInsn(arg0, arg1); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitVarInsn(int, int) */ public void visitVarInsn(int arg0, int arg1) { this.handleJOPInstruction(arg0); if (this.mv != null) this.mv.visitVarInsn(arg0, arg1); } /* * (non-Javadoc) * * @see wcet.framework.interfaces.instruction.IJOPMethodVisitor#visitJOPInsn(int) */ public void visitJOPInsn(int opCode) { this.handleJOPInstruction(opCode); if (this.mv != null) ((IJOPMethodVisitor) this.mv).visitJOPInsn(opCode); } // all the methods bellow just delegate the call to the next visitor // if it exists /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitAnnotation(java.lang.String, * boolean) */ public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) { if (this.mv != null) return this.mv.visitAnnotation(arg0, arg1); else return null; } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitAnnotationDefault() */ public AnnotationVisitor visitAnnotationDefault() { if (this.mv != null) return this.mv.visitAnnotationDefault(); else return null; } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitAttribute(org.objectweb.asm.Attribute) */ public void visitAttribute(Attribute arg0) { if (this.mv != null) this.mv.visitAttribute(arg0); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitCode() */ public void visitCode() { if (this.mv != null) this.mv.visitCode(); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitEnd() */ public void visitEnd() { if (this.mv != null) this.mv.visitEnd(); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitFrame(int, int, * java.lang.Object[], int, java.lang.Object[]) */ public void visitFrame(int arg0, int arg1, Object[] arg2, int arg3, Object[] arg4) { if (this.mv != null) this.mv.visitFrame(arg0, arg1, arg2, arg3, arg4); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitLabel(org.objectweb.asm.Label) */ public void visitLabel(Label arg0) { if (this.mv != null) this.mv.visitLabel(arg0); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitLineNumber(int, * org.objectweb.asm.Label) */ public void visitLineNumber(int arg0, Label arg1) { if (this.mv != null) this.mv.visitLineNumber(arg0, arg1); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitLocalVariable(java.lang.String, * java.lang.String, java.lang.String, org.objectweb.asm.Label, * org.objectweb.asm.Label, int) */ public void visitLocalVariable(String arg0, String arg1, String arg2, Label arg3, Label arg4, int arg5) { if (this.mv != null) this.mv.visitLocalVariable(arg0, arg1, arg2, arg3, arg4, arg5); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitMaxs(int, int) */ public void visitMaxs(int arg0, int arg1) { if (this.mv != null) this.mv.visitMaxs(arg0, arg1); } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitParameterAnnotation(int, * java.lang.String, boolean) */ public AnnotationVisitor visitParameterAnnotation(int arg0, String arg1, boolean arg2) { if (this.mv != null) return this.mv.visitParameterAnnotation(arg0, arg1, arg2); else return null; } /* * (non-Javadoc) * * @see org.objectweb.asm.MethodVisitor#visitTryCatchBlock(org.objectweb.asm.Label, * org.objectweb.asm.Label, org.objectweb.asm.Label, * java.lang.String) */ public void visitTryCatchBlock(Label arg0, Label arg1, Label arg2, String arg3) { if (this.mv != null) this.mv.visitTryCatchBlock(arg0, arg1, arg2, arg3); } } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visit(int, int, java.lang.String, * java.lang.String, java.lang.String, java.lang.String[]) */ public void visit(int arg0, int arg1, String arg2, String arg3, String arg4, String[] arg5) { if (this.lastVisitor != null) this.lastVisitor.visit(arg0, arg1, arg2, arg3, arg4, arg5); } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visitAnnotation(java.lang.String, * boolean) */ public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) { if (this.lastVisitor != null) return this.lastVisitor.visitAnnotation(arg0, arg1); else return null; } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visitAttribute(org.objectweb.asm.Attribute) */ public void visitAttribute(Attribute arg0) { if (this.lastVisitor != null) this.lastVisitor.visitAttribute(arg0); } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visitEnd() */ public void visitEnd() { if (this.lastVisitor != null) this.lastVisitor.visitEnd(); } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visitField(int, java.lang.String, * java.lang.String, java.lang.String, java.lang.Object) */ public FieldVisitor visitField(int arg0, String arg1, String arg2, String arg3, Object arg4) { if (this.lastVisitor != null) return this.lastVisitor.visitField(arg0, arg1, arg2, arg3, arg4); else return null; } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visitInnerClass(java.lang.String, * java.lang.String, java.lang.String, int) */ public void visitInnerClass(String arg0, String arg1, String arg2, int arg3) { if (this.lastVisitor != null) this.lastVisitor.visitInnerClass(arg0, arg1, arg2, arg3); } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visitOuterClass(java.lang.String, * java.lang.String, java.lang.String) */ public void visitOuterClass(String arg0, String arg1, String arg2) { if (this.lastVisitor != null) this.lastVisitor.visitOuterClass(arg0, arg1, arg2); } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visitSource(java.lang.String, * java.lang.String) */ public void visitSource(String arg0, String arg1) { if (this.lastVisitor != null) this.lastVisitor.visitSource(arg0, arg1); } } 1.1 jop/java/tools/src/wcet/components/graphbuilder/methodgb/JOPSystemMethodCache.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/components/graphbuilder/methodgb/JOPSystemMethodCache.java?rev=1.1&content-type=text/x-cvsweb-markup Index: JOPSystemMethodCache.java =================================================================== /** * */ package wcet.components.graphbuilder.methodgb; import java.util.Iterator; import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.FieldInsnNode; import org.objectweb.asm.tree.MethodInsnNode; import wcet.components.graphbuilder.IGraphBuilderConstants; import wcet.components.graphbuilder.util.IFileList; import wcet.components.graphbuilder.util.MethodBlockCache; import wcet.framework.exceptions.TaskInitException; import wcet.framework.interfaces.instruction.IImplementationConfig; import wcet.framework.interfaces.instruction.OpCodes; /** * @author Elena Axamitova * @version 0.1 05.04.2007 * * MethodMap of jop system classes. */ public class JOPSystemMethodCache { private IFileList systemMethodsList; private MethodBlockCache jopSystemMethodCache; protected JOPSystemMethodCache(IFileList systemFl){ this.systemMethodsList = systemFl; this.jopSystemMethodCache = new MethodBlockCache(this.systemMethodsList); } protected MethodBlock getJOPMethodBlock(MethodKey key) throws TaskInitException { MethodBlock result; // MEMO bad - infinite loop - wr(String) in JVMHelp -charAt in String- // WORKAROUND if (key.getOwner().endsWith("WorkAroundString")) { MethodKey tempKey = new MethodKey("java/lang/String", key.getName(), key.getDecription()); result = this.jopSystemMethodCache.getMethodBlock(tempKey); Iterator insnIterator = result.instructions.iterator(); while (insnIterator.hasNext()) { AbstractInsnNode insnNode = (AbstractInsnNode) insnIterator .next(); if (insnNode.getOpcode() == OpCodes.NEW) insnNode = new FieldInsnNode(OpCodes.GETFIELD, "java/lang/String", "value", "[C"); if (insnNode.getOpcode() == OpCodes.INVOKESPECIAL) insnNode = new FieldInsnNode(OpCodes.GETFIELD, "java/lang/String", "value", "[C"); } } else { result = this.jopSystemMethodCache.getMethodBlock(key); if ((key.getOwner().endsWith("JVMHelp") && (key.getName().equals("wr")) && (key.getDecription() .equals("(Ljava/lang/String;)V")))) { Iterator insnIterator = result.instructions.iterator(); while (insnIterator.hasNext()) { AbstractInsnNode insnNode = (AbstractInsnNode) insnIterator .next(); if (insnNode.getType() == AbstractInsnNode.METHOD_INSN) { MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; if ((methodInsnNode.owner.endsWith("String")) && (methodInsnNode.name.equals("charAt")) && (methodInsnNode.desc.equals("(I)C"))) { methodInsnNode.owner = IGraphBuilderConstants.JOP_SYSTEM_PACKAGE_NAME + "WorkAroundString"; } } } } } result.resolve(); return result; } public static void main(String[] args) { for (int i = 0; i < IImplementationConfig.JOP_INSN_IMPL_DEFAULT.length; i++) { System.out.println("OpCode: " + i + " name:" + OpCodes.OPCODE_NAMES[i] + " desc:" + IImplementationConfig.JOP_METHOD_IMPL_DESCR[i] + "."); } } } 1.1 jop/java/tools/src/wcet/components/graphbuilder/methodgb/MBCacheVisitor.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/components/graphbuilder/methodgb/MBCacheVisitor.java?rev=1.1&content-type=text/x-cvsweb-markup Index: MBCacheVisitor.java =================================================================== /** * */ package wcet.components.graphbuilder.methodgb; import java.util.Iterator; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.Attribute; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.FieldInsnNode; import org.objectweb.asm.tree.MethodInsnNode; import wcet.components.graphbuilder.IGraphBuilderConstants; import wcet.components.graphbuilder.util.IFileList; import wcet.components.graphbuilder.util.IMethodBlockCache; import wcet.components.graphbuilder.util.MethodBlockCache; import wcet.framework.exceptions.TaskInitException; import wcet.framework.interfaces.instruction.OpCodes; /** * @author Elena Axamitova * @version 0.3 12.01.2007 * * Caches method blocks of previously encountred classes. If the required method * block not found in cache, it will be created and stored. The cache cache uses * least recently accessed strategy when removing the oldest entry. */ public class MBCacheVisitor implements ClassVisitor, IMethodBlockCache { private MethodBlockCache methodBlockCache; /** * Construct a new cache that uses the provided file list * * @param fl - * file list to get class input streams from */ public MBCacheVisitor(IFileList fl) { this.methodBlockCache = new MethodBlockCache(fl); } public void setFilter(ClassVisitor filter) { this.methodBlockCache.setFilter(filter); } /** * Get MethodBlock for the method key. If not in cache, read the class, * store all method blocks of the class in cache. * * @param key * @return * @throws TaskInitException */ public MethodBlock getMethodBlock(MethodKey key) throws TaskInitException { MethodBlock methBlock; if (key.getOwner().startsWith( IGraphBuilderConstants.JOP_SYSTEM_PACKAGE_NAME)) { try { methBlock = this.getJOPMethodBlock(key); } catch (Exception e) { throw new TaskInitException(e); } } else { methBlock = this.methodBlockCache.getMethodBlock(key); } return methBlock; } private MethodBlock getJOPMethodBlock(MethodKey key) throws TaskInitException { MethodBlock result; // MEMO bad - infinite loop - wr(String) in JVMHelp -charAt in String- // WORKAROUND if (key.getOwner().endsWith("WorkAroundString")) { MethodKey tempKey = new MethodKey("java/lang/String", key.getName(), key.getDecription()); result = this.methodBlockCache.getMethodBlock(tempKey); Iterator insnIterator = result.instructions.iterator(); while (insnIterator.hasNext()) { AbstractInsnNode insnNode = (AbstractInsnNode) insnIterator .next(); if (insnNode.getOpcode() == OpCodes.NEW) insnNode = new FieldInsnNode(OpCodes.GETFIELD, "java/lang/String", "value", "[C"); if (insnNode.getOpcode() == OpCodes.INVOKESPECIAL) insnNode = new FieldInsnNode(OpCodes.GETFIELD, "java/lang/String", "value", "[C"); } result.replaceChild(new MethodKey("com/jopdesign/sys/JVM","f_new","(I)I"), null); result.replaceChild(new MethodKey("com/jopdesign/sys/JVM","f_athrow","(Ljava/lang/Throwable;)Ljava/lang/Throwable;"), null); result.replaceChild(new MethodKey("java/lang/StringIndexOutOfBoundsException","<init>","(I)V"), null); } else { result = this.methodBlockCache.getMethodBlock(key); if ((key.getOwner().endsWith("JVMHelp") && (key.getName().equals("wr")) && (key.getDecription() .equals("(Ljava/lang/String;)V")))) { Iterator insnIterator = result.instructions.iterator(); while (insnIterator.hasNext()) { AbstractInsnNode insnNode = (AbstractInsnNode) insnIterator .next(); if (insnNode.getType() == AbstractInsnNode.METHOD_INSN) { MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; if ((methodInsnNode.owner.endsWith("String")) && (methodInsnNode.name.equals("charAt")) && (methodInsnNode.desc.equals("(I)C"))) { methodInsnNode.owner = IGraphBuilderConstants.JOP_SYSTEM_PACKAGE_NAME + "WorkAroundString"; } } } MethodKey oldKey = new MethodKey("java/lang/String", "charAt", "(I)C"); MethodKey newKey = new MethodKey(IGraphBuilderConstants.JOP_SYSTEM_PACKAGE_NAME+"WorkAroundString", "charAt", "(I)C"); result.replaceChild(oldKey, newKey); } } // result.resolve(); return result; } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visit(int, int, java.lang.String, * java.lang.String, java.lang.String, java.lang.String[]) */ public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { this.methodBlockCache.getCurrClassNode().visit(version, access, name, signature, superName, interfaces); } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visitAnnotation(java.lang.String, * boolean) */ public AnnotationVisitor visitAnnotation(String desc, boolean visible) { return this.methodBlockCache.getCurrClassNode().visitAnnotation(desc, visible); } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visitAttribute(org.objectweb.asm.Attribute) */ public void visitAttribute(Attribute attr) { this.methodBlockCache.getCurrClassNode().visitAttribute(attr); } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visitEnd() */ public void visitEnd() { this.methodBlockCache.getCurrClassNode().visitEnd(); } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visitField(int, java.lang.String, * java.lang.String, java.lang.String, java.lang.Object) */ public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { return this.methodBlockCache.getCurrClassNode().visitField(access, name, desc, signature, value); } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visitInnerClass(java.lang.String, * java.lang.String, java.lang.String, int) */ public void visitInnerClass(String name, String outerName, String innerName, int access) { this.methodBlockCache.getCurrClassNode().visitInnerClass(name, outerName, innerName, access); } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visitMethod(int, * java.lang.String, java.lang.String, java.lang.String, * java.lang.String[]) */ public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { return this.methodBlockCache.getCurrClassNode().visitMethod(access, name, desc, signature, exceptions); } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visitOuterClass(java.lang.String, * java.lang.String, java.lang.String) */ public void visitOuterClass(String owner, String name, String desc) { this.methodBlockCache.getCurrClassNode().visitOuterClass(owner, name, desc); } /* * (non-Javadoc) * * @see org.objectweb.asm.ClassVisitor#visitSource(java.lang.String, * java.lang.String) */ public void visitSource(String source, String debug) { this.methodBlockCache.getCurrClassNode().visitSource(source, debug); } } 1.1 jop/java/tools/src/wcet/components/graphbuilder/methodgb/MethodBlock.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/components/graphbuilder/methodgb/MethodBlock.java?rev=1.1&content-type=text/x-cvsweb-markup Index: MethodBlock.java =================================================================== /** * */ package wcet.components.graphbuilder.methodgb; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.LinkedHashMap; import org.objectweb.asm.Label; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; import wcet.components.graphbuilder.basicblockgb.JOPInsnNode; import wcet.components.graphbuilder.util.IMethodBlockCache; import wcet.framework.exceptions.TaskInitException; import wcet.framework.interfaces.instruction.IJOPMethodVisitor; /** * @author Elena Axamitova * @version 0.4 20.01.2007 * * Interim representation of a method invocation. Used in the first part of the * cotrol flow graph creaion. */ // TODO find all possible implementations of a method - in resolve() if possible // TODO handle inner classes - enclosed in a method (?method parameter access) public class MethodBlock extends MethodNode implements IJOPMethodVisitor{ /** * cache used to search for method block */ private static IMethodBlockCache methodCache; /** * enclosing class of the method */ private String owner; /** * source file from which this method's class was compiled */ private String source; /** * all labels in the method sorted by their order in the method bytecode */ private ArrayList<Label> labels; /** * method keys and method blocks of methods called from this method */ private LinkedHashMap<MethodKey, MethodBlock> children; private boolean resolved = false; /** * Get method blocks of method's children. Before this method is called, * only children keys are stored in the children map, all method blocks * are null. * * @throws TaskInitException */ public void resolve() throws TaskInitException { if (!resolved) { this.constructChildren(); Iterator<MethodBlock> blockIterator = this.children.values() .iterator(); while (blockIterator.hasNext()) { blockIterator.next().resolve(); } this.resolved = true; } } public static void setMBCache(IMethodBlockCache cache){ MethodBlock.methodCache = cache; } /** * @return method enclosing class */ public String getOwner() { return this.owner; } /** * @return file name ffrom which this method's enclosing class was * compiled. */ public String getSourceFile() { return this.source; } /** * Get child method block. * * @param key - * key of the child method * @return Method block of the child identified by the key */ public MethodBlock getChild(MethodKey key) { return children.get(key); } // /** // * Get the predecessor label. // * // * @param label - label of this method // * @return label immediately before the parameter in the bytecode // */ // public Label getPreviousLabel(Label label) { // int labelPosition = this.labels.indexOf(label); // return this.labels.get(labelPosition - 1); // } // // /** // * Get the successor label. // * // * @param label - label of this method // * @return label immediately after the parameter in the bytecode // */ // public Label getNextLabel(Label label) { // int labelPosition = this.labels.indexOf(label); // return this.labels.get(labelPosition + 1); // } // // /** // * Compare positions of two labels. // * // * @param l1 - first label // * @param l2 - second label // * @return 0 if equal, positive if l1 before l2, negative if l1 after // l2 // */ // public int compareLabelPosition(Label l1, Label l2) { // int idx1 = this.labels.indexOf(l1); // int idx2 = this.labels.indexOf(l2); // return idx2-idx1; // } /** * Constructor called from ClassNode when reading the class bytecode. * * @param owner - * method enclosing class * @param source * -source of the owner * @param access - * access flags of the method * @param name - * name of the method * @param desc - * mehod desriptor * @param signature - * method signature (generic information) * @param exceptions - * exception class names that can be thrown */ public MethodBlock(String owner, String source, final int access, final String name, final String desc, final String signature, final String[] exceptions) { super(access, name, desc, signature, exceptions); this.owner = owner; this.source = source; this.children = new LinkedHashMap<MethodKey, MethodBlock>(); this.labels = new ArrayList<Label>(); } /* * (non-Javadoc) * * @see org.objectweb.asm.tree.MethodNode#visitMethodInsn(int, * java.lang.String, java.lang.String, java.lang.String) */ @Override public void visitMethodInsn(final int opcode, final String owner, final String name, final String desc) { this.children.put(new MethodKey(owner, name, desc), null); instructions.add(new MethodInsnNode(opcode, owner, name, desc)); } @Override public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) { super.visitLookupSwitchInsn(dflt, keys, labels); this.labels.add(dflt); this.labels.addAll(Arrays.asList(labels)); } @Override public void visitTableSwitchInsn(int min, int max, Label dflt, Label[] labels) { super.visitTableSwitchInsn(min, max, dflt, labels); this.labels.add(dflt); this.labels.addAll(Arrays.asList(labels)); } public void visitTryCatchBlock(Label start, Label end, Label handler, String type) { super.visitTryCatchBlock(start, end, handler, type); this.labels.add(start); this.labels.add(end); this.labels.add(handler); } /* * (non-Javadoc) * * @see org.objectweb.asm.tree.MethodNode#visitJumpInsn(int, * org.objectweb.asm.Label) */ @Override public void visitJumpInsn(int opc, Label label) { super.visitJumpInsn(opc, label); this.labels.add(label); } /* (non-Javadoc) * @see wcet.framework.interfaces.instruction.IJOPMethodVisitor#visitJOPInsn(int) */ public void visitJOPInsn(int opCode) { instructions.add(new JOPInsnNode(opCode)); } public boolean isJumpLabel(Label label) { return this.labels.contains(label); } /** * Resolve children method keys into corresponding method blocks. It is * called only for methods realy needed in the graph. * * @throws TaskInitException */ private void constructChildren() throws TaskInitException { Iterator<MethodKey> keyIterator = this.children.keySet().iterator(); while (keyIterator.hasNext()) { MethodKey currKey = keyIterator.next(); MethodBlock currChild = methodCache.getMethodBlock(currKey); // I could call resolve on the currChild right here // but this way it should better use the methodBlockCache. // Maybe I will try it later. // System.out.println(currKey.getOwner() // +":"+currKey.getName()+":"+currKey.getDecription()); this.children.put(currKey, currChild); } } protected void replaceChild(MethodKey oldChild, MethodKey newChild){ if (this.children.containsKey(oldChild)&&(this.children.get(oldChild)==null) ){ this.children.remove(oldChild); if(newChild!=null) this.children.put(newChild, null); } } } 1.1 jop/java/tools/src/wcet/components/graphbuilder/methodgb/MethodGraphBuilder.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/components/graphbuilder/methodgb/MethodGraphBuilder.java?rev=1.1&content-type=text/x-cvsweb-markup Index: MethodGraphBuilder.java =================================================================== /** * */ package wcet.components.graphbuilder.methodgb; import java.io.File; import org.objectweb.asm.ClassVisitor; import wcet.components.graphbuilder.IGraphBuilderConstants; import wcet.components.graphbuilder.util.FileList; import wcet.components.graphbuilder.util.FileListPool; import wcet.components.graphbuilder.util.IFileList; //import wcet.components.graphbuilder.util.MethodBlockCache; import wcet.components.graphbuilder.util.ZipFileList; import wcet.framework.exceptions.InitException; import wcet.framework.interfaces.general.IAnalyserComponent; import wcet.framework.interfaces.general.IDataStore; import wcet.framework.interfaces.general.IDataStoreKeys; import wcet.framework.interfaces.general.IGlobalComponentOrder; /** * @author Elena Axamitova * @version 0.1 20.01.2007 * * Creates graph consisting of method blocks of the methods called in the * analysed application. Calls to methods of the Native class are replaced * by the corresponding bytecode instruction. Java methods for bytecodes implemented * in java are not included yet. */ public class MethodGraphBuilder implements IAnalyserComponent { /** * Shared data store */ private IDataStore dataStore = null; /** * file list containing all class files needed */ private IFileList classFileList = null; private MBCacheVisitor methodBlockCacheVisitor; public MethodGraphBuilder(IDataStore dataStore) { this.dataStore = dataStore; } /* * (non-Javadoc) * * @see wcet.interfaces.general.IAnalyserComponent#getOnlyOne() */ public boolean getOnlyOne() { return true; } /* * (non-Javadoc) * * @see wcet.interfaces.general.IAnalyserComponent#getOrder() */ public int getOrder() { return IGlobalComponentOrder.GRAPH_BUILDER + IGraphBuilderConstants.METHOD_GRAPH_BUILDER; } /* * (non-Javadoc) * * @see wcet.interfaces.general.IAnalyserComponent#init() */ public void init() throws InitException { this.initClassFileList(); this.methodBlockCacheVisitor = new MBCacheVisitor(this.classFileList); this.dataStore.storeObject(IGraphBuilderConstants.LAST_MB_CLASS_VISITOR_KEY, this.methodBlockCacheVisitor); MethodBlock.setMBCache(this.methodBlockCacheVisitor); } /* * (non-Javadoc) * * @see java.util.concurrent.Callable#call() */ public String call() throws Exception { // close the method visitor chain ClassVisitor filter = (ClassVisitor)this.dataStore.getObject(IGraphBuilderConstants.LAST_MB_CLASS_VISITOR_KEY); this.methodBlockCacheVisitor.setFilter(filter); //change task name to java internal name conform String className = this.dataStore.getTask().replace('.', '/'); String mainMethodName = this.dataStore.getMainMethodName(); String mainMethodDescriptor = this.dataStore.getMainMethodDescriptor(); //create the root method block - read in from class file and store keys (only keys) //of all methods called in it - its children MethodKey rootKey = new MethodKey( className, //use default values if not else provided mainMethodName == null ? IGraphBuilderConstants.MAIN_METHOD_NAME_DEFAULT : mainMethodName, mainMethodDescriptor == null ? IGraphBuilderConstants.MAIN_METHOD_DESCRIPTOR_DEFAULT : mainMethodDescriptor); MethodBlock rootBlock = this.methodBlockCacheVisitor.getMethodBlock(rootKey); //construct children - create method blocks for stored method keys rootBlock.resolve(); this.dataStore.storeObject( IGraphBuilderConstants.METHOD_BLOCK_TREE_ROOT_KEY, rootBlock); return "+++ The MethodBlockBuilder component ended successfully.+++\n"; } private void initClassFileList()throws InitException{ // if classpath given, construct file list that searches for //class files in the directories on the classpath if (this.dataStore.getClasspath() != null) { //init application classes file lisr FileListPool flPool = new FileListPool(); String classPath = this.dataStore.getClasspath() + File.pathSeparator + this.dataStore .getObject(IGraphBuilderConstants.JOP_JDK_CLASSPATH_KEY); FileList classFileList = new FileList(classPath, ".class"); classFileList.findAllFiles(); flPool.addFileList(classFileList); //init jop system classes file list String jopSystemPath = (String)this.dataStore.getObject(IGraphBuilderConstants.JOP_SYSTEM_CLASSPATH_KEY); FileList jopSystemFileList = new FileList(jopSystemPath, ".class"); jopSystemFileList.findAllFiles(); flPool.addFileList(jopSystemFileList); this.classFileList = flPool; } else { //else if zip file path given, create ZipFileList for the zip file path String zipPath = (String) this.dataStore .getObject(IDataStoreKeys.ZIP_CLASSFILE_KEY); if (zipPath != null) { this.classFileList = new ZipFileList(zipPath, ".class"); } else { //as a last resort try to find the zip file in the location where //jop design flow saves the input for JOPizer - default String jopHome = (String)this.dataStore.getObject(IGraphBuilderConstants.JOP_HOME_KEY); if (!jopHome.endsWith("/")) jopHome+="/"; String zipPathDefault = jopHome + IGraphBuilderConstants.ZIP_CLASSES_DEFAULT_REL_PATH; zipPathDefault.replace('\\', '/'); this.classFileList = new ZipFileList(zipPathDefault, ".class"); } } } } 1.1 jop/java/tools/src/wcet/components/graphbuilder/methodgb/MethodKey.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/components/graphbuilder/methodgb/MethodKey.java?rev=1.1&content-type=text/x-cvsweb-markup Index: MethodKey.java =================================================================== /** * */ package wcet.components.graphbuilder.methodgb; /** * @author Elena Axamitova * @version 0.1 22.01.2007 * * Method identifier. */ public class MethodKey { /** * enclosing class name */ private String owner; /** * name of the method */ private String name; /** * desriptor of the method (java class file method descriptor format) */ private String description; /** * Construct new method key for the data. Cannot be changed later. * @param o - method owner class * @param n - method name * @param d - method deriptor */ public MethodKey(String o, String n, String d) { this.owner = o.replace('.', '/'); this.name = n; this.description = d; } /** * @return method class */ public String getOwner() { return this.owner; } /** * @return method name */ public String getName() { return this.name; } /** * @return method descriptor */ public String getDecription() { return this.description; } /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object o) { if (o == null) return false; MethodKey obj = (MethodKey) o; boolean result = ((obj.owner.equals(this.owner)) && (obj.description.equals(this.description)) && (obj.name .equals(this.name))); return result; } /* (non-Javadoc) * @see java.lang.Object#hashCode() */ @Override public int hashCode() { // needed, since MethodKey is used as a key in HashMaps //must be conform to equals(.) return (new String(this.getOwner() + "$" + this.getName() + "$" + this.getDecription())).hashCode(); } /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { return this.getOwner() + "||" + this.getName() + "||" + this.getDecription(); } }

     
    Copyright (c) 1999 OPENCORES.ORG. All rights reserved.