Mercurial > hg > truffle
comparison graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java @ 18378:c57c3777fa72
when testing replay compilation, only compare result of capturing compilation against replay compilation and ignore result of original compilation altogether
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 14 Nov 2014 16:26:38 +0100 |
parents | cb3c93857cbb |
children | df47f69cda83 |
comparison
equal
deleted
inserted
replaced
18376:e11768d6136e | 18378:c57c3777fa72 |
---|---|
700 throw new GraalInternalError("Could not create test output directory: %s", OUTPUT_DIR.getAbsolutePath()); | 700 throw new GraalInternalError("Could not create test output directory: %s", OUTPUT_DIR.getAbsolutePath()); |
701 } | 701 } |
702 return OUTPUT_DIR; | 702 return OUTPUT_DIR; |
703 } | 703 } |
704 | 704 |
705 protected String dissasembleToFile(CompilationResult original, ResolvedJavaMethod installedCodeOwner, String fileSuffix) { | 705 protected String dissasembleToFile(CompilationResult result, ResolvedJavaMethod installedCodeOwner, String fileSuffix) { |
706 String dis = getCodeCache().disassemble(original, null); | 706 String dis = getCodeCache().disassemble(result, null); |
707 File disFile = new File(getOutputDir(), installedCodeOwner.format("%H.%n_%p").replace(", ", "__") + "." + fileSuffix); | 707 File disFile = new File(getOutputDir(), installedCodeOwner.format("%H.%n_%p").replace(", ", "__") + "." + fileSuffix); |
708 try (PrintStream ps = new PrintStream(new FileOutputStream(disFile))) { | 708 try (PrintStream ps = new PrintStream(new FileOutputStream(disFile))) { |
709 ps.println(dis); | 709 ps.println(dis); |
710 return disFile.getAbsolutePath(); | 710 return disFile.getAbsolutePath(); |
711 } catch (IOException e) { | 711 } catch (IOException e) { |
712 return null; | 712 return null; |
713 } | 713 } |
714 } | 714 } |
715 | 715 |
716 protected void checkCompilationResultsEqual(Context c, String prefix, CompilationResult original, CompilationResult derived, ResolvedJavaMethod installedCodeOwner) { | 716 protected void checkCompilationResultsEqual(Context c, String prefix, CompilationResult expected, CompilationResult actual, ResolvedJavaMethod installedCodeOwner) { |
717 if (!derived.equals(original)) { | 717 if (!actual.equals(expected)) { |
718 Mode mode = c.getMode(); | 718 Mode mode = c.getMode(); |
719 // Temporarily force capturing mode as dumping/printing/disassembling | 719 // Temporarily force capturing mode as dumping/printing/disassembling |
720 // may need to execute proxy methods that have not yet been executed | 720 // may need to execute proxy methods that have not yet been executed |
721 c.setMode(Mode.Capturing); | 721 c.setMode(Mode.Capturing); |
722 try { | 722 try { |
723 String originalDisFile = dissasembleToFile(original, installedCodeOwner, "original"); | 723 String expectedDisFile = dissasembleToFile(expected, installedCodeOwner, "expected"); |
724 String derivedDisFile = dissasembleToFile(derived, installedCodeOwner, "derived"); | 724 String actualDisFile = dissasembleToFile(actual, installedCodeOwner, "actual"); |
725 String message = String.format("%s compilation result differs from original compilation result", prefix); | 725 String message = String.format("%s compilation result differs from expected compilation result", prefix); |
726 if (originalDisFile != null && derivedDisFile != null) { | 726 if (expectedDisFile != null && actualDisFile != null) { |
727 message += String.format(" [diff %s %s]", originalDisFile, derivedDisFile); | 727 message += String.format(" [diff %s %s]", expectedDisFile, actualDisFile); |
728 } | 728 } |
729 if (TEST_REPLAY_MISMATCH_IS_FAILURE) { | 729 if (TEST_REPLAY_MISMATCH_IS_FAILURE) { |
730 Assert.fail(message); | 730 Assert.fail(message); |
731 } else { | 731 } else { |
732 System.out.println(message); | 732 System.out.println(message); |
735 c.setMode(mode); | 735 c.setMode(mode); |
736 } | 736 } |
737 } | 737 } |
738 } | 738 } |
739 | 739 |
740 protected void testRecompile(Context c, Mode mode, CompilationResult originalResultInContext, ResolvedJavaMethod installedCodeOwner) { | 740 protected CompilationResult testRecompile(Context c, Mode mode, CompilationResult expectedResult, ResolvedJavaMethod installedCodeOwner) { |
741 try (Debug.Scope s = Debug.scope(mode.name(), new DebugDumpScope(mode.name(), true))) { | 741 try (Debug.Scope s = Debug.scope(mode.name(), new DebugDumpScope(mode.name(), true))) { |
742 | 742 |
743 StructuredGraph graphToCompile = parseForCompile(installedCodeOwner); | 743 StructuredGraph graphToCompile = parseForCompile(installedCodeOwner); |
744 | |
744 lastCompiledGraph = graphToCompile; | 745 lastCompiledGraph = graphToCompile; |
745 | 746 |
746 CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graphToCompile.method(), false); | 747 CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graphToCompile.method(), false); |
747 Request<CompilationResult> request = c.get(new GraalCompiler.Request<>(graphToCompile, null, cc, installedCodeOwner, getProviders(), getBackend(), getCodeCache().getTarget(), null, | 748 Request<CompilationResult> request = c.get(new GraalCompiler.Request<>(graphToCompile, null, cc, installedCodeOwner, getProviders(), getBackend(), getCodeCache().getTarget(), null, |
748 getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, getProfilingInfo(graphToCompile), getSpeculationLog(), getSuites(), new CompilationResult(), | 749 getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, getProfilingInfo(graphToCompile), getSpeculationLog(), getSuites(), new CompilationResult(), |
749 CompilationResultBuilderFactory.Default)); | 750 CompilationResultBuilderFactory.Default)); |
750 checkCompilationResultsEqual(c, mode.name(), originalResultInContext, GraalCompiler.compile(request), installedCodeOwner); | 751 CompilationResult result = GraalCompiler.compile(request); |
752 if (expectedResult != null) { | |
753 checkCompilationResultsEqual(c, mode.name(), expectedResult, result, installedCodeOwner); | |
754 } | |
755 return result; | |
751 } catch (Throwable e) { | 756 } catch (Throwable e) { |
752 throw Debug.handle(e); | 757 throw Debug.handle(e); |
753 } | 758 } |
754 } | 759 } |
755 | 760 |
756 protected void testReplayCompile(ResolvedJavaMethod installedCodeOwner) { | 761 protected void testReplayCompile(ResolvedJavaMethod installedCodeOwner) { |
757 CompilationResult originalResult; | |
758 | |
759 // Repeat the compilation without a context to account for any side-effects the | |
760 // initial compilation may have had. For example, if dumping was enabled then | |
761 // the dumping code may have changed profiles in methods that are inlined | |
762 // by the test method being compiled. | |
763 try (Debug.Scope s = Debug.scope("Repeating", new DebugDumpScope("Repeating", true))) { | |
764 StructuredGraph graphToCompile = parseForCompile(installedCodeOwner); | |
765 lastCompiledGraph = graphToCompile; | |
766 CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graphToCompile.method(), false); | |
767 originalResult = GraalCompiler.compileGraph(graphToCompile, null, cc, installedCodeOwner, getProviders(), getBackend(), getCodeCache().getTarget(), null, getDefaultGraphBuilderSuite(), | |
768 OptimisticOptimizations.ALL, getProfilingInfo(graphToCompile), getSpeculationLog(), getSuites(), new CompilationResult(), CompilationResultBuilderFactory.Default); | |
769 } catch (Throwable e) { | |
770 throw Debug.handle(e); | |
771 } | |
772 | |
773 try (Context c = new Context()) { | 762 try (Context c = new Context()) { |
774 // Need to use an 'in context' copy of the original result when comparing for | |
775 // equality against other 'in context' results so that proxies are compared | |
776 // against proxies | |
777 CompilationResult originalResultInContext = c.get(originalResult); | |
778 | 763 |
779 // Capturing compilation | 764 // Capturing compilation |
780 testRecompile(c, Mode.Capturing, originalResultInContext, installedCodeOwner); | 765 CompilationResult expected = testRecompile(c, Mode.Capturing, null, installedCodeOwner); |
781 | 766 |
782 // Replay compilation | 767 // Replay compilation |
783 testRecompile(c, Mode.Replaying, originalResultInContext, installedCodeOwner); | 768 testRecompile(c, Mode.Replaying, expected, installedCodeOwner); |
784 } | 769 } |
785 } | 770 } |
786 | 771 |
787 /** | 772 /** |
788 * Compiles a given method. | 773 * Compiles a given method. |