88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Copyright 2009 Goldman Sachs International. All Rights Reserved.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * This code is free software; you can redistribute it and/or modify it
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * under the terms of the GNU General Public License version 2 only, as
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * published by the Free Software Foundation.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * This code is distributed in the hope that it will be useful, but WITHOUT
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * version 2 for more details (a copy is included in the LICENSE file that
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * accompanied this code).
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * You should have received a copy of the GNU General Public License version
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * 2 along with this work; if not, write to the Free Software Foundation,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * or visit www.oracle.com if you need additional information or have any
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * @bug 6865031
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * @summary Application gives bad result (throws bad exception) with compressed oops
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:HeapBaseMinAddress=32g -XX:-LoopUnswitching -XX:CompileCommand=inline,AbstractMemoryEfficientList.equals Test hello goodbye
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore public Object set(final int index, final Object element);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amoreabstract class AbstractMemoryEfficientList implements MyList {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore abstract public Object get(final int index);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore abstract public Object set(final int index, final Object element);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (o == this) {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!(o instanceof MyList)) {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return false;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return false;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return false;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore System.out.println("concurrent modification of this:" + this.getClass() + ":" + System.identityHashCode(this) + "; that:" + that.getClass() + ":" + System.identityHashCode(that) + "; i:" + i);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore throw new RuntimeException("concurrent modification of this:" + this.getClass() + ":" + System.identityHashCode(this) + "; that:" + that.getClass() + ":" + System.identityHashCode(that) + "; i:" + i, e);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorefinal class SingletonList extends AbstractMemoryEfficientList {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore public Object set(final int index, final Object element) {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore final Object previousElement = this.element1;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorefinal class DoubletonList extends AbstractMemoryEfficientList {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore DoubletonList(final Object obj1, final Object obj2) {
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems case 1 : return this.element2;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore default: throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size());
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems public Object set(final int index, final Object element) {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore final Object previousElement = this.element1;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore final Object previousElement = this.element2;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore default : throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + this.size());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore protected static final int DEFAULT_INITIAL_CAPACITY = 16;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore private static final int MAXIMUM_CAPACITY = 1 << 30;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore private static final float DEFAULT_LOAD_FACTOR = 0.75f;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore private final ReferenceQueue<V> queue = new ReferenceQueue<V>();
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore table = new Entry[DEFAULT_INITIAL_CAPACITY];
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Check for equality of non-null reference x and possibly-null y. By
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * default uses Object.equals.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return x == y || x.equals(y);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Return index for hash code h.
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems private int indexFor(int h, int length)
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems * Expunge stale entries from the table.
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems int i = indexFor(h, table.length);
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems // System.out.println("EXPUNGING " + h);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Return the table after first expunging stale entries
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Returns the number of key-value mappings in this map.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * This result is a snapshot, and may not reflect unprocessed
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * entries that will be removed before next attempted access
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * because they are no longer referenced.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Returns <tt>true</tt> if this map contains no key-value mappings.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * This result is a snapshot, and may not reflect unprocessed
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * entries that will be removed before next attempted access
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * because they are no longer referenced.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Returns the value stored in the pool that equals the requested key
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems * or <tt>null</tt> if the map contains no mapping for
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * this key (or the key is null)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * @param key the key whose equals value is to be returned.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * @return the object that is equal the specified key, or
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * <tt>null</tt> if key is null or no object in the pool equals the key.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Returns the entry associated with the specified key in the HashMap.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Returns null if the HashMap contains no mapping for this key.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore while (e != null && !(e.hash == h && eq(key, e.get())))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Places the object into the pool. If the object is null, nothing happens.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * If an equal object already exists, it is not replaced.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * @param key the object to put into the pool. key may be null.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * @return the object in the pool that is equal to the key, or the newly placed key if no such object existed when put was called
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore for (Entry<V> e = tab[i]; e != null; e = e.next)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore tab[i] = new Entry<V>(key, queue, h, tab[i]);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore // System.out.println("Added " + key + " to pool");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Rehashes the contents of this map into a new array with a
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * larger capacity. This method is called automatically when the
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * number of keys in this map reaches its threshold.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * If current capacity is MAXIMUM_CAPACITY, this method does not
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * resize the map, but but sets threshold to Integer.MAX_VALUE.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * This has the effect of preventing future calls.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * @param newCapacity the new capacity, MUST be a power of two;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * must be greater than current capacity unless current
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * capacity is MAXIMUM_CAPACITY (in which case value
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * is irrelevant).
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore Entry<V>[] newTable = new Entry[newCapacity];
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * If ignoring null elements and processing ref queue caused massive
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * shrinkage, then restore old table. This should be rare, but avoids
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * unbounded expansion of garbage-filled tables.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore threshold = (int) (newCapacity * loadFactor);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Transfer all entries from src to dest tables
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore private void transfer(Entry[] src, Entry[] dest)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Removes the object in the pool that equals the key.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * @return previous value associated with specified key, or <tt>null</tt>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * if there was no mapping for key or the key is null.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Removes all mappings from this map.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore // clear out ref queue. We don't need to expunge entries
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore // since table is getting cleared.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore table = new Entry[DEFAULT_INITIAL_CAPACITY];
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore // Allocation of array may have caused GC, which may have caused
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore // additional entries to go stale. Removing these entries from the
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore // reference queue will make them eligible for reclamation.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * The entries in this hash table extend WeakReference, using its main ref
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * field as the key.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Create new entry.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore Entry(final V key, final ReferenceQueue<V> queue, final int hash, final Entry<V> next)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return super.get();
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return false;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore WeakPool.Entry<V> that = (WeakPool.Entry<V>) o;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (this == obj) {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return false;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore MultiSynonymKey that = (MultiSynonymKey) obj;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return this.getKeys().equals(that.getKeys());
68c47f65208790c466e5e484f2293d3baed71c6aGarrett D'Amore return this.getClass().getName() + this.getKeys().toString();
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore while (true) {
} catch (Exception e) {}
synchronized (wp) {
} catch (Exception e) {}
synchronized (wp) {
synchronized (wp) {
counter++;
return x == y || x.equals(y);