Mercurial > hg > truffle
changeset 16871:e728b9d4905c
Recompute phase suites when options are changed.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Wed, 20 Aug 2014 16:43:05 +0200 |
parents | 11b22ccafccd |
children | ce8ac92efb14 |
files | graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSuitesProvider.java graal/com.oracle.graal.java/src/com/oracle/graal/java/DefaultSuitesProvider.java graal/com.oracle.graal.options/src/com/oracle/graal/options/DerivedOptionValue.java graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/Suites.java |
diffstat | 5 files changed, 97 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSuitesProvider.java Wed Aug 20 15:35:27 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSuitesProvider.java Wed Aug 20 16:43:05 2014 +0200 @@ -27,6 +27,7 @@ import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.phases.*; import com.oracle.graal.java.*; +import com.oracle.graal.options.*; import com.oracle.graal.phases.*; import com.oracle.graal.phases.tiers.*; @@ -35,18 +36,18 @@ */ public class HotSpotSuitesProvider implements SuitesProvider { - protected final Suites defaultSuites; + protected final DerivedOptionValue<Suites> defaultSuites; protected final PhaseSuite<HighTierContext> defaultGraphBuilderSuite; protected final HotSpotGraalRuntime runtime; public HotSpotSuitesProvider(HotSpotGraalRuntime runtime) { this.runtime = runtime; this.defaultGraphBuilderSuite = createGraphBuilderSuite(); - defaultSuites = createSuites(); + this.defaultSuites = new DerivedOptionValue<>(this::createSuites); } public Suites getDefaultSuites() { - return defaultSuites; + return defaultSuites.getValue(); } public PhaseSuite<HighTierContext> getDefaultGraphBuilderSuite() {
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/DefaultSuitesProvider.java Wed Aug 20 15:35:27 2014 +0200 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/DefaultSuitesProvider.java Wed Aug 20 16:43:05 2014 +0200 @@ -22,21 +22,22 @@ */ package com.oracle.graal.java; +import com.oracle.graal.options.*; import com.oracle.graal.phases.*; import com.oracle.graal.phases.tiers.*; public class DefaultSuitesProvider implements SuitesProvider { - private final Suites defaultSuites; + private final DerivedOptionValue<Suites> defaultSuites; private final PhaseSuite<HighTierContext> defaultGraphBuilderSuite; public DefaultSuitesProvider() { this.defaultGraphBuilderSuite = createGraphBuilderSuite(); - this.defaultSuites = createSuites(); + this.defaultSuites = new DerivedOptionValue<>(this::createSuites); } public Suites getDefaultSuites() { - return defaultSuites; + return defaultSuites.getValue(); } public Suites createSuites() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.options/src/com/oracle/graal/options/DerivedOptionValue.java Wed Aug 20 16:43:05 2014 +0200 @@ -0,0 +1,55 @@ +/* + * 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.options; + +import java.util.function.*; + +import com.oracle.graal.options.OptionValue.OverrideScope; + +/** + * A cached value that needs to be recomputed when an option changes. + */ +public class DerivedOptionValue<T> { + + private final T initialValue; + private final Supplier<T> supplier; + + public DerivedOptionValue(Supplier<T> supplier) { + this.supplier = supplier; + assert OptionValue.overrideScopes.get() == null : "derived option value should be initialized outside any override scope"; + this.initialValue = createValue(); + } + + public T getValue() { + OverrideScope overrideScope = OptionValue.overrideScopes.get(); + if (overrideScope != null) { + return overrideScope.getDerived(this); + } else { + return initialValue; + } + } + + T createValue() { + return supplier.get(); + } +}
--- a/graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java Wed Aug 20 15:35:27 2014 +0200 +++ b/graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java Wed Aug 20 16:43:05 2014 +0200 @@ -128,7 +128,7 @@ return new MultipleOverridesScope(current, map); } - private static final ThreadLocal<OverrideScope> overrideScopes = new ThreadLocal<>(); + static final ThreadLocal<OverrideScope> overrideScopes = new ThreadLocal<>(); /** * The raw option value. @@ -252,6 +252,22 @@ * {@link OptionValue#override(OptionValue, Object)} or {@link OptionValue#override(Map)}. */ public abstract static class OverrideScope implements AutoCloseable { + + private Map<DerivedOptionValue<?>, Object> derivedCache = null; + + public <T> T getDerived(DerivedOptionValue<T> key) { + if (derivedCache == null) { + derivedCache = new HashMap<>(); + } + @SuppressWarnings("unchecked") + T ret = (T) derivedCache.get(key); + if (ret == null) { + ret = key.createValue(); + derivedCache.put(key, ret); + } + return ret; + } + abstract void addToInherited(Map<OptionValue<?>, Object> inherited); abstract <T> T getOverride(OptionValue<T> option);
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/Suites.java Wed Aug 20 15:35:27 2014 +0200 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/Suites.java Wed Aug 20 16:43:05 2014 +0200 @@ -83,26 +83,19 @@ } } - if (CompilerConfiguration.getValue().equals("")) { - if (nonBasicCount == 1) { - /* - * There is exactly one non-basic configuration. We use this one as default. - */ - defaultConfiguration = nonBasic; - } else { - /* - * There is either no extended configuration available, or more than one. In that - * case, default to "basic". - */ - defaultConfiguration = basic; - if (defaultConfiguration == null) { - throw new GraalInternalError("unable to find basic compiler configuration"); - } - } + if (nonBasicCount == 1) { + /* + * There is exactly one non-basic configuration. We use this one as default. + */ + defaultConfiguration = nonBasic; } else { - defaultConfiguration = configurations.get(CompilerConfiguration.getValue()); + /* + * There is either no extended configuration available, or more than one. In that case, + * default to "basic". + */ + defaultConfiguration = basic; if (defaultConfiguration == null) { - throw new GraalInternalError("unknown compiler configuration: " + CompilerConfiguration.getValue()); + throw new GraalInternalError("unable to find basic compiler configuration"); } } } @@ -120,7 +113,12 @@ } public static Suites createDefaultSuites() { - return new Suites(defaultConfiguration); + String selected = CompilerConfiguration.getValue(); + if (selected.equals("")) { + return new Suites(defaultConfiguration); + } else { + return createSuites(selected); + } } public static Suites createSuites(String name) {