hotspot/agent/make/ClosureFinder.java
author roland
Wed, 14 Sep 2011 09:22:51 +0200
changeset 11196 a310a659c580
parent 5547 f4b087cbb361
permissions -rw-r--r--
7077312: Provide a CALL effect for instruct declaration in the ad file Summary: abstracted way to declare that the MachNode has the effect of a call (kills caller save registers, preserves callee save registers) Reviewed-by: twisti, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
     2
 * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
/**
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
<p> This class finds transitive closure of dependencies from a given
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
root set of classes. If your project has lots of .class files and you
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
want to ship only those .class files which are used (transitively)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
from a root set of classes, then you can use this utility.  </p> <p>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
How does it work?</p>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
<p> We walk through all constant pool entries of a given class and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
find all modified UTF-8 entries. Anything that looks like a class name is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
considered as a class and we search for that class in the given
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
classpath. If we find a .class of that name, then we add that class to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
list.</p>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
<p> We could have used CONSTANT_ClassInfo type constants only. But
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
that will miss classes used through Class.forName or xyz.class
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
construct.  But, if you refer to a class name in some other string we
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
would include it as dependency :(. But this is quite unlikely
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
anyway. To look for exact Class.forName argument(s) would involve
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
bytecode analysis. Also, we handle only simple reflection. If you
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
accept name of a class from externally (for eg properties file or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
command line args for example, this utility will not be able to find
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
that dependency. In such cases, include those classes in the root set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
</p>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
public class ClosureFinder {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    private Collection roots;            // root class names Collection<String>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    private Map        visitedClasses;   // set of all dependencies as a Map
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    private String     classPath;        // classpath to look for .class files
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    private String[]   pathComponents;   // classpath components
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    private static final boolean isWindows = File.separatorChar != '/';
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    public ClosureFinder(Collection roots, String classPath) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
        this.roots = roots;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
        this.classPath = classPath;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
        parseClassPath();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    // parse classPath into pathComponents array
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    private void parseClassPath() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
        List paths = new ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
        StringTokenizer st = new StringTokenizer(classPath, File.pathSeparator);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
        while (st.hasMoreTokens())
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
            paths.add(st.nextToken());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
        Object[] arr = paths.toArray();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
        pathComponents = new String[arr.length];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
        System.arraycopy(arr, 0, pathComponents, 0, arr.length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    // if output is aleady not computed, compute it now
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    // result is a map from class file name to base path where the .class was found
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    public Map find() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
        if (visitedClasses == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
            visitedClasses = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
            computeClosure();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
        return visitedClasses;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    // compute closure for all given root classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    private void computeClosure() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
        for (Iterator rootsItr = roots.iterator(); rootsItr.hasNext();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
            String name = (String) rootsItr.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
            name = name.substring(0, name.indexOf(".class"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
            computeClosure(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    // looks up for .class in pathComponents and returns
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    // base path if found, else returns null
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    private String lookupClassFile(String classNameAsPath) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
        for (int i = 0; i < pathComponents.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
            File f =  new File(pathComponents[i] + File.separator +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
                               classNameAsPath + ".class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
            if (f.exists()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
                if (isWindows) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
                    String name = f.getName();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
                    // Windows reports special devices AUX,NUL,CON as files
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
                    // under any directory. It does not care about file extention :-(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
                    if (name.compareToIgnoreCase("AUX.class") == 0 ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
                        name.compareToIgnoreCase("NUL.class") == 0 ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
                        name.compareToIgnoreCase("CON.class") == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
                        return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
                return pathComponents[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
        return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    // from JVM spec. 2'nd edition section 4.4
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    private static final int CONSTANT_Class = 7;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    private static final int CONSTANT_FieldRef = 9;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    private static final int CONSTANT_MethodRef = 10;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    private static final int CONSTANT_InterfaceMethodRef = 11;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    private static final int CONSTANT_String = 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    private static final int CONSTANT_Integer = 3;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    private static final int CONSTANT_Float = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    private static final int CONSTANT_Long = 5;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    private static final int CONSTANT_Double = 6;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    private static final int CONSTANT_NameAndType = 12;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    private static final int CONSTANT_Utf8 = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    // whether a given string may be a class name?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    private boolean mayBeClassName(String internalClassName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
        int len = internalClassName.length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
        for (int s = 0; s < len; s++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
            char c = internalClassName.charAt(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
            if (!Character.isJavaIdentifierPart(c) && c != '/')
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
                return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
        return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    // compute closure for a given class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    private void computeClosure(String className) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
        if (visitedClasses.get(className) != null) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
        String basePath = lookupClassFile(className);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
        if (basePath != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
            visitedClasses.put(className, basePath);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
            try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
                File classFile = new File(basePath + File.separator + className + ".class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
                FileInputStream fis = new FileInputStream(classFile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
                DataInputStream dis = new DataInputStream(fis);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
                // look for .class signature
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
                if (dis.readInt() != 0xcafebabe) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
                    System.err.println(classFile.getAbsolutePath() + " is not a valid .class file");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
                    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
                // ignore major and minor version numbers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
                dis.readShort();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
                dis.readShort();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
                // read number of constant pool constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
                int numConsts = (int) dis.readShort();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
                String[] strings = new String[numConsts];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
                // zero'th entry is unused
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
                for (int cpIndex = 1; cpIndex < numConsts; cpIndex++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
                    int constType = (int) dis.readByte();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
                    switch (constType) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
                    case CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
                    case CONSTANT_String:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
                        dis.readShort(); // string name index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
                        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
                    case CONSTANT_FieldRef:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
                    case CONSTANT_MethodRef:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
                    case CONSTANT_InterfaceMethodRef:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
                    case CONSTANT_NameAndType:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
                    case CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
                    case CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
                        // all these are 4 byte constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
                        dis.readInt();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
                        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
                    case CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
                    case CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
                        // 8 byte constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
                        dis.readLong();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
                        // occupies 2 cp entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
                        cpIndex++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
                        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
                    case CONSTANT_Utf8: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
                        strings[cpIndex] = dis.readUTF();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
                        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
                    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
                        System.err.println("invalid constant pool entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
                        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
                    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
            // now walk thru the string constants and look for class names
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
            for (int s = 0; s < numConsts; s++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
                if (strings[s] != null && mayBeClassName(strings[s]))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
                    computeClosure(strings[s].replace('/', File.separatorChar));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
            } catch (IOException exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
                // ignore for now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    // a sample main that accepts roots classes in a file and classpath as args
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    public static void main(String[] args) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
        if (args.length != 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
            System.err.println("Usage: ClosureFinder <root class file> <class path>");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
            System.exit(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
        List roots = new ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
        try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
            FileInputStream fis = new FileInputStream(args[0]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
            DataInputStream dis = new DataInputStream(fis);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
            String line = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
            while ((line = dis.readLine()) != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
                if (isWindows) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
                    line = line.replace('/', File.separatorChar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
                roots.add(line);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
        } catch (IOException exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
            System.err.println(exp.getMessage());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
            System.exit(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
        ClosureFinder cf = new ClosureFinder(roots, args[1]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
        Map out = cf.find();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
        Iterator res = out.keySet().iterator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
        for(; res.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
            String className = (String) res.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
            System.out.println(className + ".class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
}