diff options
author | cpeyser <cpeyser@google.com> | 2018-03-26 09:36:23 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-26 09:37:31 -0700 |
commit | cf1c75a67dc7aadcca24c869a9dd19dc93df5d19 (patch) | |
tree | b874eeaaeec7f6f352ff2ff6642918487deb4a58 /src/main/java/com/google/devtools/build/lib/collect | |
parent | 171a7ebd9a28c4169f2c3018b9c4d740dadcf324 (diff) |
During NestedSet deserialization, maintain a list of known children outside of
the global digestToChild map. Since digestToChild contains weak references,
this is required to ensure the children are not GCed.
PiperOrigin-RevId: 190476243
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/collect')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodec.java | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodec.java b/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodec.java index ba170820b3..4932b3474c 100644 --- a/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodec.java +++ b/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodec.java @@ -28,6 +28,7 @@ import com.google.protobuf.CodedInputStream; import com.google.protobuf.CodedOutputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; import java.util.IdentityHashMap; import java.util.LinkedHashSet; @@ -94,12 +95,14 @@ public class NestedSetCodec<T> implements ObjectCodec<NestedSet<T>> { "Should have at least serialized one nested set, got: %s", nestedSetCount); Order order = orderCodec.deserialize(context, codedIn); - Object children = null; + ArrayList<Object> childrenForThisNestedSet = new ArrayList<>(nestedSetCount); for (int i = 0; i < nestedSetCount; ++i) { - // Update var, the last one in the list is the top level nested set - children = deserializeOneNestedSet(context, codedIn); + // Maintain pointers to all children in this NestedSet so that their entries in the + // digestToChild map are not GCed. + childrenForThisNestedSet.add(deserializeOneNestedSet(context, codedIn)); } - return createNestedSet(order, children); + // The last element of childrenForThisNestedSet is the top-level NestedSet + return createNestedSet(order, childrenForThisNestedSet.get(nestedSetCount - 1)); } private void serializeOneNestedSet( |