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

Fix bug in handling JNI roots #1636

Merged
merged 1 commit into from Nov 25, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions shark/src/main/java/shark/internal/PathFinder.kt
Expand Up @@ -295,10 +295,11 @@ internal class PathFinder(
is HeapPrimitiveArray -> jniGlobalReferenceMatchers[objectRecord.arrayClassName]
}
if (referenceMatcher !is IgnoredReferenceMatcher) {
if (referenceMatcher is LibraryLeakReferenceMatcher)
if (referenceMatcher is LibraryLeakReferenceMatcher) {
enqueue(LibraryLeakRootNode(gcRoot.id, gcRoot, referenceMatcher))
} else {
enqueue(NormalRootNode(gcRoot.id, gcRoot))
} else {
enqueue(NormalRootNode(gcRoot.id, gcRoot))
}
}
}
else -> enqueue(NormalRootNode(gcRoot.id, gcRoot))
Expand Down
9 changes: 9 additions & 0 deletions shark/src/test/java/shark/HeapAnalyzerTest.kt
Expand Up @@ -5,6 +5,7 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import shark.GcRoot.JniGlobal
import shark.GcRoot.ThreadObject
import shark.LeakTraceElement.Type.LOCAL
import shark.LeakTraceElement.Type.STATIC_FIELD
Expand Down Expand Up @@ -146,4 +147,12 @@ class HeapAnalyzerTest {
assertThat(leak.leakTrace.elements[1].className).isEqualTo("Leaking")
}

@Test fun nativeGlobalVariableApplicationLeak() {
hprofFile.dump {
gcRoot(JniGlobal(id = "Leaking".watchedInstance {}.value, jniGlobalRefId = 42))
}

val leaks = hprofFile.checkForLeaks<HeapAnalysisSuccess>()
assertThat(leaks.applicationLeaks).hasSize(1)
}
}