62 import com.sun.tools.classfile.LocalVariableTable_attribute; |
62 import com.sun.tools.classfile.LocalVariableTable_attribute; |
63 import com.sun.tools.classfile.Method; |
63 import com.sun.tools.classfile.Method; |
64 |
64 |
65 import static javax.tools.StandardLocation.*; |
65 import static javax.tools.StandardLocation.*; |
66 import static com.sun.tools.classfile.LocalVariableTable_attribute.Entry; |
66 import static com.sun.tools.classfile.LocalVariableTable_attribute.Entry; |
|
67 import static javax.tools.JavaFileObject.Kind.SOURCE; |
67 |
68 |
68 public class LVTHarness { |
69 public class LVTHarness { |
69 |
70 |
70 static int nerrors = 0; |
71 static int nerrors = 0; |
71 |
72 |
72 static final JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); |
73 static final JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); |
73 static final StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); |
74 static final StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); |
74 |
75 |
75 public static void main(String[] args) throws Exception { |
76 public static void main(String[] args) throws Exception { |
76 fm.setLocation(SOURCE_PATH, |
77 |
77 Arrays.asList(new File(System.getProperty("test.src"), "tests"))); |
78 String testDir = System.getProperty("test.src"); |
78 for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", |
79 fm.setLocation(SOURCE_PATH, Arrays.asList(new File(testDir, "tests"))); |
79 Collections.singleton(JavaFileObject.Kind.SOURCE), true)) { |
80 |
|
81 // Make sure classes are written to scratch dir. |
|
82 fm.setLocation(CLASS_OUTPUT, Arrays.asList(new File("."))); |
|
83 |
|
84 for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(SOURCE), true)) { |
80 new LVTHarness(jfo).check(); |
85 new LVTHarness(jfo).check(); |
81 } |
86 } |
82 if (nerrors > 0) { |
87 if (nerrors > 0) { |
83 throw new AssertionError("Errors were found"); |
88 throw new AssertionError("Errors were found"); |
84 } |
89 } |
85 } |
90 } |
86 |
91 |
87 |
92 |
88 JavaFileObject jfo; |
93 JavaFileObject jfo; |
89 Map<ElementKey, AliveRanges> aliveRangeMap = |
94 Map<ElementKey, AliveRanges> aliveRangeMap = new HashMap<>(); |
90 new HashMap<ElementKey, AliveRanges>(); |
|
91 Set<String> declaredKeys = new HashSet<>(); |
95 Set<String> declaredKeys = new HashSet<>(); |
92 List<ElementKey> seenAliveRanges = new ArrayList<>(); |
96 List<ElementKey> seenAliveRanges = new ArrayList<>(); |
93 |
97 |
94 protected LVTHarness(JavaFileObject jfo) { |
98 protected LVTHarness(JavaFileObject jfo) { |
95 this.jfo = jfo; |
99 this.jfo = jfo; |
96 } |
100 } |
97 |
101 |
98 protected void check() throws Exception { |
102 protected void check() throws Exception { |
99 JavacTask ct = (JavacTask)comp.getTask(null, fm, null, Arrays.asList("-g"), |
103 |
100 null, Arrays.asList(jfo)); |
104 JavacTask ct = (JavacTask) comp.getTask(null, fm, null, Arrays.asList("-g"), |
101 System.err.println("compiling code " + jfo.toString()); |
105 null, Arrays.asList(jfo)); |
|
106 System.err.println("compiling code " + jfo); |
102 ct.setProcessors(Collections.singleton(new AliveRangeFinder())); |
107 ct.setProcessors(Collections.singleton(new AliveRangeFinder())); |
103 if (!ct.call()) { |
108 if (!ct.call()) { |
104 throw new AssertionError("Error during compilation"); |
109 throw new AssertionError("Error during compilation"); |
105 } |
110 } |
106 |
111 |
107 checkClassFile(new File(jfo.getName().replace(".java", ".class"))); |
112 |
|
113 File javaFile = new File(jfo.getName()); |
|
114 File classFile = new File(javaFile.getName().replace(".java", ".class")); |
|
115 checkClassFile(classFile); |
108 |
116 |
109 //check all candidates have been used up |
117 //check all candidates have been used up |
110 for (Map.Entry<ElementKey, AliveRanges> entry : aliveRangeMap.entrySet()) { |
118 for (Map.Entry<ElementKey, AliveRanges> entry : aliveRangeMap.entrySet()) { |
111 if (!seenAliveRanges.contains(entry.getKey())) { |
119 if (!seenAliveRanges.contains(entry.getKey())) { |
112 error("Redundant @AliveRanges annotation on method " + |
120 error("Redundant @AliveRanges annotation on method " + |