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
  • Find Resources
  • 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:57:07 CEST 2007
    Subject: [cvs-checkins] MODIFIED: jop ...
    Top
    Date: 00/07/07 24:14:57

    Added: jop/java/tools/src/wcet/components/graphbuilder/util
    FileList.java FileListPool.java IFileList.java
    IMethodBlockCache.java MethodBlockCache.java
    MethodBlockClassNode.java ZipFileList.java
    Log:



    Revision Changes Path
    1.1 jop/java/tools/src/wcet/components/graphbuilder/util/FileList.java

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

    Index: FileList.java
    ===================================================================
    /**
    *
    */
    package wcet.components.graphbuilder.util;

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.InputStream;
    import java.util.HashMap;
    import java.util.StringTokenizer;

    import wcet.framework.exceptions.InitException;

    /**
    * @author Elena Axamitova
    * @version 0.3 09.01.2007
    *
    * Provides InputStream for files stored in a file system.
    */
    public class FileList implements IFileList {

    /**
    * map containing files stored by file names
    */
    private HashMap<String, String> files = null;

    /**
    * path to look for files
    */
    private String path = null;

    /**
    * extension of the files to look for
    */
    private String extension = null;

    /**
    * Construct a new FileList.
    *
    * @param p -
    * path to look for files
    * @param e -
    * extension of the files needed
    * @throws InitException
    */
    public FileList(String p, String e) throws InitException {
    if ((p != null) && (e != null)) {
    this.path = p;
    this.extension = e;
    this.files = new HashMap<String, String>();
    } else {
    throw new InitException(
    "GB:FileList: Path or file extension to search for not specified.");
    }
    }

    /**
    * Find all files with the provided extension in the path given.
    */
    public void findAllFiles() {
    StringTokenizer stClass = new StringTokenizer(this.path,
    File.pathSeparator);
    while (stClass.hasMoreTokens()) {// "java/target/src/common";
    this.findAllFiles(new File(stClass.nextToken()));
    }
    }

    /**
    * Get whole path of the file fileName
    *
    * @param fileName -
    * name of the file
    * @return whole path to the file fileName
    */
    public String getFilePath(String fileName) {
    int idx = fileName.lastIndexOf('/');
    // if(idx==-1){
    // idx=0;// fileName.length();
    // }
    String className = fileName.substring(idx + 1, fileName.length());
    String paths = this.files.get(className);
    if (paths == null)
    return null;
    StringTokenizer tokenizer = new StringTokenizer(paths,
    File.pathSeparator); while (tokenizer.hasMoreTokens()) { String path = tokenizer.nextToken(); if (this.getNameWithoutSuffix(path).endsWith(fileName)) return path; } return null; } /* * (non-Javadoc) * * @see wcet.components.graphbuilder.util.IFileList#getFileInputStream(java.lang.String) */ public InputStream getFileInputStream(String fileName) { String path = this.getFilePath(fileName); if (path == null) return null; else try { return new FileInputStream(path); } catch (FileNotFoundException e) { return null; } } /* P R I V A T E M E T H O D S */ /** * Find all files in the parent file given * * @param item - * File(directory) to search in */ private void findAllFiles(File item) { if (item.isDirectory()) { String[] children = item.list(); for (int i = 0; i < children.length; i++) { this.findAllFiles(new File(item, children[i])); } } else { String filePath = item.getAbsolutePath(); String fileName = item.getName(); if (fileName.endsWith(this.extension)) { String oldPath = this.files.get(fileName); if (oldPath != null) { filePath = oldPath + File.pathSeparator + filePath; } fileName = this.getNameWithoutSuffix(fileName); // System.out.println(this.extension+" files: Key " + fileName + // " Path:" // + filePath); files.put(fileName, filePath); } } } /** * Remove file name suffix * * @param fileName * @return */ private String getNameWithoutSuffix(String fileName) { fileName = fileName.replace('\\', '/'); return fileName.substring(0, fileName.lastIndexOf('.')); } } 1.1 jop/java/tools/src/wcet/components/graphbuilder/util/FileListPool.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/components/graphbuilder/util/FileListPool.java?rev=1.1&content-type=text/x-cvsweb-markup Index: FileListPool.java =================================================================== /** * */ package wcet.components.graphbuilder.util; import java.io.InputStream; import java.util.HashSet; import java.util.Iterator; /** * @author Elena Axamitova * @version 0.1 22.07.2007 */ public class FileListPool implements IFileList { HashSet<IFileList> fileList; public FileListPool(){ this.fileList = new HashSet<IFileList>(); } /* (non-Javadoc) * @see wcet.components.graphbuilder.util.IFileList#getFileInputStream(java.lang.String) */ public InputStream getFileInputStream(String fileName) { Iterator<IFileList> iterator = this.fileList.iterator(); while(iterator.hasNext()){ IFileList currFileList = iterator.next(); InputStream fileInpStream = currFileList.getFileInputStream(fileName); if(fileInpStream!=null) return fileInpStream; } return null; } public void addFileList(IFileList fl){ this.fileList.add(fl); } } 1.1 jop/java/tools/src/wcet/components/graphbuilder/util/IFileList.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/components/graphbuilder/util/IFileList.java?rev=1.1&content-type=text/x-cvsweb-markup Index: IFileList.java =================================================================== /** * */ package wcet.components.graphbuilder.util; import java.io.InputStream; /** * @author Elena Axamitova * @version 0.1 04.06.2007 * * Provides InputStreams for the content of files stored by names. */ public interface IFileList { /** * Get the InputStream of the file FileName * @param fileName - name of the file that is needed * @return InputStream of the file fileName */ public InputStream getFileInputStream(String fileName); } 1.1 jop/java/tools/src/wcet/components/graphbuilder/util/IMethodBlockCache.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/components/graphbuilder/util/IMethodBlockCache.java?rev=1.1&content-type=text/x-cvsweb-markup Index: IMethodBlockCache.java =================================================================== /** * */ package wcet.components.graphbuilder.util; import wcet.components.graphbuilder.methodgb.MethodBlock; import wcet.components.graphbuilder.methodgb.MethodKey; import wcet.framework.exceptions.TaskInitException; /** * @author Elena Axamitova * @version 0.1 23.07.2007 */ public interface IMethodBlockCache { public MethodBlock getMethodBlock(MethodKey key) throws TaskInitException; } 1.1 jop/java/tools/src/wcet/components/graphbuilder/util/MethodBlockCache.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/components/graphbuilder/util/MethodBlockCache.java?rev=1.1&content-type=text/x-cvsweb-markup Index: MethodBlockCache.java =================================================================== /** * */ package wcet.components.graphbuilder.util; import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.tree.ClassNode; import wcet.components.graphbuilder.IGraphBuilderConstants; import wcet.components.graphbuilder.methodgb.MethodBlock; import wcet.components.graphbuilder.methodgb.MethodKey; import wcet.framework.exceptions.TaskInitException; /** * @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. */ // TODO does not handle Interfaces and abstract classes (? here ?) public class MethodBlockCache implements IMethodBlockCache{ /** * load factor of the map storing method blocks. */ private static final float LOAD_FACTOR = 0.75f; /** * FileList that provides InputStreams for new classes */ private IFileList fileList = null; /** * the method map (all method blocks of a class) cache */ private LinkedHashMap<String, MethodMap> classMap = null; private ClassVisitor filer; private ClassNode currClassNode; /** * Construct a new cache that uses the provided file list * @param fl - file list to get class input streams from */ public MethodBlockCache(IFileList fl) { this.fileList = fl; this.classMap = new LinkedHashMap<String, MethodMap>( IGraphBuilderConstants.CAPACITY, MethodBlockCache.LOAD_FACTOR, //true means least recently accessed strategy true) { protected boolean removeEldestEntry( Map.Entry<String, MethodMap> eldest) { return this.size() > IGraphBuilderConstants.CAPACITY; } }; } /** * 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 { MethodMap classMethods = this.classMap.get(key.getOwner()); if (classMethods == null) { //not in cache classMethods = new MethodMap(this .constructClassNode(key.getOwner())); this.classMap.put(key.getOwner(), classMethods); } return classMethods.getNode(key); } public ClassNode getCurrClassNode(){ return this.currClassNode; } public void setFilter(ClassVisitor f){ this.filer = f; } /** * Constructs a cache entry (map of all method blocks of this class) for * the given class name. * * @param className - name of the class that contains the required method * @return * @throws TaskInitException - when problems reading class file */ private ClassNode constructClassNode(String className) throws TaskInitException { //read the class ClassReader classReader; try { classReader = new ClassReader(this.fileList .getFileInputStream(className)); } catch (IOException e) { throw new TaskInitException(e); } // works as a normal ClassNode, only instead of MethodNodes //creates MethodBlocks this.currClassNode = new MethodBlockClassNode(); if(this.filer!=null) classReader.accept(this.filer, ClassReader.SKIP_FRAMES); else classReader.accept(this.currClassNode, ClassReader.SKIP_FRAMES); return this.currClassNode; } /** * Map that contains all method blocks of the class it is constructed for, * stored by method key. * * @author Elena Axamitova * @version 0.1 04.06.2007 */ private class MethodMap { private HashMap<MethodKey, MethodBlock> methods; // TODO find the worst method implementation, not just the first. // or find all implementations, hang them on the graph and let the lp // solver // find the worst (cache). /** * name of the superclass, needed when resolving inherited methods */ private String superName; // TODO handle interfaces (complex) /** * all implemented interfaces */ private String[] interfaces = new String[3]; @SuppressWarnings("unchecked") MethodMap(ClassNode classNode) { this.superName = classNode.superName; List<String> toArray = classNode.interfaces; this.interfaces = toArray.toArray(this.interfaces); this.methods = new HashMap<MethodKey, MethodBlock>(); List<MethodBlock> methodList = classNode.methods; Iterator<MethodBlock> iterator = methodList.iterator(); while (iterator.hasNext()) { MethodBlock tempNode = iterator.next(); methods.put(new MethodKey(classNode.name, tempNode.name, tempNode.desc), tempNode); } } /** * Get the method block for the key. If not found, search * superclass. * * @param key - key of the method needed * @return * @throws TaskInitException */ MethodBlock getNode(MethodKey key) throws TaskInitException { // methods.containsKey(key); MethodBlock result = methods.get(key); if (result == null) { if (this.superName == null) { throw new TaskInitException("Method name: " + key.getName() + " description:" + key.getDecription() + " not found."); } else { MethodKey superKey = new MethodKey(this.superName, key .getName(), key.getDecription()); result = getMethodBlock(superKey); } } return result; } } } 1.1 jop/java/tools/src/wcet/components/graphbuilder/util/MethodBlockClassNode.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/components/graphbuilder/util/MethodBlockClassNode.java?rev=1.1&content-type=text/x-cvsweb-markup Index: MethodBlockClassNode.java =================================================================== /** * */ package wcet.components.graphbuilder.util; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.tree.ClassNode; import wcet.components.graphbuilder.methodgb.MethodBlock; /** * @author Elena Axamitova * @version 0.1 21.07.2007 */ public class MethodBlockClassNode extends ClassNode { @SuppressWarnings("unchecked") @Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { MethodBlock mn = new MethodBlock(this.name, this.sourceFile, access, name, desc, signature, exceptions); methods.add(mn); return mn; } } 1.1 jop/java/tools/src/wcet/components/graphbuilder/util/ZipFileList.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/wcet/components/graphbuilder/util/ZipFileList.java?rev=1.1&content-type=text/x-cvsweb-markup Index: ZipFileList.java =================================================================== /** * */ package wcet.components.graphbuilder.util; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import wcet.framework.exceptions.InitException; /** * @author Elena Axamitova * @version 0.1 03.06.2007 * * Provides InputStream for files stored in a zip file. */ public class ZipFileList implements IFileList{ /** * zip file containing files of the application */ private ZipFile zipFile; /** * file extension of the files */ private String extension = null; public ZipFileList(String p, String e) throws InitException { if ((p != null) && (e != null)) { try { this.zipFile = new ZipFile(p); } catch (IOException e1) { throw new InitException(e1); } this.extension = e; } else { throw new InitException( "ZipFileList: Path or file extension to search for not specified."); } } /* (non-Javadoc) * @see wcet.components.graphbuilder.util.IFileList#getFileInputStream(java.lang.String) */ public InputStream getFileInputStream(String fileName) { String namePlusExt = fileName + this.extension; //complete file name provided ZipEntry zipEntry = this.zipFile.getEntry(namePlusExt); if (zipEntry == null) //only part of the fileName given, find //zip entry that matches zipEntry = this.searchFor(fileName); if (zipEntry == null) return null; else try { return this.zipFile.getInputStream(zipEntry); } catch (IOException e) { return null; } } /* P R I V A T E M E T H O D S */ /** * Search for a file whose name ends with the given fileName * @param fileName - name of the file to search for * @return - the corresponding zip entry, null when not found */ private ZipEntry searchFor(String fileName) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().endsWith(fileName + this.extension)) return entry; } return null; } }

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