1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/rt/emul/compact/src/main/java/java/lang/BootstrapMethodError.java Sun Aug 10 05:55:55 2014 +0200
1.3 @@ -0,0 +1,80 @@
1.4 +/*
1.5 + * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.7 + *
1.8 + * This code is free software; you can redistribute it and/or modify it
1.9 + * under the terms of the GNU General Public License version 2 only, as
1.10 + * published by the Free Software Foundation. Oracle designates this
1.11 + * particular file as subject to the "Classpath" exception as provided
1.12 + * by Oracle in the LICENSE file that accompanied this code.
1.13 + *
1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.17 + * version 2 for more details (a copy is included in the LICENSE file that
1.18 + * accompanied this code).
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License version
1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.23 + *
1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1.25 + * or visit www.oracle.com if you need additional information or have any
1.26 + * questions.
1.27 + */
1.28 +
1.29 +package java.lang;
1.30 +
1.31 +/**
1.32 + * Thrown to indicate that an {@code invokedynamic} instruction has
1.33 + * failed to find its bootstrap method,
1.34 + * or the bootstrap method has failed to provide a
1.35 + * {@linkplain java.lang.invoke.CallSite call site} with a {@linkplain java.lang.invoke.CallSite#getTarget target}
1.36 + * of the correct {@linkplain java.lang.invoke.MethodHandle#type method type}.
1.37 + *
1.38 + * @author John Rose, JSR 292 EG
1.39 + * @since 1.7
1.40 + */
1.41 +public class BootstrapMethodError extends LinkageError {
1.42 + private static final long serialVersionUID = 292L;
1.43 +
1.44 + /**
1.45 + * Constructs a {@code BootstrapMethodError} with no detail message.
1.46 + */
1.47 + public BootstrapMethodError() {
1.48 + super();
1.49 + }
1.50 +
1.51 + /**
1.52 + * Constructs a {@code BootstrapMethodError} with the specified
1.53 + * detail message.
1.54 + *
1.55 + * @param s the detail message.
1.56 + */
1.57 + public BootstrapMethodError(String s) {
1.58 + super(s);
1.59 + }
1.60 +
1.61 + /**
1.62 + * Constructs a {@code BootstrapMethodError} with the specified
1.63 + * detail message and cause.
1.64 + *
1.65 + * @param s the detail message.
1.66 + * @param cause the cause, may be {@code null}.
1.67 + */
1.68 + public BootstrapMethodError(String s, Throwable cause) {
1.69 + super(s, cause);
1.70 + }
1.71 +
1.72 + /**
1.73 + * Constructs a {@code BootstrapMethodError} with the specified
1.74 + * cause.
1.75 + *
1.76 + * @param cause the cause, may be {@code null}.
1.77 + */
1.78 + public BootstrapMethodError(Throwable cause) {
1.79 + // cf. Throwable(Throwable cause) constructor.
1.80 + super(cause == null ? null : cause.toString());
1.81 + initCause(cause);
1.82 + }
1.83 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/rt/emul/compact/src/main/java/java/lang/ClassValue.java Sun Aug 10 05:55:55 2014 +0200
2.3 @@ -0,0 +1,760 @@
2.4 +/*
2.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2.7 + *
2.8 + * This code is free software; you can redistribute it and/or modify it
2.9 + * under the terms of the GNU General Public License version 2 only, as
2.10 + * published by the Free Software Foundation. Oracle designates this
2.11 + * particular file as subject to the "Classpath" exception as provided
2.12 + * by Oracle in the LICENSE file that accompanied this code.
2.13 + *
2.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
2.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2.17 + * version 2 for more details (a copy is included in the LICENSE file that
2.18 + * accompanied this code).
2.19 + *
2.20 + * You should have received a copy of the GNU General Public License version
2.21 + * 2 along with this work; if not, write to the Free Software Foundation,
2.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2.23 + *
2.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2.25 + * or visit www.oracle.com if you need additional information or have any
2.26 + * questions.
2.27 + */
2.28 +
2.29 +package java.lang;
2.30 +
2.31 +import java.lang.ClassValue.ClassValueMap;
2.32 +import java.util.WeakHashMap;
2.33 +import java.lang.ref.WeakReference;
2.34 +import java.util.concurrent.atomic.AtomicInteger;
2.35 +
2.36 +import static java.lang.ClassValue.ClassValueMap.probeHomeLocation;
2.37 +import static java.lang.ClassValue.ClassValueMap.probeBackupLocations;
2.38 +
2.39 +/**
2.40 + * Lazily associate a computed value with (potentially) every type.
2.41 + * For example, if a dynamic language needs to construct a message dispatch
2.42 + * table for each class encountered at a message send call site,
2.43 + * it can use a {@code ClassValue} to cache information needed to
2.44 + * perform the message send quickly, for each class encountered.
2.45 + * @author John Rose, JSR 292 EG
2.46 + * @since 1.7
2.47 + */
2.48 +public abstract class ClassValue<T> {
2.49 + /**
2.50 + * Sole constructor. (For invocation by subclass constructors, typically
2.51 + * implicit.)
2.52 + */
2.53 + protected ClassValue() {
2.54 + }
2.55 +
2.56 + /**
2.57 + * Computes the given class's derived value for this {@code ClassValue}.
2.58 + * <p>
2.59 + * This method will be invoked within the first thread that accesses
2.60 + * the value with the {@link #get get} method.
2.61 + * <p>
2.62 + * Normally, this method is invoked at most once per class,
2.63 + * but it may be invoked again if there has been a call to
2.64 + * {@link #remove remove}.
2.65 + * <p>
2.66 + * If this method throws an exception, the corresponding call to {@code get}
2.67 + * will terminate abnormally with that exception, and no class value will be recorded.
2.68 + *
2.69 + * @param type the type whose class value must be computed
2.70 + * @return the newly computed value associated with this {@code ClassValue}, for the given class or interface
2.71 + * @see #get
2.72 + * @see #remove
2.73 + */
2.74 + protected abstract T computeValue(Class<?> type);
2.75 +
2.76 + /**
2.77 + * Returns the value for the given class.
2.78 + * If no value has yet been computed, it is obtained by
2.79 + * an invocation of the {@link #computeValue computeValue} method.
2.80 + * <p>
2.81 + * The actual installation of the value on the class
2.82 + * is performed atomically.
2.83 + * At that point, if several racing threads have
2.84 + * computed values, one is chosen, and returned to
2.85 + * all the racing threads.
2.86 + * <p>
2.87 + * The {@code type} parameter is typically a class, but it may be any type,
2.88 + * such as an interface, a primitive type (like {@code int.class}), or {@code void.class}.
2.89 + * <p>
2.90 + * In the absence of {@code remove} calls, a class value has a simple
2.91 + * state diagram: uninitialized and initialized.
2.92 + * When {@code remove} calls are made,
2.93 + * the rules for value observation are more complex.
2.94 + * See the documentation for {@link #remove remove} for more information.
2.95 + *
2.96 + * @param type the type whose class value must be computed or retrieved
2.97 + * @return the current value associated with this {@code ClassValue}, for the given class or interface
2.98 + * @throws NullPointerException if the argument is null
2.99 + * @see #remove
2.100 + * @see #computeValue
2.101 + */
2.102 + public T get(Class<?> type) {
2.103 + // non-racing this.hashCodeForCache : final int
2.104 + Entry<?>[] cache;
2.105 + Entry<T> e = probeHomeLocation(cache = getCacheCarefully(type), this);
2.106 + // racing e : current value <=> stale value from current cache or from stale cache
2.107 + // invariant: e is null or an Entry with readable Entry.version and Entry.value
2.108 + if (match(e))
2.109 + // invariant: No false positive matches. False negatives are OK if rare.
2.110 + // The key fact that makes this work: if this.version == e.version,
2.111 + // then this thread has a right to observe (final) e.value.
2.112 + return e.value();
2.113 + // The fast path can fail for any of these reasons:
2.114 + // 1. no entry has been computed yet
2.115 + // 2. hash code collision (before or after reduction mod cache.length)
2.116 + // 3. an entry has been removed (either on this type or another)
2.117 + // 4. the GC has somehow managed to delete e.version and clear the reference
2.118 + return getFromBackup(cache, type);
2.119 + }
2.120 +
2.121 + /**
2.122 + * Removes the associated value for the given class.
2.123 + * If this value is subsequently {@linkplain #get read} for the same class,
2.124 + * its value will be reinitialized by invoking its {@link #computeValue computeValue} method.
2.125 + * This may result in an additional invocation of the
2.126 + * {@code computeValue} method for the given class.
2.127 + * <p>
2.128 + * In order to explain the interaction between {@code get} and {@code remove} calls,
2.129 + * we must model the state transitions of a class value to take into account
2.130 + * the alternation between uninitialized and initialized states.
2.131 + * To do this, number these states sequentially from zero, and note that
2.132 + * uninitialized (or removed) states are numbered with even numbers,
2.133 + * while initialized (or re-initialized) states have odd numbers.
2.134 + * <p>
2.135 + * When a thread {@code T} removes a class value in state {@code 2N},
2.136 + * nothing happens, since the class value is already uninitialized.
2.137 + * Otherwise, the state is advanced atomically to {@code 2N+1}.
2.138 + * <p>
2.139 + * When a thread {@code T} queries a class value in state {@code 2N},
2.140 + * the thread first attempts to initialize the class value to state {@code 2N+1}
2.141 + * by invoking {@code computeValue} and installing the resulting value.
2.142 + * <p>
2.143 + * When {@code T} attempts to install the newly computed value,
2.144 + * if the state is still at {@code 2N}, the class value will be initialized
2.145 + * with the computed value, advancing it to state {@code 2N+1}.
2.146 + * <p>
2.147 + * Otherwise, whether the new state is even or odd,
2.148 + * {@code T} will discard the newly computed value
2.149 + * and retry the {@code get} operation.
2.150 + * <p>
2.151 + * Discarding and retrying is an important proviso,
2.152 + * since otherwise {@code T} could potentially install
2.153 + * a disastrously stale value. For example:
2.154 + * <ul>
2.155 + * <li>{@code T} calls {@code CV.get(C)} and sees state {@code 2N}
2.156 + * <li>{@code T} quickly computes a time-dependent value {@code V0} and gets ready to install it
2.157 + * <li>{@code T} is hit by an unlucky paging or scheduling event, and goes to sleep for a long time
2.158 + * <li>...meanwhile, {@code T2} also calls {@code CV.get(C)} and sees state {@code 2N}
2.159 + * <li>{@code T2} quickly computes a similar time-dependent value {@code V1} and installs it on {@code CV.get(C)}
2.160 + * <li>{@code T2} (or a third thread) then calls {@code CV.remove(C)}, undoing {@code T2}'s work
2.161 + * <li> the previous actions of {@code T2} are repeated several times
2.162 + * <li> also, the relevant computed values change over time: {@code V1}, {@code V2}, ...
2.163 + * <li>...meanwhile, {@code T} wakes up and attempts to install {@code V0}; <em>this must fail</em>
2.164 + * </ul>
2.165 + * We can assume in the above scenario that {@code CV.computeValue} uses locks to properly
2.166 + * observe the time-dependent states as it computes {@code V1}, etc.
2.167 + * This does not remove the threat of a stale value, since there is a window of time
2.168 + * between the return of {@code computeValue} in {@code T} and the installation
2.169 + * of the the new value. No user synchronization is possible during this time.
2.170 + *
2.171 + * @param type the type whose class value must be removed
2.172 + * @throws NullPointerException if the argument is null
2.173 + */
2.174 + public void remove(Class<?> type) {
2.175 + ClassValueMap map = getMap(type);
2.176 + map.removeEntry(this);
2.177 + }
2.178 +
2.179 + // Possible functionality for JSR 292 MR 1
2.180 + /*public*/ void put(Class<?> type, T value) {
2.181 + ClassValueMap map = getMap(type);
2.182 + map.changeEntry(this, value);
2.183 + }
2.184 +
2.185 + /// --------
2.186 + /// Implementation...
2.187 + /// --------
2.188 +
2.189 + /** Return the cache, if it exists, else a dummy empty cache. */
2.190 + private static Entry<?>[] getCacheCarefully(Class<?> type) {
2.191 + // racing type.classValueMap{.cacheArray} : null => new Entry[X] <=> new Entry[Y]
2.192 + ClassValueMap map = type.classValueMap;
2.193 + if (map == null) return EMPTY_CACHE;
2.194 + Entry<?>[] cache = map.getCache();
2.195 + return cache;
2.196 + // invariant: returned value is safe to dereference and check for an Entry
2.197 + }
2.198 +
2.199 + /** Initial, one-element, empty cache used by all Class instances. Must never be filled. */
2.200 + private static final Entry<?>[] EMPTY_CACHE = { null };
2.201 +
2.202 + /**
2.203 + * Slow tail of ClassValue.get to retry at nearby locations in the cache,
2.204 + * or take a slow lock and check the hash table.
2.205 + * Called only if the first probe was empty or a collision.
2.206 + * This is a separate method, so compilers can process it independently.
2.207 + */
2.208 + private T getFromBackup(Entry<?>[] cache, Class<?> type) {
2.209 + Entry<T> e = probeBackupLocations(cache, this);
2.210 + if (e != null)
2.211 + return e.value();
2.212 + return getFromHashMap(type);
2.213 + }
2.214 +
2.215 + // Hack to suppress warnings on the (T) cast, which is a no-op.
2.216 + @SuppressWarnings("unchecked")
2.217 + Entry<T> castEntry(Entry<?> e) { return (Entry<T>) e; }
2.218 +
2.219 + /** Called when the fast path of get fails, and cache reprobe also fails.
2.220 + */
2.221 + private T getFromHashMap(Class<?> type) {
2.222 + // The fail-safe recovery is to fall back to the underlying classValueMap.
2.223 + ClassValueMap map = getMap(type);
2.224 + for (;;) {
2.225 + Entry<T> e = map.startEntry(this);
2.226 + if (!e.isPromise())
2.227 + return e.value();
2.228 + try {
2.229 + // Try to make a real entry for the promised version.
2.230 + e = makeEntry(e.version(), computeValue(type));
2.231 + } finally {
2.232 + // Whether computeValue throws or returns normally,
2.233 + // be sure to remove the empty entry.
2.234 + e = map.finishEntry(this, e);
2.235 + }
2.236 + if (e != null)
2.237 + return e.value();
2.238 + // else try again, in case a racing thread called remove (so e == null)
2.239 + }
2.240 + }
2.241 +
2.242 + /** Check that e is non-null, matches this ClassValue, and is live. */
2.243 + boolean match(Entry<?> e) {
2.244 + // racing e.version : null (blank) => unique Version token => null (GC-ed version)
2.245 + // non-racing this.version : v1 => v2 => ... (updates are read faithfully from volatile)
2.246 + return (e != null && e.get() == this.version);
2.247 + // invariant: No false positives on version match. Null is OK for false negative.
2.248 + // invariant: If version matches, then e.value is readable (final set in Entry.<init>)
2.249 + }
2.250 +
2.251 + /** Internal hash code for accessing Class.classValueMap.cacheArray. */
2.252 + final int hashCodeForCache = nextHashCode.getAndAdd(HASH_INCREMENT) & HASH_MASK;
2.253 +
2.254 + /** Value stream for hashCodeForCache. See similar structure in ThreadLocal. */
2.255 + private static final AtomicInteger nextHashCode = new AtomicInteger();
2.256 +
2.257 + /** Good for power-of-two tables. See similar structure in ThreadLocal. */
2.258 + private static final int HASH_INCREMENT = 0x61c88647;
2.259 +
2.260 + /** Mask a hash code to be positive but not too large, to prevent wraparound. */
2.261 + static final int HASH_MASK = (-1 >>> 2);
2.262 +
2.263 + /**
2.264 + * Private key for retrieval of this object from ClassValueMap.
2.265 + */
2.266 + static class Identity {
2.267 + }
2.268 + /**
2.269 + * This ClassValue's identity, expressed as an opaque object.
2.270 + * The main object {@code ClassValue.this} is incorrect since
2.271 + * subclasses may override {@code ClassValue.equals}, which
2.272 + * could confuse keys in the ClassValueMap.
2.273 + */
2.274 + final Identity identity = new Identity();
2.275 +
2.276 + /**
2.277 + * Current version for retrieving this class value from the cache.
2.278 + * Any number of computeValue calls can be cached in association with one version.
2.279 + * But the version changes when a remove (on any type) is executed.
2.280 + * A version change invalidates all cache entries for the affected ClassValue,
2.281 + * by marking them as stale. Stale cache entries do not force another call
2.282 + * to computeValue, but they do require a synchronized visit to a backing map.
2.283 + * <p>
2.284 + * All user-visible state changes on the ClassValue take place under
2.285 + * a lock inside the synchronized methods of ClassValueMap.
2.286 + * Readers (of ClassValue.get) are notified of such state changes
2.287 + * when this.version is bumped to a new token.
2.288 + * This variable must be volatile so that an unsynchronized reader
2.289 + * will receive the notification without delay.
2.290 + * <p>
2.291 + * If version were not volatile, one thread T1 could persistently hold onto
2.292 + * a stale value this.value == V1, while while another thread T2 advances
2.293 + * (under a lock) to this.value == V2. This will typically be harmless,
2.294 + * but if T1 and T2 interact causally via some other channel, such that
2.295 + * T1's further actions are constrained (in the JMM) to happen after
2.296 + * the V2 event, then T1's observation of V1 will be an error.
2.297 + * <p>
2.298 + * The practical effect of making this.version be volatile is that it cannot
2.299 + * be hoisted out of a loop (by an optimizing JIT) or otherwise cached.
2.300 + * Some machines may also require a barrier instruction to execute
2.301 + * before this.version.
2.302 + */
2.303 + private volatile Version<T> version = new Version<>(this);
2.304 + Version<T> version() { return version; }
2.305 + void bumpVersion() { version = new Version<>(this); }
2.306 + static class Version<T> {
2.307 + private final ClassValue<T> classValue;
2.308 + private final Entry<T> promise = new Entry<>(this);
2.309 + Version(ClassValue<T> classValue) { this.classValue = classValue; }
2.310 + ClassValue<T> classValue() { return classValue; }
2.311 + Entry<T> promise() { return promise; }
2.312 + boolean isLive() { return classValue.version() == this; }
2.313 + }
2.314 +
2.315 + /** One binding of a value to a class via a ClassValue.
2.316 + * States are:<ul>
2.317 + * <li> promise if value == Entry.this
2.318 + * <li> else dead if version == null
2.319 + * <li> else stale if version != classValue.version
2.320 + * <li> else live </ul>
2.321 + * Promises are never put into the cache; they only live in the
2.322 + * backing map while a computeValue call is in flight.
2.323 + * Once an entry goes stale, it can be reset at any time
2.324 + * into the dead state.
2.325 + */
2.326 + static class Entry<T> extends WeakReference<Version<T>> {
2.327 + final Object value; // usually of type T, but sometimes (Entry)this
2.328 + Entry(Version<T> version, T value) {
2.329 + super(version);
2.330 + this.value = value; // for a regular entry, value is of type T
2.331 + }
2.332 + private void assertNotPromise() { assert(!isPromise()); }
2.333 + /** For creating a promise. */
2.334 + Entry(Version<T> version) {
2.335 + super(version);
2.336 + this.value = this; // for a promise, value is not of type T, but Entry!
2.337 + }
2.338 + /** Fetch the value. This entry must not be a promise. */
2.339 + @SuppressWarnings("unchecked") // if !isPromise, type is T
2.340 + T value() { assertNotPromise(); return (T) value; }
2.341 + boolean isPromise() { return value == this; }
2.342 + Version<T> version() { return get(); }
2.343 + ClassValue<T> classValueOrNull() {
2.344 + Version<T> v = version();
2.345 + return (v == null) ? null : v.classValue();
2.346 + }
2.347 + boolean isLive() {
2.348 + Version<T> v = version();
2.349 + if (v == null) return false;
2.350 + if (v.isLive()) return true;
2.351 + clear();
2.352 + return false;
2.353 + }
2.354 + Entry<T> refreshVersion(Version<T> v2) {
2.355 + assertNotPromise();
2.356 + @SuppressWarnings("unchecked") // if !isPromise, type is T
2.357 + Entry<T> e2 = new Entry<>(v2, (T) value);
2.358 + clear();
2.359 + // value = null -- caller must drop
2.360 + return e2;
2.361 + }
2.362 + static final Entry<?> DEAD_ENTRY = new Entry<>(null, null);
2.363 + }
2.364 +
2.365 + /** Return the backing map associated with this type. */
2.366 + private static ClassValueMap getMap(Class<?> type) {
2.367 + // racing type.classValueMap : null (blank) => unique ClassValueMap
2.368 + // if a null is observed, a map is created (lazily, synchronously, uniquely)
2.369 + // all further access to that map is synchronized
2.370 + ClassValueMap map = type.classValueMap;
2.371 + if (map != null) return map;
2.372 + return initializeMap(type);
2.373 + }
2.374 +
2.375 + private static final Object CRITICAL_SECTION = new Object();
2.376 + private static ClassValueMap initializeMap(Class<?> type) {
2.377 + ClassValueMap map;
2.378 + synchronized (CRITICAL_SECTION) { // private object to avoid deadlocks
2.379 + // happens about once per type
2.380 + if ((map = type.classValueMap) == null)
2.381 + type.classValueMap = map = new ClassValueMap(type);
2.382 + }
2.383 + return map;
2.384 + }
2.385 +
2.386 + static <T> Entry<T> makeEntry(Version<T> explicitVersion, T value) {
2.387 + // Note that explicitVersion might be different from this.version.
2.388 + return new Entry<>(explicitVersion, value);
2.389 +
2.390 + // As soon as the Entry is put into the cache, the value will be
2.391 + // reachable via a data race (as defined by the Java Memory Model).
2.392 + // This race is benign, assuming the value object itself can be
2.393 + // read safely by multiple threads. This is up to the user.
2.394 + //
2.395 + // The entry and version fields themselves can be safely read via
2.396 + // a race because they are either final or have controlled states.
2.397 + // If the pointer from the entry to the version is still null,
2.398 + // or if the version goes immediately dead and is nulled out,
2.399 + // the reader will take the slow path and retry under a lock.
2.400 + }
2.401 +
2.402 + // The following class could also be top level and non-public:
2.403 +
2.404 + /** A backing map for all ClassValues, relative a single given type.
2.405 + * Gives a fully serialized "true state" for each pair (ClassValue cv, Class type).
2.406 + * Also manages an unserialized fast-path cache.
2.407 + */
2.408 + static class ClassValueMap extends WeakHashMap<ClassValue.Identity, Entry<?>> {
2.409 + private final Class<?> type;
2.410 + private Entry<?>[] cacheArray;
2.411 + private int cacheLoad, cacheLoadLimit;
2.412 +
2.413 + /** Number of entries initially allocated to each type when first used with any ClassValue.
2.414 + * It would be pointless to make this much smaller than the Class and ClassValueMap objects themselves.
2.415 + * Must be a power of 2.
2.416 + */
2.417 + private static final int INITIAL_ENTRIES = 32;
2.418 +
2.419 + /** Build a backing map for ClassValues, relative the given type.
2.420 + * Also, create an empty cache array and install it on the class.
2.421 + */
2.422 + ClassValueMap(Class<?> type) {
2.423 + this.type = type;
2.424 + sizeCache(INITIAL_ENTRIES);
2.425 + }
2.426 +
2.427 + Entry<?>[] getCache() { return cacheArray; }
2.428 +
2.429 + /** Initiate a query. Store a promise (placeholder) if there is no value yet. */
2.430 + synchronized
2.431 + <T> Entry<T> startEntry(ClassValue<T> classValue) {
2.432 + @SuppressWarnings("unchecked") // one map has entries for all value types <T>
2.433 + Entry<T> e = (Entry<T>) get(classValue.identity);
2.434 + Version<T> v = classValue.version();
2.435 + if (e == null) {
2.436 + e = v.promise();
2.437 + // The presence of a promise means that a value is pending for v.
2.438 + // Eventually, finishEntry will overwrite the promise.
2.439 + put(classValue.identity, e);
2.440 + // Note that the promise is never entered into the cache!
2.441 + return e;
2.442 + } else if (e.isPromise()) {
2.443 + // Somebody else has asked the same question.
2.444 + // Let the races begin!
2.445 + if (e.version() != v) {
2.446 + e = v.promise();
2.447 + put(classValue.identity, e);
2.448 + }
2.449 + return e;
2.450 + } else {
2.451 + // there is already a completed entry here; report it
2.452 + if (e.version() != v) {
2.453 + // There is a stale but valid entry here; make it fresh again.
2.454 + // Once an entry is in the hash table, we don't care what its version is.
2.455 + e = e.refreshVersion(v);
2.456 + put(classValue.identity, e);
2.457 + }
2.458 + // Add to the cache, to enable the fast path, next time.
2.459 + checkCacheLoad();
2.460 + addToCache(classValue, e);
2.461 + return e;
2.462 + }
2.463 + }
2.464 +
2.465 + /** Finish a query. Overwrite a matching placeholder. Drop stale incoming values. */
2.466 + synchronized
2.467 + <T> Entry<T> finishEntry(ClassValue<T> classValue, Entry<T> e) {
2.468 + @SuppressWarnings("unchecked") // one map has entries for all value types <T>
2.469 + Entry<T> e0 = (Entry<T>) get(classValue.identity);
2.470 + if (e == e0) {
2.471 + // We can get here during exception processing, unwinding from computeValue.
2.472 + assert(e.isPromise());
2.473 + remove(classValue.identity);
2.474 + return null;
2.475 + } else if (e0 != null && e0.isPromise() && e0.version() == e.version()) {
2.476 + // If e0 matches the intended entry, there has not been a remove call
2.477 + // between the previous startEntry and now. So now overwrite e0.
2.478 + Version<T> v = classValue.version();
2.479 + if (e.version() != v)
2.480 + e = e.refreshVersion(v);
2.481 + put(classValue.identity, e);
2.482 + // Add to the cache, to enable the fast path, next time.
2.483 + checkCacheLoad();
2.484 + addToCache(classValue, e);
2.485 + return e;
2.486 + } else {
2.487 + // Some sort of mismatch; caller must try again.
2.488 + return null;
2.489 + }
2.490 + }
2.491 +
2.492 + /** Remove an entry. */
2.493 + synchronized
2.494 + void removeEntry(ClassValue<?> classValue) {
2.495 + Entry<?> e = remove(classValue.identity);
2.496 + if (e == null) {
2.497 + // Uninitialized, and no pending calls to computeValue. No change.
2.498 + } else if (e.isPromise()) {
2.499 + // State is uninitialized, with a pending call to finishEntry.
2.500 + // Since remove is a no-op in such a state, keep the promise
2.501 + // by putting it back into the map.
2.502 + put(classValue.identity, e);
2.503 + } else {
2.504 + // In an initialized state. Bump forward, and de-initialize.
2.505 + classValue.bumpVersion();
2.506 + // Make all cache elements for this guy go stale.
2.507 + removeStaleEntries(classValue);
2.508 + }
2.509 + }
2.510 +
2.511 + /** Change the value for an entry. */
2.512 + synchronized
2.513 + <T> void changeEntry(ClassValue<T> classValue, T value) {
2.514 + @SuppressWarnings("unchecked") // one map has entries for all value types <T>
2.515 + Entry<T> e0 = (Entry<T>) get(classValue.identity);
2.516 + Version<T> version = classValue.version();
2.517 + if (e0 != null) {
2.518 + if (e0.version() == version && e0.value() == value)
2.519 + // no value change => no version change needed
2.520 + return;
2.521 + classValue.bumpVersion();
2.522 + removeStaleEntries(classValue);
2.523 + }
2.524 + Entry<T> e = makeEntry(version, value);
2.525 + put(classValue.identity, e);
2.526 + // Add to the cache, to enable the fast path, next time.
2.527 + checkCacheLoad();
2.528 + addToCache(classValue, e);
2.529 + }
2.530 +
2.531 + /// --------
2.532 + /// Cache management.
2.533 + /// --------
2.534 +
2.535 + // Statics do not need synchronization.
2.536 +
2.537 + /** Load the cache entry at the given (hashed) location. */
2.538 + static Entry<?> loadFromCache(Entry<?>[] cache, int i) {
2.539 + // non-racing cache.length : constant
2.540 + // racing cache[i & (mask)] : null <=> Entry
2.541 + return cache[i & (cache.length-1)];
2.542 + // invariant: returned value is null or well-constructed (ready to match)
2.543 + }
2.544 +
2.545 + /** Look in the cache, at the home location for the given ClassValue. */
2.546 + static <T> Entry<T> probeHomeLocation(Entry<?>[] cache, ClassValue<T> classValue) {
2.547 + return classValue.castEntry(loadFromCache(cache, classValue.hashCodeForCache));
2.548 + }
2.549 +
2.550 + /** Given that first probe was a collision, retry at nearby locations. */
2.551 + static <T> Entry<T> probeBackupLocations(Entry<?>[] cache, ClassValue<T> classValue) {
2.552 + if (PROBE_LIMIT <= 0) return null;
2.553 + // Probe the cache carefully, in a range of slots.
2.554 + int mask = (cache.length-1);
2.555 + int home = (classValue.hashCodeForCache & mask);
2.556 + Entry<?> e2 = cache[home]; // victim, if we find the real guy
2.557 + if (e2 == null) {
2.558 + return null; // if nobody is at home, no need to search nearby
2.559 + }
2.560 + // assume !classValue.match(e2), but do not assert, because of races
2.561 + int pos2 = -1;
2.562 + for (int i = home + 1; i < home + PROBE_LIMIT; i++) {
2.563 + Entry<?> e = cache[i & mask];
2.564 + if (e == null) {
2.565 + break; // only search within non-null runs
2.566 + }
2.567 + if (classValue.match(e)) {
2.568 + // relocate colliding entry e2 (from cache[home]) to first empty slot
2.569 + cache[home] = e;
2.570 + if (pos2 >= 0) {
2.571 + cache[i & mask] = Entry.DEAD_ENTRY;
2.572 + } else {
2.573 + pos2 = i;
2.574 + }
2.575 + cache[pos2 & mask] = ((entryDislocation(cache, pos2, e2) < PROBE_LIMIT)
2.576 + ? e2 // put e2 here if it fits
2.577 + : Entry.DEAD_ENTRY);
2.578 + return classValue.castEntry(e);
2.579 + }
2.580 + // Remember first empty slot, if any:
2.581 + if (!e.isLive() && pos2 < 0) pos2 = i;
2.582 + }
2.583 + return null;
2.584 + }
2.585 +
2.586 + /** How far out of place is e? */
2.587 + private static int entryDislocation(Entry<?>[] cache, int pos, Entry<?> e) {
2.588 + ClassValue<?> cv = e.classValueOrNull();
2.589 + if (cv == null) return 0; // entry is not live!
2.590 + int mask = (cache.length-1);
2.591 + return (pos - cv.hashCodeForCache) & mask;
2.592 + }
2.593 +
2.594 + /// --------
2.595 + /// Below this line all functions are private, and assume synchronized access.
2.596 + /// --------
2.597 +
2.598 + private void sizeCache(int length) {
2.599 + assert((length & (length-1)) == 0); // must be power of 2
2.600 + cacheLoad = 0;
2.601 + cacheLoadLimit = (int) ((double) length * CACHE_LOAD_LIMIT / 100);
2.602 + cacheArray = new Entry<?>[length];
2.603 + }
2.604 +
2.605 + /** Make sure the cache load stays below its limit, if possible. */
2.606 + private void checkCacheLoad() {
2.607 + if (cacheLoad >= cacheLoadLimit) {
2.608 + reduceCacheLoad();
2.609 + }
2.610 + }
2.611 + private void reduceCacheLoad() {
2.612 + removeStaleEntries();
2.613 + if (cacheLoad < cacheLoadLimit)
2.614 + return; // win
2.615 + Entry<?>[] oldCache = getCache();
2.616 + if (oldCache.length > HASH_MASK)
2.617 + return; // lose
2.618 + sizeCache(oldCache.length * 2);
2.619 + for (Entry<?> e : oldCache) {
2.620 + if (e != null && e.isLive()) {
2.621 + addToCache(e);
2.622 + }
2.623 + }
2.624 + }
2.625 +
2.626 + /** Remove stale entries in the given range.
2.627 + * Should be executed under a Map lock.
2.628 + */
2.629 + private void removeStaleEntries(Entry<?>[] cache, int begin, int count) {
2.630 + if (PROBE_LIMIT <= 0) return;
2.631 + int mask = (cache.length-1);
2.632 + int removed = 0;
2.633 + for (int i = begin; i < begin + count; i++) {
2.634 + Entry<?> e = cache[i & mask];
2.635 + if (e == null || e.isLive())
2.636 + continue; // skip null and live entries
2.637 + Entry<?> replacement = null;
2.638 + if (PROBE_LIMIT > 1) {
2.639 + // avoid breaking up a non-null run
2.640 + replacement = findReplacement(cache, i);
2.641 + }
2.642 + cache[i & mask] = replacement;
2.643 + if (replacement == null) removed += 1;
2.644 + }
2.645 + cacheLoad = Math.max(0, cacheLoad - removed);
2.646 + }
2.647 +
2.648 + /** Clearing a cache slot risks disconnecting following entries
2.649 + * from the head of a non-null run, which would allow them
2.650 + * to be found via reprobes. Find an entry after cache[begin]
2.651 + * to plug into the hole, or return null if none is needed.
2.652 + */
2.653 + private Entry<?> findReplacement(Entry<?>[] cache, int home1) {
2.654 + Entry<?> replacement = null;
2.655 + int haveReplacement = -1, replacementPos = 0;
2.656 + int mask = (cache.length-1);
2.657 + for (int i2 = home1 + 1; i2 < home1 + PROBE_LIMIT; i2++) {
2.658 + Entry<?> e2 = cache[i2 & mask];
2.659 + if (e2 == null) break; // End of non-null run.
2.660 + if (!e2.isLive()) continue; // Doomed anyway.
2.661 + int dis2 = entryDislocation(cache, i2, e2);
2.662 + if (dis2 == 0) continue; // e2 already optimally placed
2.663 + int home2 = i2 - dis2;
2.664 + if (home2 <= home1) {
2.665 + // e2 can replace entry at cache[home1]
2.666 + if (home2 == home1) {
2.667 + // Put e2 exactly where he belongs.
2.668 + haveReplacement = 1;
2.669 + replacementPos = i2;
2.670 + replacement = e2;
2.671 + } else if (haveReplacement <= 0) {
2.672 + haveReplacement = 0;
2.673 + replacementPos = i2;
2.674 + replacement = e2;
2.675 + }
2.676 + // And keep going, so we can favor larger dislocations.
2.677 + }
2.678 + }
2.679 + if (haveReplacement >= 0) {
2.680 + if (cache[(replacementPos+1) & mask] != null) {
2.681 + // Be conservative, to avoid breaking up a non-null run.
2.682 + cache[replacementPos & mask] = (Entry<?>) Entry.DEAD_ENTRY;
2.683 + } else {
2.684 + cache[replacementPos & mask] = null;
2.685 + cacheLoad -= 1;
2.686 + }
2.687 + }
2.688 + return replacement;
2.689 + }
2.690 +
2.691 + /** Remove stale entries in the range near classValue. */
2.692 + private void removeStaleEntries(ClassValue<?> classValue) {
2.693 + removeStaleEntries(getCache(), classValue.hashCodeForCache, PROBE_LIMIT);
2.694 + }
2.695 +
2.696 + /** Remove all stale entries, everywhere. */
2.697 + private void removeStaleEntries() {
2.698 + Entry<?>[] cache = getCache();
2.699 + removeStaleEntries(cache, 0, cache.length + PROBE_LIMIT - 1);
2.700 + }
2.701 +
2.702 + /** Add the given entry to the cache, in its home location, unless it is out of date. */
2.703 + private <T> void addToCache(Entry<T> e) {
2.704 + ClassValue<T> classValue = e.classValueOrNull();
2.705 + if (classValue != null)
2.706 + addToCache(classValue, e);
2.707 + }
2.708 +
2.709 + /** Add the given entry to the cache, in its home location. */
2.710 + private <T> void addToCache(ClassValue<T> classValue, Entry<T> e) {
2.711 + if (PROBE_LIMIT <= 0) return; // do not fill cache
2.712 + // Add e to the cache.
2.713 + Entry<?>[] cache = getCache();
2.714 + int mask = (cache.length-1);
2.715 + int home = classValue.hashCodeForCache & mask;
2.716 + Entry<?> e2 = placeInCache(cache, home, e, false);
2.717 + if (e2 == null) return; // done
2.718 + if (PROBE_LIMIT > 1) {
2.719 + // try to move e2 somewhere else in his probe range
2.720 + int dis2 = entryDislocation(cache, home, e2);
2.721 + int home2 = home - dis2;
2.722 + for (int i2 = home2; i2 < home2 + PROBE_LIMIT; i2++) {
2.723 + if (placeInCache(cache, i2 & mask, e2, true) == null) {
2.724 + return;
2.725 + }
2.726 + }
2.727 + }
2.728 + // Note: At this point, e2 is just dropped from the cache.
2.729 + }
2.730 +
2.731 + /** Store the given entry. Update cacheLoad, and return any live victim.
2.732 + * 'Gently' means return self rather than dislocating a live victim.
2.733 + */
2.734 + private Entry<?> placeInCache(Entry<?>[] cache, int pos, Entry<?> e, boolean gently) {
2.735 + Entry<?> e2 = overwrittenEntry(cache[pos]);
2.736 + if (gently && e2 != null) {
2.737 + // do not overwrite a live entry
2.738 + return e;
2.739 + } else {
2.740 + cache[pos] = e;
2.741 + return e2;
2.742 + }
2.743 + }
2.744 +
2.745 + /** Note an entry that is about to be overwritten.
2.746 + * If it is not live, quietly replace it by null.
2.747 + * If it is an actual null, increment cacheLoad,
2.748 + * because the caller is going to store something
2.749 + * in its place.
2.750 + */
2.751 + private <T> Entry<T> overwrittenEntry(Entry<T> e2) {
2.752 + if (e2 == null) cacheLoad += 1;
2.753 + else if (e2.isLive()) return e2;
2.754 + return null;
2.755 + }
2.756 +
2.757 + /** Percent loading of cache before resize. */
2.758 + private static final int CACHE_LOAD_LIMIT = 67; // 0..100
2.759 + /** Maximum number of probes to attempt. */
2.760 + private static final int PROBE_LIMIT = 6; // 1..
2.761 + // N.B. Set PROBE_LIMIT=0 to disable all fast paths.
2.762 + }
2.763 +}
3.1 --- a/rt/emul/compact/src/main/java/java/lang/InternalError.java Sat Aug 09 11:11:13 2014 +0200
3.2 +++ b/rt/emul/compact/src/main/java/java/lang/InternalError.java Sun Aug 10 05:55:55 2014 +0200
3.3 @@ -1,5 +1,5 @@
3.4 /*
3.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
3.6 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
3.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3.8 *
3.9 * This code is free software; you can redistribute it and/or modify it
3.10 @@ -32,8 +32,7 @@
3.11 * @author unascribed
3.12 * @since JDK1.0
3.13 */
3.14 -public
3.15 -class InternalError extends VirtualMachineError {
3.16 +public class InternalError extends VirtualMachineError {
3.17 private static final long serialVersionUID = -9062593416125562365L;
3.18
3.19 /**
3.20 @@ -47,9 +46,45 @@
3.21 * Constructs an <code>InternalError</code> with the specified
3.22 * detail message.
3.23 *
3.24 - * @param s the detail message.
3.25 + * @param message the detail message.
3.26 */
3.27 - public InternalError(String s) {
3.28 - super(s);
3.29 + public InternalError(String message) {
3.30 + super(message);
3.31 }
3.32 +
3.33 +
3.34 + /**
3.35 + * Constructs an {@code InternalError} with the specified detail
3.36 + * message and cause. <p>Note that the detail message associated
3.37 + * with {@code cause} is <i>not</i> automatically incorporated in
3.38 + * this error's detail message.
3.39 + *
3.40 + * @param message the detail message (which is saved for later retrieval
3.41 + * by the {@link #getMessage()} method).
3.42 + * @param cause the cause (which is saved for later retrieval by the
3.43 + * {@link #getCause()} method). (A {@code null} value is
3.44 + * permitted, and indicates that the cause is nonexistent or
3.45 + * unknown.)
3.46 + * @since 1.8
3.47 + */
3.48 + public InternalError(String message, Throwable cause) {
3.49 + super(message, cause);
3.50 + }
3.51 +
3.52 + /**
3.53 + * Constructs an {@code InternalError} with the specified cause
3.54 + * and a detail message of {@code (cause==null ? null :
3.55 + * cause.toString())} (which typically contains the class and
3.56 + * detail message of {@code cause}).
3.57 + *
3.58 + * @param cause the cause (which is saved for later retrieval by the
3.59 + * {@link #getCause()} method). (A {@code null} value is
3.60 + * permitted, and indicates that the cause is nonexistent or
3.61 + * unknown.)
3.62 + * @since 1.8
3.63 + */
3.64 + public InternalError(Throwable cause) {
3.65 + super(cause);
3.66 + }
3.67 +
3.68 }
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/rt/emul/compact/src/main/java/java/lang/NoSuchFieldException.java Sun Aug 10 05:55:55 2014 +0200
4.3 @@ -0,0 +1,52 @@
4.4 +/*
4.5 + * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4.7 + *
4.8 + * This code is free software; you can redistribute it and/or modify it
4.9 + * under the terms of the GNU General Public License version 2 only, as
4.10 + * published by the Free Software Foundation. Oracle designates this
4.11 + * particular file as subject to the "Classpath" exception as provided
4.12 + * by Oracle in the LICENSE file that accompanied this code.
4.13 + *
4.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
4.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4.17 + * version 2 for more details (a copy is included in the LICENSE file that
4.18 + * accompanied this code).
4.19 + *
4.20 + * You should have received a copy of the GNU General Public License version
4.21 + * 2 along with this work; if not, write to the Free Software Foundation,
4.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4.23 + *
4.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4.25 + * or visit www.oracle.com if you need additional information or have any
4.26 + * questions.
4.27 + */
4.28 +
4.29 +package java.lang;
4.30 +
4.31 +/**
4.32 + * Signals that the class doesn't have a field of a specified name.
4.33 + *
4.34 + * @author unascribed
4.35 + * @since JDK1.1
4.36 + */
4.37 +public class NoSuchFieldException extends ReflectiveOperationException {
4.38 + private static final long serialVersionUID = -6143714805279938260L;
4.39 +
4.40 + /**
4.41 + * Constructor.
4.42 + */
4.43 + public NoSuchFieldException() {
4.44 + super();
4.45 + }
4.46 +
4.47 + /**
4.48 + * Constructor with a detail message.
4.49 + *
4.50 + * @param s the detail message
4.51 + */
4.52 + public NoSuchFieldException(String s) {
4.53 + super(s);
4.54 + }
4.55 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/rt/emul/compact/src/main/java/java/lang/NoSuchMethodError.java Sun Aug 10 05:55:55 2014 +0200
5.3 @@ -0,0 +1,60 @@
5.4 +/*
5.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5.7 + *
5.8 + * This code is free software; you can redistribute it and/or modify it
5.9 + * under the terms of the GNU General Public License version 2 only, as
5.10 + * published by the Free Software Foundation. Oracle designates this
5.11 + * particular file as subject to the "Classpath" exception as provided
5.12 + * by Oracle in the LICENSE file that accompanied this code.
5.13 + *
5.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
5.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5.17 + * version 2 for more details (a copy is included in the LICENSE file that
5.18 + * accompanied this code).
5.19 + *
5.20 + * You should have received a copy of the GNU General Public License version
5.21 + * 2 along with this work; if not, write to the Free Software Foundation,
5.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5.23 + *
5.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5.25 + * or visit www.oracle.com if you need additional information or have any
5.26 + * questions.
5.27 + */
5.28 +
5.29 +package java.lang;
5.30 +
5.31 +/**
5.32 + * Thrown if an application tries to call a specified method of a
5.33 + * class (either static or instance), and that class no longer has a
5.34 + * definition of that method.
5.35 + * <p>
5.36 + * Normally, this error is caught by the compiler; this error can
5.37 + * only occur at run time if the definition of a class has
5.38 + * incompatibly changed.
5.39 + *
5.40 + * @author unascribed
5.41 + * @since JDK1.0
5.42 + */
5.43 +public
5.44 +class NoSuchMethodError extends IncompatibleClassChangeError {
5.45 + private static final long serialVersionUID = -3765521442372831335L;
5.46 +
5.47 + /**
5.48 + * Constructs a <code>NoSuchMethodError</code> with no detail message.
5.49 + */
5.50 + public NoSuchMethodError() {
5.51 + super();
5.52 + }
5.53 +
5.54 + /**
5.55 + * Constructs a <code>NoSuchMethodError</code> with the
5.56 + * specified detail message.
5.57 + *
5.58 + * @param s the detail message.
5.59 + */
5.60 + public NoSuchMethodError(String s) {
5.61 + super(s);
5.62 + }
5.63 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/rt/emul/compact/src/main/java/java/lang/NoSuchMethodException.java Sun Aug 10 05:55:55 2014 +0200
6.3 @@ -0,0 +1,53 @@
6.4 +/*
6.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6.7 + *
6.8 + * This code is free software; you can redistribute it and/or modify it
6.9 + * under the terms of the GNU General Public License version 2 only, as
6.10 + * published by the Free Software Foundation. Oracle designates this
6.11 + * particular file as subject to the "Classpath" exception as provided
6.12 + * by Oracle in the LICENSE file that accompanied this code.
6.13 + *
6.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
6.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6.17 + * version 2 for more details (a copy is included in the LICENSE file that
6.18 + * accompanied this code).
6.19 + *
6.20 + * You should have received a copy of the GNU General Public License version
6.21 + * 2 along with this work; if not, write to the Free Software Foundation,
6.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6.23 + *
6.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6.25 + * or visit www.oracle.com if you need additional information or have any
6.26 + * questions.
6.27 + */
6.28 +
6.29 +package java.lang;
6.30 +
6.31 +/**
6.32 + * Thrown when a particular method cannot be found.
6.33 + *
6.34 + * @author unascribed
6.35 + * @since JDK1.0
6.36 + */
6.37 +public
6.38 +class NoSuchMethodException extends ReflectiveOperationException {
6.39 + private static final long serialVersionUID = 5034388446362600923L;
6.40 +
6.41 + /**
6.42 + * Constructs a <code>NoSuchMethodException</code> without a detail message.
6.43 + */
6.44 + public NoSuchMethodException() {
6.45 + super();
6.46 + }
6.47 +
6.48 + /**
6.49 + * Constructs a <code>NoSuchMethodException</code> with a detail message.
6.50 + *
6.51 + * @param s the detail message.
6.52 + */
6.53 + public NoSuchMethodException(String s) {
6.54 + super(s);
6.55 + }
6.56 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/rt/emul/compact/src/main/java/java/lang/TypeNotPresentException.java Sun Aug 10 05:55:55 2014 +0200
7.3 @@ -0,0 +1,70 @@
7.4 +/*
7.5 + * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7.7 + *
7.8 + * This code is free software; you can redistribute it and/or modify it
7.9 + * under the terms of the GNU General Public License version 2 only, as
7.10 + * published by the Free Software Foundation. Oracle designates this
7.11 + * particular file as subject to the "Classpath" exception as provided
7.12 + * by Oracle in the LICENSE file that accompanied this code.
7.13 + *
7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
7.17 + * version 2 for more details (a copy is included in the LICENSE file that
7.18 + * accompanied this code).
7.19 + *
7.20 + * You should have received a copy of the GNU General Public License version
7.21 + * 2 along with this work; if not, write to the Free Software Foundation,
7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7.23 + *
7.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7.25 + * or visit www.oracle.com if you need additional information or have any
7.26 + * questions.
7.27 + */
7.28 +
7.29 +package java.lang;
7.30 +
7.31 +/**
7.32 + * Thrown when an application tries to access a type using a string
7.33 + * representing the type's name, but no definition for the type with
7.34 + * the specified name can be found. This exception differs from
7.35 + * {@link ClassNotFoundException} in that <tt>ClassNotFoundException</tt> is a
7.36 + * checked exception, whereas this exception is unchecked.
7.37 + *
7.38 + * <p>Note that this exception may be used when undefined type variables
7.39 + * are accessed as well as when types (e.g., classes, interfaces or
7.40 + * annotation types) are loaded.
7.41 + * In particular, this exception can be thrown by the {@linkplain
7.42 + * java.lang.reflect.AnnotatedElement API used to read annotations
7.43 + * reflectively}.
7.44 + *
7.45 + * @author Josh Bloch
7.46 + * @see java.lang.reflect.AnnotatedElement
7.47 + * @since 1.5
7.48 + */
7.49 +public class TypeNotPresentException extends RuntimeException {
7.50 + private static final long serialVersionUID = -5101214195716534496L;
7.51 +
7.52 + private String typeName;
7.53 +
7.54 + /**
7.55 + * Constructs a <tt>TypeNotPresentException</tt> for the named type
7.56 + * with the specified cause.
7.57 + *
7.58 + * @param typeName the fully qualified name of the unavailable type
7.59 + * @param cause the exception that was thrown when the system attempted to
7.60 + * load the named type, or <tt>null</tt> if unavailable or inapplicable
7.61 + */
7.62 + public TypeNotPresentException(String typeName, Throwable cause) {
7.63 + super("Type " + typeName + " not present", cause);
7.64 + this.typeName = typeName;
7.65 + }
7.66 +
7.67 + /**
7.68 + * Returns the fully qualified name of the unavailable type.
7.69 + *
7.70 + * @return the fully qualified name of the unavailable type
7.71 + */
7.72 + public String typeName() { return typeName;}
7.73 +}