Mercurial > hg > truffle
comparison graal/com.oracle.max.asmdis/src/com/sun/max/asm/gen/AssemblyTester.java @ 4142:bc8527f3071c
Adjust code base to new level of warnings.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sun, 18 Dec 2011 05:24:06 +0100 |
parents | e233f5660da4 |
children |
comparison
equal
deleted
inserted
replaced
4141:04d21be7a24f | 4142:bc8527f3071c |
---|---|
226 final Iterable<? extends Argument> argumentsIterable = parameter.getLegalTestArguments(); | 226 final Iterable<? extends Argument> argumentsIterable = parameter.getLegalTestArguments(); |
227 final ArgumentRange argumentRange = parameter.argumentRange(); | 227 final ArgumentRange argumentRange = parameter.argumentRange(); |
228 if (argumentRange == null || !argumentRange.appliesInternally()) { | 228 if (argumentRange == null || !argumentRange.appliesInternally()) { |
229 testArgumentIterators[i] = argumentsIterable.iterator(); | 229 testArgumentIterators[i] = argumentsIterable.iterator(); |
230 } else { | 230 } else { |
231 testArgumentIterators[i] = new FilterIterator<Argument>(argumentsIterable.iterator(), new Predicate<Argument>() { | 231 testArgumentIterators[i] = new FilterIterator<>(argumentsIterable.iterator(), new Predicate<Argument>() { |
232 public boolean evaluate(Argument argument) { | 232 public boolean evaluate(Argument argument) { |
233 return argumentRange.includes(argument); | 233 return argumentRange.includes(argument); |
234 } | 234 } |
235 }); | 235 }); |
236 } | 236 } |
281 | 281 |
282 private final String tmpFilePrefix; | 282 private final String tmpFilePrefix; |
283 private static final String SOURCE_EXTENSION = ".s"; | 283 private static final String SOURCE_EXTENSION = ".s"; |
284 private static final String BINARY_EXTENSION = ".o"; | 284 private static final String BINARY_EXTENSION = ".o"; |
285 | 285 |
286 private boolean findExcludedDisassemblerTestArgument(List<? extends Parameter> parameters, List<Argument> arguments) { | 286 private static boolean findExcludedDisassemblerTestArgument(List<? extends Parameter> parameters, List<Argument> arguments) { |
287 for (int i = 0; i < parameters.size(); i++) { | 287 for (int i = 0; i < parameters.size(); i++) { |
288 if (parameters.get(i).excludedDisassemblerTestArguments().contains(arguments.get(i))) { | 288 if (parameters.get(i).excludedDisassemblerTestArguments().contains(arguments.get(i))) { |
289 return true; | 289 return true; |
290 } | 290 } |
291 } | 291 } |
292 return false; | 292 return false; |
293 } | 293 } |
294 | 294 |
295 private boolean findExcludedExternalTestArgument(List<? extends Parameter> parameters, List<Argument> arguments) { | 295 private static boolean findExcludedExternalTestArgument(List<? extends Parameter> parameters, List<Argument> arguments) { |
296 for (int i = 0; i < parameters.size(); i++) { | 296 for (int i = 0; i < parameters.size(); i++) { |
297 final Parameter parameter = parameters.get(i); | 297 final Parameter parameter = parameters.get(i); |
298 if (parameter.excludedExternalTestArguments().contains(arguments.get(i))) { | 298 if (parameter.excludedExternalTestArguments().contains(arguments.get(i))) { |
299 return true; | 299 return true; |
300 } | 300 } |
401 * Executes a command in a subprocess redirecting the standard streams of the | 401 * Executes a command in a subprocess redirecting the standard streams of the |
402 * subprocess to/from the standard streams of the current process. | 402 * subprocess to/from the standard streams of the current process. |
403 * | 403 * |
404 * @param command the command line to execute | 404 * @param command the command line to execute |
405 */ | 405 */ |
406 private void exec(String command) throws IOException, InterruptedException { | 406 private static void exec(String command) throws IOException, InterruptedException { |
407 exec(command, System.out, System.err, System.in); | 407 exec(command, System.out, System.err, System.in); |
408 } | 408 } |
409 | 409 |
410 /** | 410 /** |
411 * Executes a command in a subprocess redirecting the standard streams of the | 411 * Executes a command in a subprocess redirecting the standard streams of the |
414 * @param command the command line to execute | 414 * @param command the command line to execute |
415 * @param out the stream to which standard output will be directed | 415 * @param out the stream to which standard output will be directed |
416 * @param err the stream to which standard error output will be directed | 416 * @param err the stream to which standard error output will be directed |
417 * @param in the stream from which standard input will be read | 417 * @param in the stream from which standard input will be read |
418 */ | 418 */ |
419 private void exec(String command, OutputStream out, OutputStream err, InputStream in) throws IOException, InterruptedException { | 419 private static void exec(String command, OutputStream out, OutputStream err, InputStream in) throws IOException, InterruptedException { |
420 final Process process = Runtime.getRuntime().exec(command); | 420 final Process process = Runtime.getRuntime().exec(command); |
421 try { | 421 try { |
422 final Redirector stderr = Streams.redirect(process, process.getErrorStream(), err, command + " [stderr]", 50); | 422 final Redirector stderr = Streams.redirect(process, process.getErrorStream(), err, command + " [stderr]", 50); |
423 final Redirector stdout = Streams.redirect(process, process.getInputStream(), out, command + " [stdout]"); | 423 final Redirector stdout = Streams.redirect(process, process.getInputStream(), out, command + " [stdout]"); |
424 final Redirector stdin = Streams.redirect(process, in, process.getOutputStream(), command + " [stdin]"); | 424 final Redirector stdin = Streams.redirect(process, in, process.getOutputStream(), command + " [stdin]"); |
497 * because some arguments with different identity may have equal values, | 497 * because some arguments with different identity may have equal values, |
498 * e.g. 'FPStackRegister.ST.value() == FPStackRegister.ST_0.value()'. | 498 * e.g. 'FPStackRegister.ST.value() == FPStackRegister.ST_0.value()'. |
499 * It would have been much more clean to override 'equals()' of those argument classes, | 499 * It would have been much more clean to override 'equals()' of those argument classes, |
500 * but they are enums and Java predeclares methods inherited via Enum final :-( | 500 * but they are enums and Java predeclares methods inherited via Enum final :-( |
501 */ | 501 */ |
502 private boolean equals(List<Argument> arguments1, List<Argument> arguments2) { | 502 private static boolean equals(List<Argument> arguments1, List<Argument> arguments2) { |
503 if (arguments1.size() != arguments2.size()) { | 503 if (arguments1.size() != arguments2.size()) { |
504 return false; | 504 return false; |
505 } | 505 } |
506 for (int i = 0; i < arguments1.size(); i++) { | 506 for (int i = 0; i < arguments1.size(); i++) { |
507 final Argument argument1 = arguments1.get(i); | 507 final Argument argument1 = arguments1.get(i); |
578 throw ProgramError.unexpected("mismatch between internal assembler and disassembler"); | 578 throw ProgramError.unexpected("mismatch between internal assembler and disassembler"); |
579 } | 579 } |
580 disassemblyStream.close(); | 580 disassemblyStream.close(); |
581 } | 581 } |
582 | 582 |
583 private void testTemplate(final Template_Type template, List<File> temporaryFiles) throws IOException, InterruptedException, AssemblyException { | 583 private void testTemplate(final Template_Type template, List<File> temporaryFiles) throws IOException, AssemblyException { |
584 final boolean testingExternally = components.contains(AssemblyTestComponent.EXTERNAL_ASSEMBLER) && template.isExternallyTestable(); | 584 final boolean testingExternally = components.contains(AssemblyTestComponent.EXTERNAL_ASSEMBLER) && template.isExternallyTestable(); |
585 | 585 |
586 // Process legal test cases | 586 // Process legal test cases |
587 final ArgumentListIterator argumentLists = new ArgumentListIterator(template, TestCaseLegality.LEGAL); | 587 final ArgumentListIterator argumentLists = new ArgumentListIterator(template, TestCaseLegality.LEGAL); |
588 ProgramError.check(argumentLists.hasNext(), "no test cases were generated for template: " + template); | 588 ProgramError.check(argumentLists.hasNext(), "no test cases were generated for template: " + template); |
608 final List<Argument> argumentList = iterator.next(); | 608 final List<Argument> argumentList = iterator.next(); |
609 final Assembler assembler = createTestAssembler(); | 609 final Assembler assembler = createTestAssembler(); |
610 assembly().assemble(assembler, template, argumentList); | 610 assembly().assemble(assembler, template, argumentList); |
611 final byte[] internalResult = assembler.toByteArray(); | 611 final byte[] internalResult = assembler.toByteArray(); |
612 if (Trace.hasLevel(3)) { | 612 if (Trace.hasLevel(3)) { |
613 Trace.line(3, "assembleInternally[" + testCaseNumber + "]: " + assembly().createMethodCallString(template, argumentList) + " = " + DisassembledInstruction.toHexString(internalResult)); | 613 Trace.line(3, "assembleInternally[" + testCaseNumber + "]: " + Assembly.createMethodCallString(template, argumentList) + " = " + DisassembledInstruction.toHexString(internalResult)); |
614 } | 614 } |
615 if (components.contains(AssemblyTestComponent.DISASSEMBLER) && template.isDisassemblable() && | 615 if (components.contains(AssemblyTestComponent.DISASSEMBLER) && template.isDisassemblable() && |
616 !findExcludedDisassemblerTestArgument(template.parameters(), argumentList)) { | 616 !findExcludedDisassemblerTestArgument(template.parameters(), argumentList)) { |
617 try { | 617 try { |
618 testDisassembler(template, argumentList, internalResult); | 618 testDisassembler(template, argumentList, internalResult); |
638 ++testCaseNumber; | 638 ++testCaseNumber; |
639 } | 639 } |
640 | 640 |
641 // Process illegal test cases | 641 // Process illegal test cases |
642 int illegalTestCaseNumber = 0; | 642 int illegalTestCaseNumber = 0; |
643 final Set<String> uniqueExceptionMessages = new HashSet<String>(); | 643 final Set<String> uniqueExceptionMessages = new HashSet<>(); |
644 for (TestCaseLegality testCaseLegality : new TestCaseLegality[]{TestCaseLegality.ILLEGAL_BY_CONSTRAINT, TestCaseLegality.ILLEGAL_BY_ARGUMENT}) { | 644 for (TestCaseLegality testCaseLegality : new TestCaseLegality[]{TestCaseLegality.ILLEGAL_BY_CONSTRAINT, TestCaseLegality.ILLEGAL_BY_ARGUMENT}) { |
645 for (final ArgumentListIterator iterator = new ArgumentListIterator(template, testCaseLegality); iterator.hasNext();) { | 645 for (final ArgumentListIterator iterator = new ArgumentListIterator(template, testCaseLegality); iterator.hasNext();) { |
646 final List<Argument> argumentList = iterator.next(); | 646 final List<Argument> argumentList = iterator.next(); |
647 final Assembler assembler = createTestAssembler(); | 647 final Assembler assembler = createTestAssembler(); |
648 Trace.line(3, "assembleInternally-negative[" + illegalTestCaseNumber + "]: " + assembly().createMethodCallString(template, argumentList)); | 648 Trace.line(3, "assembleInternally-negative[" + illegalTestCaseNumber + "]: " + Assembly.createMethodCallString(template, argumentList)); |
649 try { | 649 try { |
650 assembly().assemble(assembler, template, argumentList); | 650 assembly().assemble(assembler, template, argumentList); |
651 } catch (IllegalArgumentException e) { | 651 } catch (IllegalArgumentException e) { |
652 final String exceptionMessage = e.getMessage(); | 652 final String exceptionMessage = e.getMessage(); |
653 uniqueExceptionMessages.add(exceptionMessage); | 653 uniqueExceptionMessages.add(exceptionMessage); |
714 } else { | 714 } else { |
715 numberOfWorkerThreads = Runtime.getRuntime().availableProcessors(); | 715 numberOfWorkerThreads = Runtime.getRuntime().availableProcessors(); |
716 } | 716 } |
717 final ThreadPoolExecutor compilerService = (ThreadPoolExecutor) Executors.newFixedThreadPool(numberOfWorkerThreads); | 717 final ThreadPoolExecutor compilerService = (ThreadPoolExecutor) Executors.newFixedThreadPool(numberOfWorkerThreads); |
718 | 718 |
719 final CompletionService<Template_Type> compilationCompletionService = new ExecutorCompletionService<Template_Type>(compilerService); | 719 final CompletionService<Template_Type> compilationCompletionService = new ExecutorCompletionService<>(compilerService); |
720 long submittedTests = 0; | 720 long submittedTests = 0; |
721 final List<Template_Type> errors = new LinkedList<Template_Type>(); | 721 final List<Template_Type> errors = new LinkedList<>(); |
722 for (final Template_Type template : assembly().templates()) { | 722 for (final Template_Type template : assembly().templates()) { |
723 if (template.serial() > endTemplateSerial) { | 723 if (template.serial() > endTemplateSerial) { |
724 break; | 724 break; |
725 } | 725 } |
726 Trace.on(2); | 726 Trace.on(2); |
727 if (!template.isRedundant() && template.serial() >= startTemplateSerial) { | 727 if (!template.isRedundant() && template.serial() >= startTemplateSerial) { |
728 if (templatePattern == null || template.internalName().contains(templatePattern)) { | 728 if (templatePattern == null || template.internalName().contains(templatePattern)) { |
729 ++submittedTests; | 729 ++submittedTests; |
730 compilationCompletionService.submit(new Callable<Template_Type>() { | 730 compilationCompletionService.submit(new Callable<Template_Type>() { |
731 public Template_Type call() { | 731 public Template_Type call() { |
732 final List<File> temporaryFiles = new ArrayList<File>(); | 732 final List<File> temporaryFiles = new ArrayList<>(); |
733 try { | 733 try { |
734 testTemplate(template, temporaryFiles); | 734 testTemplate(template, temporaryFiles); |
735 } catch (Throwable throwable) { | 735 } catch (Throwable throwable) { |
736 Trace.line(2, "template: " + template + " failed testing"); | 736 Trace.line(2, "template: " + template + " failed testing"); |
737 throwable.printStackTrace(); | 737 throwable.printStackTrace(); |
789 * last template of the {@linkplain #assembly() assembly}. | 789 * last template of the {@linkplain #assembly() assembly}. |
790 * @param stream | 790 * @param stream |
791 * where to print the generate source. The caller takes responsibility for closing the stream. | 791 * where to print the generate source. The caller takes responsibility for closing the stream. |
792 */ | 792 */ |
793 public void createExternalSource(int startTemplateSerial, int endTemplateSerial, IndentWriter stream) { | 793 public void createExternalSource(int startTemplateSerial, int endTemplateSerial, IndentWriter stream) { |
794 final List<Template_Type> errors = new LinkedList<Template_Type>(); | 794 final List<Template_Type> errors = new LinkedList<>(); |
795 | 795 |
796 for (Template_Type template : assembly().templates()) { | 796 for (Template_Type template : assembly().templates()) { |
797 if (template.serial() > endTemplateSerial) { | 797 if (template.serial() > endTemplateSerial) { |
798 break; | 798 break; |
799 } | 799 } |