Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Merge branch 'binder_leak'" #598

Merged
merged 1 commit into from
Sep 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,43 +179,19 @@ private void visitRootObj(LeakNode node) {
RootObj rootObj = (RootObj) node.instance;
Instance child = rootObj.getReferredInstance();

Exclusion exclusion = rootSuperClassAlwaysIgnored(child);

if (exclusion != null && exclusion.alwaysExclude) {
return;
}

if (rootObj.getRootType() == RootType.JAVA_LOCAL) {
Instance holder = HahaSpy.allocatingThread(rootObj);
// We switch the parent node with the thread instance that holds
// the local reference.
LeakNode parent = new LeakNode(null, holder, null, null, null);
Exclusion exclusion = null;
if (node.exclusion != null) {
exclusion = node.exclusion;
}
LeakNode parent = new LeakNode(null, holder, null, null, null);
enqueue(exclusion, parent, child, "<Java Local>", LOCAL);
} else {
enqueue(exclusion, node, child, null, null);
}
}

private Exclusion rootSuperClassAlwaysIgnored(Instance child) {
if (child == null) {
return null;
}
Exclusion matchingParams = null;
ClassObj superClassObj = child.getClassObj();
while (superClassObj != null) {
Exclusion params = excludedRefs.rootClassNames.get(superClassObj.getClassName());
if (params != null) {
// true overrides null or false.
if (matchingParams == null || !matchingParams.alwaysExclude) {
matchingParams = params;
}
}
superClassObj = superClassObj.getSuperClassObj();
enqueue(null, node, child, null, null);
}
return matchingParams;
}

private void visitClassObj(LeakNode node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import static com.squareup.leakcanary.TestUtil.HeapDumpFile.ASYNC_TASK;
import static com.squareup.leakcanary.TestUtil.HeapDumpFile.ASYNC_TASK_MPREVIEW2;
import static com.squareup.leakcanary.TestUtil.HeapDumpFile.ASYNC_TASK_M_POSTPREVIEW2;
import static com.squareup.leakcanary.TestUtil.HeapDumpFile.SERVICE_BINDER;
import static com.squareup.leakcanary.TestUtil.HeapDumpFile.SERVICE_BINDER_IGNORED;
import static com.squareup.leakcanary.TestUtil.analyze;
import static org.junit.Assert.assertEquals;

Expand All @@ -27,8 +25,6 @@ public class RetainedSizeTest {
{ ASYNC_TASK, 207_407 }, //
{ ASYNC_TASK_MPREVIEW2, 1_604 }, //
{ ASYNC_TASK_M_POSTPREVIEW2, 1_870 }, //
{ SERVICE_BINDER, 378 }, //
{ SERVICE_BINDER_IGNORED, 378 }, //
});
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ enum HeapDumpFile {
ASYNC_TASK("leak_asynctask.hprof", "dc983a12-d029-4003-8890-7dd644c664c5"),
ASYNC_TASK_MPREVIEW2("leak_asynctask_mpreview2.hprof", "1114018e-e154-435f-9a3d-da63ae9b47fa"),
ASYNC_TASK_M_POSTPREVIEW2("leak_asynctask_m_postpreview2.hprof",
"25ae1778-7c1d-4ec7-ac50-5cce55424069"),

SERVICE_BINDER("leak_service_binder.hprof", "b3abfae6-2c53-42e1-b8c1-96b0558dbeae"),
SERVICE_BINDER_IGNORED("leak_service_binder_ignored.hprof",
"6e524414-9581-4ce7-8690-e8ddf8b82454"),;
"25ae1778-7c1d-4ec7-ac50-5cce55424069");

private final String filename;
private final String referenceKey;
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,6 @@ public enum AndroidExcludedRefs {
}
},

SERVICE_BINDER {
@Override void add(ExcludedRefs.Builder excluded) {
// We should ignore leaks where an android.os.Binder is the root of the leak.
// When you bind and unbind from a Service, the OS will keep a reference to the Binder
// until the client binder has been GC'ed. This means the Binder can be retained after
// Service.onDestroy() is called.
excluded.rootClass("android.os.Binder").alwaysExclude();
}
},

