# HG changeset patch # User Roland Schatz # Date 1408545785 -7200 # Node ID e728b9d4905c799eb2da4d0405af0701b54db904 # Parent 11b22ccafccd7b8fb20e5455d4bd2cecb65b734c Recompute phase suites when options are changed. diff -r 11b22ccafccd -r e728b9d4905c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSuitesProvider.java --- 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 defaultSuites; protected final PhaseSuite 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 getDefaultGraphBuilderSuite() { diff -r 11b22ccafccd -r e728b9d4905c graal/com.oracle.graal.java/src/com/oracle/graal/java/DefaultSuitesProvider.java --- 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 defaultSuites; private final PhaseSuite 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() { diff -r 11b22ccafccd -r e728b9d4905c graal/com.oracle.graal.options/src/com/oracle/graal/options/DerivedOptionValue.java --- /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 { + + private final T initialValue; + private final Supplier supplier; + + public DerivedOptionValue(Supplier 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(); + } +} diff -r 11b22ccafccd -r e728b9d4905c graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java --- 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 overrideScopes = new ThreadLocal<>(); + static final ThreadLocal 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, Object> derivedCache = null; + + public T getDerived(DerivedOptionValue 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, Object> inherited); abstract T getOverride(OptionValue option); diff -r 11b22ccafccd -r e728b9d4905c graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/Suites.java --- 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) {