Skip to content

Commit ac3fec1

Browse files
committed
[swift-inspect] move Android-specific memory region naming to Android
class
1 parent 25da1a9 commit ac3fec1

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

tools/swift-inspect/Sources/SwiftInspectLinux/MemoryMap.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ public class MemoryMap {
2525
public let device: String
2626
public let inode: UInt64
2727
public let pathname: String?
28-
29-
public func isHeapRegion() -> Bool {
30-
guard let name = self.pathname else { return false }
31-
if name == "[anon:libc_malloc]" { return true }
32-
if name.hasPrefix("[anon:scudo:") { return true }
33-
if name.hasPrefix("[anon:GWP-ASan") { return true }
34-
return false
35-
}
3628
}
3729

3830
public let entries: [Entry]

tools/swift-inspect/Sources/swift-inspect/AndroidRemoteProcess.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ import LinuxSystemHeaders
1818
import SwiftInspectLinux
1919
import SwiftRemoteMirror
2020

21+
extension MemoryMap.Entry {
22+
public func isHeapRegion() -> Bool {
23+
guard let name = self.pathname else { return false }
24+
// The heap region naming convention is found in AOSP's libmemunreachable at
25+
// android/platform/system/memory/libmemunreachable/MemUnreachable.cpp.
26+
if name == "[anon:libc_malloc]" { return true }
27+
if name.hasPrefix("[anon:scudo:") { return true }
28+
if name.hasPrefix("[anon:GWP-ASan") { return true }
29+
return false
30+
}
31+
}
32+
2133
internal final class AndroidRemoteProcess: LinuxRemoteProcess {
2234
enum RemoteProcessError: Error {
2335
case missingSymbol(_ name: String)
@@ -39,6 +51,9 @@ internal final class AndroidRemoteProcess: LinuxRemoteProcess {
3951

4052
override internal func iterateHeap(_ body: (swift_addr_t, UInt64) -> Void) {
4153
for entry in self.memoryMap.entries {
54+
// Limiting malloc_iterate calls to only memory regions that are known
55+
// to contain heap allocations is not strictly necessary but it does
56+
// significantly improves the speed of heap iteration.
4257
guard entry.isHeapRegion() else { continue }
4358

4459
// collect all of the allocations in this heap region

0 commit comments

Comments
 (0)