SOFT_REFERENCES {
@Override void add(ExcludedRefs.Builder excluded) {
excluded.clazz(WeakReference.class.getName()).alwaysExclude();
Expand Down Expand Up @@ -450,7 +440,7 @@ public enum AndroidExcludedRefs {
public static ExcludedRefs.Builder createAndroidDefaults() {
return createBuilder(
EnumSet.of(SOFT_REFERENCES, FINALIZER_WATCHDOG_DAEMON, MAIN, LEAK_CANARY_THREAD,
EVENT_RECEIVER__MMESSAGE_QUEUE, SERVICE_BINDER));
EVENT_RECEIVER__MMESSAGE_QUEUE));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import static java.util.Collections.unmodifiableMap;

/**
* Prevents specific references from being taken into account when computing the shortest reference
* path from a suspected leaking instance to the GC roots.
* Prevents specific references from being taken into account when computing the shortest strong
* reference path from a suspected leaking instance to the GC roots.
*
* This class lets you ignore known memory leaks that you know about. If the shortest path
* This class lets you ignore known memory leaks that you known about. If the shortest path
* matches {@link ExcludedRefs}, than the heap analyzer should look for a longer path with nothing
* matching in {@link ExcludedRefs}.
*/
Expand All @@ -40,14 +40,12 @@ public static Builder builder() {
public final Map<String, Map<String, Exclusion>> staticFieldNameByClassName;
public final Map<String, Exclusion> threadNames;
public final Map<String, Exclusion> classNames;
public final Map<String, Exclusion> rootClassNames;

ExcludedRefs(BuilderWithParams builder) {
this.fieldNameByClassName = unmodifiableRefStringMap(builder.fieldNameByClassName);
this.staticFieldNameByClassName = unmodifiableRefStringMap(builder.staticFieldNameByClassName);
this.threadNames = unmodifiableRefMap(builder.threadNames);
this.classNames = unmodifiableRefMap(builder.classNames);
this.rootClassNames = unmodifiableRefMap(builder.rootClassNames);
}

private Map<String, Map<String, Exclusion>> unmodifiableRefStringMap(
Expand Down Expand Up @@ -91,10 +89,6 @@ private Map<String, Exclusion> unmodifiableRefMap(Map<String, ParamsBuilder> fie
String always = clazz.getValue().alwaysExclude ? " (always)" : "";
string += "| Class:" + clazz.getKey() + always + "\n";
}
for (Map.Entry<String, Exclusion> clazz : rootClassNames.entrySet()) {
String always = clazz.getValue().alwaysExclude ? " (always)" : "";
string += "| Root Class:" + clazz.getKey() + always + "\n";
}
return string;
}

Expand All @@ -118,8 +112,6 @@ public interface Builder {

BuilderWithParams clazz(String className);

BuilderWithParams rootClass(String rootSuperClassName);

ExcludedRefs build();
}

Expand All @@ -131,7 +123,6 @@ public static final class BuilderWithParams implements Builder {
new LinkedHashMap<>();
private final Map<String, ParamsBuilder> threadNames = new LinkedHashMap<>();
private final Map<String, ParamsBuilder> classNames = new LinkedHashMap<>();
private final Map<String, ParamsBuilder> rootClassNames = new LinkedHashMap<>();

private ParamsBuilder lastParams;

Expand Down Expand Up @@ -179,14 +170,6 @@ public static final class BuilderWithParams implements Builder {
return this;
}

/** Ignores any GC root that belongs to a subclass of the provided class name. */
@Override public BuilderWithParams rootClass(String rootClassName) {
checkNotNull(rootClassName, "rootClassName");
lastParams = new ParamsBuilder("any GC root subclass of " + rootClassName);
rootClassNames.put(rootClassName, lastParams);
return this;
}

public BuilderWithParams named(String name) {
lastParams.name = name;
return this;
Expand Down