annotate graal/com.oracle.jvmci.options/src/com/oracle/jvmci/options/StableOptionValue.java @ 21705:729e6acde6c0

added JVMCI_UTIL distribution
author Doug Simon <doug.simon@oracle.com>
date Wed, 03 Jun 2015 16:23:33 +0200
parents 47bebae7454f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9914
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@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: 9919
diff changeset
23 package com.oracle.jvmci.options;
9914
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
25 /**
9919
af909f4b80a9 options are grouped per top level class/interface when accessed via the service mechanism
Doug Simon <doug.simon@oracle.com>
parents: 9914
diff changeset
26 * An option that always returns the same {@linkplain #getValue() value}.
9914
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
27 */
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28 public class StableOptionValue<T> extends OptionValue<T> {
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30 /**
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31 * Creates a stable option value.
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
32 */
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 public StableOptionValue(T value) {
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 super(value);
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 }
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37 /**
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
38 * Used to assert the invariant for stability. Without using locks, this check is not safe
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
39 * against races and so it's only an assertion.
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40 */
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
41 private boolean getValueCalled;
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
43 /**
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44 * Creates an uninitialized stable option value for a subclass that initializes itself
21519
cecb4e39521c Use files in lib/graal/options to define Graal options (-G:...) instead of generating code for them
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 9919
diff changeset
45 * {@link #defaultValue() lazily}.
9914
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
46 */
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
47 public StableOptionValue() {
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
48 }
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
49
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
50 /**
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
51 * Gets the value of this option.
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
52 */
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
53 @Override
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
54 public final T getValue() {
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
55 T result = super.getValue();
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
56 assert initGetValueCalled();
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
57 return result;
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
58 }
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
59
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
60 private boolean initGetValueCalled() {
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
61 getValueCalled = true;
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
62 return true;
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
63 }
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
64
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
65 /**
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
66 * {@inheritDoc}
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
67 * <p>
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
68 * This must only be called if {@link #getValue()} has never been called.
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
69 */
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
70 @Override
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
71 public final void setValue(Object v) {
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72 assert !getValueCalled;
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
73 super.setValue(v);
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
74 }
84890660eefb cleaner implementation of stable options
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
75 }