Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Suppress safe racy init in AbstractMultiset and HashBiMap. All the classes that are stored in the newly annotated fields have only final fields (except HashBiMap.Inverse, which inherits AbstractBiMap's keySet and values fields, which are themselves @lazyinit), so they are safe to read racily. 2. Mark some graph "cache" fields as volatile. These fields are an optimization: When the user accesses an entry through iteration (and sometimes through get(...)), the graph stores the entry in a field. That way, if the user then queries it again (such as to look up the value associated with a key during iteration), the graph doesn't have to perform a potentially mildly expensive lookup. But this caching isn't implemented in a thread-safe way. It *ought* to be safe to initialize a graph in one thread, safely publish it, and then read it concurrently from other threads. But because of the racy reads of the cached entry fields, I don't think this is guaranteed to be safe. RELNOTES=`graph`: Fixed data race. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=273585560
- Loading branch information
1 parent
491fe70
commit 0e94fb5
Showing
14 changed files
with
382 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...guava-tests/test/com/google/common/graph/ConfigurableSimpleDirectedSortedNetworkTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2014 The Guava Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.common.graph; | ||
|
||
import static com.google.common.graph.ElementOrder.sorted; | ||
|
||
import com.google.common.collect.Ordering; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
/** | ||
* Tests for a directed {@link ConfigurableMutableNetwork}, creating a simple directed sorted graph | ||
* (parallel and self-loop edges are not allowed). | ||
* | ||
* <p>The main purpose of this class is to run the inherited {@link #concurrentIteration} test | ||
* against a sorted graph so as to cover {@link MapRetrievalCache}. | ||
*/ | ||
@RunWith(JUnit4.class) | ||
public class ConfigurableSimpleDirectedSortedNetworkTest | ||
extends ConfigurableSimpleDirectedNetworkTest { | ||
|
||
@Override | ||
public MutableNetwork<Integer, String> createGraph() { | ||
return NetworkBuilder.directed() | ||
.allowsParallelEdges(false) | ||
.allowsSelfLoops(false) | ||
.edgeOrder(sorted(Ordering.natural())) | ||
.nodeOrder(sorted(Ordering.natural())) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public void addEdge_nodesNotInGraph() { | ||
/* | ||
* Skip this test because the expected ordering is different here than in the superclass because | ||
* of sorting. | ||
* | ||
* TODO(cpovirk): Implement this to check for the proper order. | ||
*/ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.