aboutsummaryrefslogtreecommitdiff
path: root/src/test/javassist/bytecode/CodeAnalyzerTest.java
blob: b6b331893460d7f4e6c4eb6ad8eb11a7b41910a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package javassist.bytecode;

import java.util.zip.*;
import java.util.Enumeration;
import java.util.List;
import java.io.*;

@SuppressWarnings({"rawtypes","resource"})
public class CodeAnalyzerTest {
    public static void main(String[] args) throws Exception {
        ZipFile zfile = new ZipFile(args[0]);
        Enumeration e = zfile.entries();
        while (e.hasMoreElements()) {
            ZipEntry zip = (ZipEntry)e.nextElement();
            if (zip.getName().endsWith(".class"))
                test(zfile.getInputStream(zip));
        }
    }

    static void test(InputStream is) throws Exception {
        is = new BufferedInputStream(is);
        ClassFile cf = new ClassFile(new DataInputStream(is));
        is.close();
        List list = cf.getMethods();
        int n = list.size();
        for (int i = 0; i < n; ++i) {
            MethodInfo minfo = (MethodInfo)list.get(i);
            CodeAttribute ca = minfo.getCodeAttribute();
            if (ca != null) {
                try {
                    int max = ca.getMaxStack();
                    int newMax = ca.computeMaxStack();
                    if (max != newMax)
                        System.out.println(max + " -> " + newMax +
                                           " for " + minfo.getName() + " (" +
                                           minfo.getDescriptor() + ") in " +
                                           cf.getName());
                }
                catch (BadBytecode e) {
                    System.out.println(e.getMessage() +
                                       " for " + minfo.getName() + " (" +
                                       minfo.getDescriptor() + ") in " +
                                       cf.getName());
                }
            }
        }
    }
}