# HG changeset patch # User Roland Schatz # Date 1393323857 -3600 # Node ID ac599fff18dc2c8fa7b0f7906dab94276e952d10 # Parent 4347ad3df3d71e09cbe193861c604947b6863c1f Substitution methods for injecting fake profiling data into unit tests. diff -r 4347ad3df3d7 -r ac599fff18dc 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 Mon Feb 24 17:31:15 2014 -0800 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Tue Feb 25 11:24:17 2014 +0100 @@ -83,10 +83,20 @@ private final Backend backend; private final Suites suites; + private static boolean substitutionsInstalled; + + private void installSubstitutions() { + if (!substitutionsInstalled) { + this.providers.getReplacements().registerSubstitutions(InjectProfileDataSubstitutions.class); + substitutionsInstalled = true; + } + } + public GraalCompilerTest() { this.backend = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend(); this.providers = getBackend().getProviders(); this.suites = backend.getSuites().createSuites(); + installSubstitutions(); } /** @@ -106,6 +116,7 @@ } this.providers = backend.getProviders(); this.suites = backend.getSuites().createSuites(); + installSubstitutions(); } @BeforeClass @@ -643,4 +654,27 @@ protected Replacements getReplacements() { return getProviders().getReplacements(); } + + /** + * Inject a probability for a branch condition into the profiling information of this test case. + * + * @param p the probability that cond is true + * @param cond the condition of the branch + * @return cond + */ + protected static boolean branchProbability(double p, boolean cond) { + return cond; + } + + /** + * Inject an iteration count for a loop condition into the profiling information of this test + * case. + * + * @param i the iteration count of the loop + * @param cond the condition of the loop + * @return cond + */ + protected static boolean iterationCount(double i, boolean cond) { + return cond; + } } diff -r 4347ad3df3d7 -r ac599fff18dc graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InjectProfileDataSubstitutions.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InjectProfileDataSubstitutions.java Tue Feb 25 11:24:17 2014 +0100 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.compiler.test; + +import com.oracle.graal.api.replacements.*; +import com.oracle.graal.nodes.extended.*; + +@ClassSubstitution(GraalCompilerTest.class) +class InjectProfileDataSubstitutions { + + @MethodSubstitution + public static boolean branchProbability(double p, boolean cond) { + return BranchProbabilityNode.probability(p, cond); + } + + @MethodSubstitution + public static boolean iterationCount(double i, boolean cond) { + return BranchProbabilityNode.probability(1. - 1. / i, cond); + } +}