annotate graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/DerivedOptionValue.java @ 21554:b1530a6cce8c

renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Tue, 26 May 2015 23:21:15 +0200
parents graal/com.oracle.graal.options/src/com/oracle/graal/options/DerivedOptionValue.java@75cf0899be47
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16871
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
1 /*
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
4 *
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
8 *
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
14 *
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
18 *
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
21 * questions.
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
22 */
21554
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 19196
diff changeset
23 package com.oracle.jvmci.options;
16871
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
24
19196
75cf0899be47 Use serializable interface in DerivedOptionValue.
Roland Schatz <roland.schatz@oracle.com>
parents: 18935
diff changeset
25 import java.io.*;
16871
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
26 import java.util.function.*;
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
27
21554
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 19196
diff changeset
28 import com.oracle.jvmci.options.OptionValue.OverrideScope;
16871
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
29
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
30 /**
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
31 * A cached value that needs to be recomputed when an option changes.
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
32 */
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
33 public class DerivedOptionValue<T> {
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
34
19196
75cf0899be47 Use serializable interface in DerivedOptionValue.
Roland Schatz <roland.schatz@oracle.com>
parents: 18935
diff changeset
35 public interface OptionSupplier<T> extends Supplier<T>, Serializable {
75cf0899be47 Use serializable interface in DerivedOptionValue.
Roland Schatz <roland.schatz@oracle.com>
parents: 18935
diff changeset
36 }
75cf0899be47 Use serializable interface in DerivedOptionValue.
Roland Schatz <roland.schatz@oracle.com>
parents: 18935
diff changeset
37
16871
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
38 private final T initialValue;
19196
75cf0899be47 Use serializable interface in DerivedOptionValue.
Roland Schatz <roland.schatz@oracle.com>
parents: 18935
diff changeset
39 private final OptionSupplier<T> supplier;
16871
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
40
19196
75cf0899be47 Use serializable interface in DerivedOptionValue.
Roland Schatz <roland.schatz@oracle.com>
parents: 18935
diff changeset
41 public DerivedOptionValue(OptionSupplier<T> supplier) {
16871
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
42 this.supplier = supplier;
18935
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 16871
diff changeset
43 assert OptionValue.getOverrideScope() == null : "derived option value should be initialized outside any override scope";
16871
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
44 this.initialValue = createValue();
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
45 }
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
46
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
47 public T getValue() {
18935
07f2a49f0bfb Various adjustments to simplify future merges
Paul Woegerer <paul.woegerer@oracle.com>
parents: 16871
diff changeset
48 OverrideScope overrideScope = OptionValue.getOverrideScope();
16871
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
49 if (overrideScope != null) {
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
50 return overrideScope.getDerived(this);
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
51 } else {
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
52 return initialValue;
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
53 }
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
54 }
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
55
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
56 T createValue() {
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
57 return supplier.get();
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
58 }
e728b9d4905c Recompute phase suites when options are changed.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
59 }