Skip to content

Commit

Permalink
Fixed new cycles in Guava 18.0.
Browse files Browse the repository at this point in the history
	Change on 2015/04/08 by tball <tball@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=90618389
  • Loading branch information
tomball authored and kstanger committed Apr 9, 2015
1 parent e9ec952 commit 1f9594c
Show file tree
Hide file tree
Showing 19 changed files with 152 additions and 60 deletions.
9 changes: 9 additions & 0 deletions guava/cycle_whitelist
Expand Up @@ -3,6 +3,7 @@ TYPE java.lang.Runnable

# *** REAL CYCLES ***
# Inverses
FIELD com.google.common.base.Converter.reverse
FIELD com.google.common.collect.AbstractBiMap.inverse
FIELD com.google.common.collect.ImmutableListMultimap.inverse
FIELD com.google.common.collect.ImmutableSetMultimap.inverse
Expand Down Expand Up @@ -33,3 +34,11 @@ NAMESPACE com.google.common.cache
NAMESPACE com.google.common.hash
NAMESPACE com.google.common.io
NAMESPACE com.google.common.net

# TODO(kstanger): investigate these Guava 18.0 cycles:
FIELD com.google.common.collect.ConcurrentHashMultiset.countMap
FIELD com.google.common.collect.TreeTraverser.PreOrderIterator.stack
FIELD com.google.common.collect.TreeTraverser.PostOrderIterator.stack
FIELD com.google.common.collect.TreeTraverser.PostOrderNode.childIterator
FIELD com.google.common.util.concurrent.Futures.WrappedCombiner.outputFuture
FIELD com.google.common.util.concurrent.AbstractScheduledService.ServiceDelegate.executorService
Expand Up @@ -1317,6 +1317,7 @@ Entry<K, Collection<V>> wrapEntry(Entry<K, Collection<V>> entry) {
return Maps.immutableEntry(key, wrapCollection(key, entry.getValue()));
}

