Esempio n. 1
0
 private static void cullClasses(boolean found, int depth) {
   if (found && depth < 3) {
     for (ByteCodeClass bc : classes) {
       bc.updateAllDependencies();
     }
     // int classCount = classes.size();
     ByteCodeClass.markDependencies(classes);
     List<ByteCodeClass> tmp = ByteCodeClass.clearUnmarked(classes);
     /*if(ByteCodeTranslator.verbose) {
     System.out.println("Classes removed from: " + classCount + " to " + classes.size());
     for(ByteCodeClass bc : classes) {
     if(!tmp.contains(bc)) {
     System.out.println("Removed class: " + bc.getClsName());
     }
     }
     }*/
     classes = tmp;
     eliminateUnusedMethods(depth + 1);
   }
 }
Esempio n. 2
0
  public static void writeOutput(File outputDirectory) throws Exception {
    System.out.println("outputDirectory is: " + outputDirectory.getAbsolutePath());
    if (ByteCodeClass.getMainClass() == null) {
      System.out.println(
          "Error main class is not defined. The main class name is expected to have a public static void main(String[]) method and it is assumed to reside in the com.package.name directory");
      System.exit(1);
    }
    String file = "Unknown File";
    try {
      for (ByteCodeClass bc : classes) {
        // special case for object
        if (bc.getClsName().equals("java_lang_Object")) {
          continue;
        }
        file = bc.getClsName();
        bc.setBaseClassObject(getClassByName(bc.getBaseClass()));
        List<ByteCodeClass> lst = new ArrayList<ByteCodeClass>();
        for (String s : bc.getBaseInterfaces()) {
          ByteCodeClass bcode = getClassByName(s);
          if (bcode == null) {
            System.out.println(
                "Error while working with the class: "
                    + s
                    + " file:"
                    + file
                    + " no class definition");
          } else {
            lst.add(getClassByName(s));
          }
        }
        bc.setBaseInterfacesObject(lst);
      }
      for (ByteCodeClass bc : classes) {
        file = bc.getClsName();
        bc.updateAllDependencies();
      }
      ByteCodeClass.markDependencies(classes);
      classes = ByteCodeClass.clearUnmarked(classes);

      // load the native sources (including user native code)
      readNativeFiles(outputDirectory);

      // loop over methods and start eliminating the body of unused methods
      eliminateUnusedMethods();

      generateClassAndMethodIndexHeader(outputDirectory);

      boolean concatenate = "true".equals(System.getProperty("concatenateFiles", "false"));
      ConcatenatingFileOutputStream cos =
          concatenate ? new ConcatenatingFileOutputStream(outputDirectory) : null;

      for (ByteCodeClass bc : classes) {
        file = bc.getClsName();
        writeFile(bc, outputDirectory, cos);
      }
      if (cos != null) cos.realClose();

    } catch (Throwable t) {
      System.out.println("Error while working with the class: " + file);
      t.printStackTrace();
      if (t instanceof Exception) {
        throw (Exception) t;
      }
      if (t instanceof RuntimeException) {
        throw (RuntimeException) t;
      }
    }
  }