Mercurial > hg > truffle
changeset 15115:de406a971984
enhanced API for scoped overriding of the current DebugConfig
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 15 Apr 2014 15:37:35 +0200 |
parents | 6876a4599b7e |
children | 0d296283e87d |
files | graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BasicHSAILTest.java graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticMethod16InArraysTest.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DelegatingDebugConfig.java |
diffstat | 5 files changed, 112 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BasicHSAILTest.java Tue Apr 15 13:34:29 2014 +0200 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BasicHSAILTest.java Tue Apr 15 15:37:35 2014 +0200 @@ -22,6 +22,8 @@ */ package com.oracle.graal.compiler.hsail.test; +import static com.oracle.graal.debug.DelegatingDebugConfig.Feature.*; + import java.lang.reflect.*; import org.junit.*; @@ -30,7 +32,6 @@ import com.oracle.graal.compiler.test.*; import com.oracle.graal.debug.*; import com.oracle.graal.debug.Debug.Scope; -import com.oracle.graal.debug.internal.*; import com.oracle.graal.gpu.*; import com.oracle.graal.hotspot.hsail.*; import com.oracle.graal.hsail.*; @@ -344,15 +345,7 @@ } private void test(final String snippet) { - DebugConfig debugConfig = DebugScope.getConfig(); - DebugConfig noInterceptConfig = new DelegatingDebugConfig(debugConfig) { - @Override - public RuntimeException interceptException(Throwable e) { - return null; - } - }; - - try (DebugConfigScope dcs = Debug.setConfig(noInterceptConfig)) { + try (DebugConfigScope dcs = Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT))) { try (Scope s = Debug.scope("HSAILCodeGen")) { Method method = getMethod(snippet); ExternalCompilationResult hsailCode = getBackend().compileKernel(getMetaAccess().lookupJavaMethod(method), false);
--- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticMethod16InArraysTest.java Tue Apr 15 13:34:29 2014 +0200 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticMethod16InArraysTest.java Tue Apr 15 15:37:35 2014 +0200 @@ -23,10 +23,11 @@ package com.oracle.graal.compiler.hsail.test; +import static com.oracle.graal.debug.DelegatingDebugConfig.Feature.*; + import org.junit.*; import com.oracle.graal.debug.*; -import com.oracle.graal.debug.internal.*; /** * Tests the addition of elements from sixteen input arrays. @@ -64,15 +65,7 @@ @Test(expected = java.lang.ClassCastException.class) @Ignore("until GPU backends can co-exist") public void test() { - DebugConfig debugConfig = DebugScope.getConfig(); - DebugConfig noInterceptConfig = new DelegatingDebugConfig(debugConfig) { - @Override - public RuntimeException interceptException(Throwable e) { - return null; - } - }; - - try (DebugConfigScope s = Debug.setConfig(noInterceptConfig)) { + try (DebugConfigScope s = Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT))) { testGeneratedHsail(); } }
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java Tue Apr 15 13:34:29 2014 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java Tue Apr 15 15:37:35 2014 +0200 @@ -22,6 +22,8 @@ */ package com.oracle.graal.compiler.test; +import static com.oracle.graal.debug.DelegatingDebugConfig.Feature.*; + import java.io.*; import java.lang.reflect.*; import java.util.*; @@ -33,7 +35,6 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.api.runtime.*; import com.oracle.graal.debug.*; -import com.oracle.graal.debug.internal.*; import com.oracle.graal.java.*; import com.oracle.graal.nodes.*; import com.oracle.graal.phases.*; @@ -106,14 +107,7 @@ String methodName = className + "." + m.getName(); if (matches(filters, methodName)) { StructuredGraph graph = new StructuredGraph(metaAccess.lookupJavaMethod(m)); - DebugConfig debugConfig = DebugScope.getConfig(); - DebugConfig noInterceptConfig = new DelegatingDebugConfig(debugConfig) { - @Override - public RuntimeException interceptException(Throwable e) { - return null; - } - }; - try (DebugConfigScope s = Debug.setConfig(noInterceptConfig)) { + try (DebugConfigScope s = Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT))) { graphBuilderSuite.apply(graph, context); checkGraph(context, graph); } catch (VerificationError e) {
--- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java Tue Apr 15 13:34:29 2014 +0200 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java Tue Apr 15 15:37:35 2014 +0200 @@ -23,6 +23,7 @@ package com.oracle.graal.debug; import static com.oracle.graal.debug.Debug.Initialization.*; +import static com.oracle.graal.debug.DelegatingDebugConfig.Feature.*; import static java.util.FormattableFlags.*; import java.io.*; @@ -259,17 +260,7 @@ } public static Scope forceLog() { - return Debug.sandbox("forceLog", new DelegatingDebugConfig(DebugScope.getConfig()) { - @Override - public boolean isLogEnabled() { - return true; - } - - @Override - public boolean isLogEnabledForMethod() { - return true; - } - }); + return Debug.sandbox("forceLog", new DelegatingDebugConfig().enable(LOG).enable(LOG_METHOD)); } /**
--- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DelegatingDebugConfig.java Tue Apr 15 13:34:29 2014 +0200 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DelegatingDebugConfig.java Tue Apr 15 15:37:35 2014 +0200 @@ -25,45 +25,139 @@ import java.io.*; import java.util.*; +import com.oracle.graal.debug.internal.*; + public class DelegatingDebugConfig implements DebugConfig { protected final DebugConfig delegate; + /** + * The features of a {@link DelegatingDebugConfig} that can be force + * {@linkplain DelegatingDebugConfig#enable(Feature) enabled}/ + * {@linkplain DelegatingDebugConfig#disable(Feature) disabled} or + * {@linkplain DelegatingDebugConfig#delegate(Feature) delegated}. + */ + public enum Feature { + /** + * @see Debug#isLogEnabled() + */ + LOG, + /** + * @see Debug#isLogEnabledForMethod() + */ + LOG_METHOD, + /** + * @see Debug#isDumpEnabled() + */ + DUMP, + /** + * @see Debug#isDumpEnabledForMethod() + */ + DUMP_METHOD, + /** + * @see Debug#isMeterEnabled() + */ + METER, + /** + * @see Debug#isTimeEnabled() + */ + TIME, + /** + * @see DebugConfig#interceptException(Throwable) + */ + INTERCEPT + } + + private final Map<Feature, Boolean> featureState = new EnumMap<>(Feature.class); + + /** + * Creates a config that delegates to the {@link DebugScope#getConfig() current config}. + */ + public DelegatingDebugConfig() { + this(DebugScope.getConfig()); + } + + /** + * Creates a config that delegates to a given config. + */ public DelegatingDebugConfig(DebugConfig delegate) { this.delegate = delegate; } + public DelegatingDebugConfig enable(Feature feature) { + featureState.put(feature, Boolean.TRUE); + return this; + } + + public DelegatingDebugConfig disable(Feature feature) { + featureState.put(feature, Boolean.FALSE); + return this; + } + + public DelegatingDebugConfig delegate(Feature feature) { + featureState.put(feature, null); + return this; + } + @Override public boolean isLogEnabled() { - return delegate.isLogEnabled(); + Boolean fs = featureState.get(Feature.LOG); + if (fs == null) { + return delegate.isLogEnabled(); + } + return fs.booleanValue(); } public boolean isLogEnabledForMethod() { - return delegate.isLogEnabledForMethod(); + Boolean fs = featureState.get(Feature.LOG_METHOD); + if (fs == null) { + return delegate.isLogEnabledForMethod(); + } + return fs.booleanValue(); } @Override public boolean isMeterEnabled() { - return delegate.isMeterEnabled(); + Boolean fs = featureState.get(Feature.METER); + if (fs == null) { + return delegate.isMeterEnabled(); + } + return fs.booleanValue(); } @Override public boolean isDumpEnabled() { - return delegate.isDumpEnabled(); + Boolean fs = featureState.get(Feature.DUMP); + if (fs == null) { + return delegate.isDumpEnabled(); + } + return fs.booleanValue(); } public boolean isDumpEnabledForMethod() { - return delegate.isDumpEnabledForMethod(); + Boolean fs = featureState.get(Feature.DUMP_METHOD); + if (fs == null) { + return delegate.isDumpEnabledForMethod(); + } + return fs.booleanValue(); } @Override public boolean isTimeEnabled() { - return delegate.isTimeEnabled(); + Boolean fs = featureState.get(Feature.TIME); + if (fs == null) { + return delegate.isTimeEnabled(); + } + return fs.booleanValue(); } @Override public RuntimeException interceptException(Throwable e) { - return delegate.interceptException(e); + Boolean fs = featureState.get(Feature.INTERCEPT); + if (fs == null || fs) { + return delegate.interceptException(e); + } + return null; } @Override