@WeakOuter
class AsMapEntries extends Maps.EntrySet<K, Collection<V>> {
@Override
Map<K, Collection<V>> map() {
Expand Down Expand Up @@ -1427,6 +1428,7 @@ SortedSet<K> createKeySet() {
}

@GwtIncompatible("NavigableAsMap")
@WeakOuter
class NavigableAsMap extends SortedAsMap implements NavigableMap<K, Collection<V>> {

NavigableAsMap(NavigableMap<K, Collection<V>> submap) {
Expand Down
Expand Up @@ -181,6 +181,7 @@ Collection<V> createValues() {
return new Values();
}

@WeakOuter
class Values extends AbstractCollection<V> {
@Override public Iterator<V> iterator() {
return valueIterator();
Expand Down
3 changes: 3 additions & 0 deletions guava/sources/com/google/common/collect/AbstractTable.java
Expand Up @@ -15,6 +15,7 @@
package com.google.common.collect;

import com.google.common.annotations.GwtCompatible;
import com.google.j2objc.annotations.WeakOuter;

import java.util.AbstractCollection;
import java.util.AbstractSet;
Expand Down Expand Up @@ -117,6 +118,7 @@ Set<Cell<R, C, V>> createCellSet() {

abstract Iterator<Table.Cell<R, C, V>> cellIterator();

@WeakOuter
class CellSet extends AbstractSet<Cell<R, C, V>> {
@Override
public boolean contains(Object o) {
Expand Down Expand Up @@ -177,6 +179,7 @@ V transform(Cell<R, C, V> cell) {
};
}

@WeakOuter
class Values extends AbstractCollection<V> {
@Override
public Iterator<V> iterator() {
Expand Down
54 changes: 32 additions & 22 deletions guava/sources/com/google/common/collect/DenseImmutableTable.java
Expand Up @@ -17,6 +17,8 @@
import static com.google.common.base.Preconditions.checkArgument;

import com.google.common.annotations.GwtCompatible;
import com.google.j2objc.annotations.Weak;
import com.google.j2objc.annotations.WeakOuter;

import java.util.Map;

Expand Down Expand Up @@ -122,30 +124,36 @@ public V get(@Nullable Object key) {

@Override
ImmutableSet<Entry<K, V>> createEntrySet() {
return new ImmutableMapEntrySet<K, V>() {
@Override ImmutableMap<K, V> map() {
return ImmutableArrayMap.this;
}

@Override
public UnmodifiableIterator<Entry<K, V>> iterator() {
return new AbstractIterator<Entry<K, V>>() {
private int index = -1;
private final int maxIndex = keyToIndex().size();

@Override
protected Entry<K, V> computeNext() {
for (index++; index < maxIndex; index++) {
V value = getValue(index);
if (value != null) {
return Maps.immutableEntry(getKey(index), value);
}
return new EntrySet<K, V>(this);
}

static class EntrySet<K, V> extends ImmutableMapEntrySet<K, V> {
@Weak ImmutableArrayMap<K, V> map;
EntrySet(ImmutableArrayMap<K, V> map) {
this.map = map;
}
@Override ImmutableMap<K, V> map() {
return map;
}

@Override
public UnmodifiableIterator<Entry<K, V>> iterator() {
return new AbstractIterator<Entry<K, V>>() {
private int index = -1;
private final int maxIndex = map.keyToIndex().size();

@Override
protected Entry<K, V> computeNext() {
for (index++; index < maxIndex; index++) {
V value = map.getValue(index);
if (value != null) {
return Maps.immutableEntry(map.getKey(index), value);
}
return endOfData();
}
};
}
};
return endOfData();
}
};
}
}
}

Expand Down Expand Up @@ -197,6 +205,7 @@ boolean isPartialView() {
}
}

@WeakOuter
private final class RowMap extends ImmutableArrayMap<R, Map<C, V>> {
private RowMap() {
super(rowCounts.length);
Expand All @@ -218,6 +227,7 @@ boolean isPartialView() {
}
}

@WeakOuter
private final class ColumnMap extends ImmutableArrayMap<C, Map<R, V>> {
private ColumnMap() {
super(columnCounts.length);
Expand Down
25 changes: 19 additions & 6 deletions guava/sources/com/google/common/collect/FilteredEntryMultimap.java
Expand Up @@ -218,7 +218,12 @@ public Collection<V> remove(@Nullable Object key) {

@Override
Set<K> createKeySet() {
return new Maps.KeySet<K, Collection<V>>(this) {
@WeakOuter
class KeySet extends Maps.KeySet<K, Collection<V>> {
KeySet(Map<K, Collection<V>> map) {
super(map);
}

@Override
public boolean removeAll(Collection<?> c) {
return removeEntriesIf(Maps.<K>keyPredicateOnEntries(in(c)));
Expand All @@ -233,12 +238,14 @@ public boolean retainAll(Collection<?> c) {
public boolean remove(@Nullable Object o) {
return AsMap.this.remove(o) != null;
}
};
}
return new KeySet(this);
}

@Override
Set<Entry<K, Collection<V>>> createEntrySet() {
return new Maps.EntrySet<K, Collection<V>>() {
@WeakOuter
class AsMapEntrySet extends Maps.EntrySet<K, Collection<V>> {
@Override
Map<K, Collection<V>> map() {
return AsMap.this;
Expand Down Expand Up @@ -280,12 +287,17 @@ public boolean retainAll(Collection<?> c) {
public int size() {
return Iterators.size(iterator());
}
};
}
return new AsMapEntrySet();
}

@Override
Collection<Collection<V>> createValues() {
return new Maps.Values<K, Collection<V>>(AsMap.this) {
@WeakOuter
class Values extends Maps.Values<K, Collection<V>> {
Values(Map<K, Collection<V>> map) {
super(map);
}
@Override
public boolean remove(@Nullable Object o) {
if (o instanceof Collection) {
Expand Down Expand Up @@ -319,7 +331,8 @@ public boolean removeAll(Collection<?> c) {
public boolean retainAll(Collection<?> c) {
return removeEntriesIf(Maps.<Collection<V>>valuePredicateOnEntries(not(in(c))));
}
};
}
return new Values(AsMap.this);
}
}

Expand Down
Expand Up @@ -19,6 +19,7 @@

import com.google.common.annotations.GwtCompatible;
import com.google.common.base.Predicate;
import com.google.j2objc.annotations.WeakOuter;

import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -180,6 +181,7 @@ Collection<Entry<K, V>> createEntries() {
return new Entries();
}

@WeakOuter
class Entries extends ForwardingCollection<Entry<K, V>> {
@Override
protected Collection<Entry<K, V>> delegate() {
Expand Down
Expand Up @@ -20,6 +20,7 @@
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.j2objc.annotations.Weak;

import java.util.AbstractCollection;
import java.util.Collection;
Expand All @@ -36,7 +37,7 @@
*/
@GwtCompatible
final class FilteredMultimapValues<K, V> extends AbstractCollection<V> {
private final FilteredMultimap<K, V> multimap;
@Weak private final FilteredMultimap<K, V> multimap;

FilteredMultimapValues(FilteredMultimap<K, V> multimap) {
this.multimap = checkNotNull(multimap);
Expand Down
Expand Up @@ -22,6 +22,7 @@
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.MoreObjects;
import com.google.j2objc.annotations.Weak;

import java.io.IOException;
import java.io.InvalidObjectException;
Expand Down Expand Up @@ -423,7 +424,7 @@ private ImmutableSetMultimap<V, K> invert() {
}

private static final class EntrySet<K, V> extends ImmutableSet<Entry<K, V>> {
private transient final ImmutableSetMultimap<K, V> multimap;
@Weak private transient final ImmutableSetMultimap<K, V> multimap;

EntrySet(ImmutableSetMultimap<K, V> multimap) {
this.multimap = multimap;
Expand Down
Expand Up @@ -23,6 +23,7 @@
import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
import com.google.j2objc.annotations.WeakOuter;

import java.io.IOException;
import java.io.ObjectInputStream;
Expand Down Expand Up @@ -300,6 +301,7 @@ public Set<V> replaceValues(@Nullable K key, Iterable<? extends V> values) {
}

@VisibleForTesting
@WeakOuter
final class ValueSet extends Sets.ImprovedAbstractSet<V> implements ValueSetLink<K, V> {
/*
* We currently use a fixed load factor of 1.0, a bit higher than normal to reduce memory
Expand Down
12 changes: 8 additions & 4 deletions guava/sources/com/google/common/collect/LinkedListMultimap.java
Expand Up @@ -684,7 +684,8 @@ class LinkedListMultimapList extends AbstractSequentialList<V> {

@Override
Set<K> createKeySet() {
return new Sets.ImprovedAbstractSet<K>() {
@WeakOuter
class LinkedListMultimapKeySet extends Sets.ImprovedAbstractSet<K> {
@Override public int size() {
return keyToKeyList.size();
}
Expand All @@ -698,7 +699,8 @@ Set<K> createKeySet() {
public boolean remove(Object o) { // for performance
return !LinkedListMultimap.this.removeAll(o).isEmpty();
}
};
}
return new LinkedListMultimapKeySet();
}

/**
Expand Down Expand Up @@ -766,15 +768,17 @@ public List<Entry<K, V>> entries() {

@Override
List<Entry<K, V>> createEntries() {
return new AbstractSequentialList<Entry<K, V>>() {
@WeakOuter
class Entries extends AbstractSequentialList<Entry<K, V>> {
@Override public int size() {
return size;
}

@Override public ListIterator<Entry<K, V>> listIterator(int index) {
return new NodeIterator(index);
}
};
}
return new Entries();
}

@Override
Expand Down
Expand Up @@ -3806,6 +3806,7 @@ public void clear() {
}
}

@WeakOuter
final class Values extends AbstractCollection<V> {

@Override
Expand Down

0 comments on commit 1f9594c

Please sign in to comment.