# HG changeset patch # User Doug Simon # Date 1415894010 -3600 # Node ID 23526af9360df556487ed0037f56f957883f5688 # Parent c09fc28640976902633d0c0f03f4e277b3134dfb try harder to avoid side-effects that perturb replay compilation testing diff -r c09fc2864097 -r 23526af9360d graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Thu Nov 13 16:52:59 2014 +0100 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Thu Nov 13 16:53:30 2014 +0100 @@ -730,12 +730,39 @@ } } - protected void replayCompile(CompilationResult originalResult, ResolvedJavaMethod installedCodeOwner, StructuredGraph graph) { + protected void testRecompile(Context c, Mode mode, CompilationResult originalResultInContext, ResolvedJavaMethod installedCodeOwner) { + try (Debug.Scope s = Debug.scope(mode.name(), new DebugDumpScope(mode.name(), true))) { + + StructuredGraph graphToCompile = parseForCompile(installedCodeOwner); + lastCompiledGraph = graphToCompile; + + CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graphToCompile.method(), false); + Request request = c.get(new GraalCompiler.Request<>(graphToCompile, null, cc, installedCodeOwner, getProviders(), getBackend(), getCodeCache().getTarget(), null, + getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, getProfilingInfo(graphToCompile), getSpeculationLog(), getSuites(), new CompilationResult(), + CompilationResultBuilderFactory.Default)); + assertCompilationResultsEqual(c, mode.name(), originalResultInContext, GraalCompiler.compile(request), installedCodeOwner); + } catch (Throwable e) { + throw Debug.handle(e); + } + } - StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner) : graph; - lastCompiledGraph = graphToCompile; + protected void testReplayCompile(ResolvedJavaMethod installedCodeOwner) { + CompilationResult originalResult; - CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graphToCompile.method(), false); + // Repeat the compilation without a context to account for any side-effects the + // initial compilation may have had. For example, if dumping was enabled then + // the dumping code may have changed profiles in methods that are inlined + // by the test method being compiled. + try (Debug.Scope s = Debug.scope("Repeating", new DebugDumpScope("Repeating", true))) { + StructuredGraph graphToCompile = parseForCompile(installedCodeOwner); + lastCompiledGraph = graphToCompile; + CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graphToCompile.method(), false); + originalResult = GraalCompiler.compileGraph(graphToCompile, null, cc, installedCodeOwner, getProviders(), getBackend(), getCodeCache().getTarget(), null, getDefaultGraphBuilderSuite(), + OptimisticOptimizations.ALL, getProfilingInfo(graphToCompile), getSpeculationLog(), getSuites(), new CompilationResult(), CompilationResultBuilderFactory.Default); + } catch (Throwable e) { + throw Debug.handle(e); + } + try (Context c = new Context()) { // Need to use an 'in context' copy of the original result when comparing for // equality against other 'in context' results so that proxies are compared @@ -743,27 +770,10 @@ CompilationResult originalResultInContext = c.get(originalResult); // Capturing compilation - Request capturingRequest = null; - try (Debug.Scope s = Debug.scope("CapturingCompiling", new DebugDumpScope("CAPTURE", true))) { - capturingRequest = c.get(new GraalCompiler.Request<>(graphToCompile, null, cc, installedCodeOwner, getProviders(), getBackend(), getCodeCache().getTarget(), null, - getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, getProfilingInfo(graphToCompile), getSpeculationLog(), getSuites(), new CompilationResult(), - CompilationResultBuilderFactory.Default)); - assertCompilationResultsEqual(c, "Capturing", originalResultInContext, GraalCompiler.compile(capturingRequest), installedCodeOwner); - } catch (Throwable e) { - throw Debug.handle(e); - } + testRecompile(c, Mode.Capturing, originalResultInContext, installedCodeOwner); // Replay compilation - try (Debug.Scope s = Debug.scope("ReplayCompiling", new DebugDumpScope("REPLAY", true))) { - Request replyRequest = c.get(new GraalCompiler.Request<>(graphToCompile.copy(), null, cc, capturingRequest.installedCodeOwner, capturingRequest.providers, - capturingRequest.backend, capturingRequest.target, null, capturingRequest.graphBuilderSuite, capturingRequest.optimisticOpts, capturingRequest.profilingInfo, - capturingRequest.speculationLog, capturingRequest.suites, new CompilationResult(), capturingRequest.factory)); - c.setMode(Mode.Replaying); - - assertCompilationResultsEqual(c, "Replay", originalResultInContext, GraalCompiler.compile(replyRequest), installedCodeOwner); - } catch (Throwable e) { - throw Debug.handle(e); - } + testRecompile(c, Mode.Replaying, originalResultInContext, installedCodeOwner); } } @@ -783,7 +793,7 @@ OptimisticOptimizations.ALL, getProfilingInfo(graphToCompile), getSpeculationLog(), getSuites(), new CompilationResult(), CompilationResultBuilderFactory.Default); if (TEST_REPLAY && graph == null) { - replayCompile(res, installedCodeOwner, null); + testReplayCompile(installedCodeOwner); } return res; }