73 |
73 |
74 String[] jpArgs = { "-classpath", ".", "-c", "E" }; |
74 String[] jpArgs = { "-classpath", ".", "-c", "E" }; |
75 |
75 |
76 StringWriter sw = new StringWriter(); |
76 StringWriter sw = new StringWriter(); |
77 javap(new PrintWriter(sw, true), jpArgs); |
77 javap(new PrintWriter(sw, true), jpArgs); |
78 check(sw.toString(), "//Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V"); |
78 check(sw.toString(), "// Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V"); |
79 callValues(); |
79 callValues(); |
80 } |
80 } |
81 |
81 |
82 void compile(String... args) { |
82 void compile(String... args) { |
83 int rc = com.sun.tools.javac.Main.compile(args); |
83 int rc = com.sun.tools.javac.Main.compile(args); |
84 if (rc != 0) |
84 if (rc != 0) |
85 throw new Error("javac failed: " + Arrays.asList(args) + ": " + rc); |
85 throw new Error("javac failed: " + Arrays.asList(args) + ": " + rc); |
86 } |
86 } |
87 |
87 |
88 void javap(PrintWriter out, String... args) throws Exception { |
88 void javap(PrintWriter out, String... args) throws Exception { |
89 // for now, we have to exec javap |
89 int rc = com.sun.tools.javap.Main.run(args, out); |
90 File javaHome = new File(System.getProperty("java.home")); |
|
91 if (javaHome.getName().equals("jre")) |
|
92 javaHome = javaHome.getParentFile(); |
|
93 File javap = new File(new File(javaHome, "bin"), "javap"); |
|
94 String[] cmd = new String[args.length + 1]; |
|
95 cmd[0] = javap.getPath(); |
|
96 System.arraycopy(args, 0, cmd, 1, args.length); |
|
97 Process p = new ProcessBuilder(cmd).redirectErrorStream(true).start(); |
|
98 p.getOutputStream().close(); |
|
99 BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); |
|
100 String line; |
|
101 while ((line = in.readLine()) != null) |
|
102 out.println(line); |
|
103 int rc = p.waitFor(); |
|
104 if (rc != 0) |
90 if (rc != 0) |
105 throw new Error("javap failed: " + Arrays.asList(args) + ": " + rc); |
91 throw new Error("javap failed: " + Arrays.asList(args) + ": " + rc); |
106 } |
92 } |
107 |
93 |
108 void check(String s, String require) { |
94 void check(String s, String require) { |
|
95 System.out.println("Checking:\n" + s); |
109 if (s.indexOf(require) == -1) { |
96 if (s.indexOf(require) == -1) { |
110 System.err.println("Can't find " + require); |
97 System.err.println("Can't find " + require); |
111 errors++; |
98 errors++; |
112 } |
99 } |
113 } |
100 } |