Clean up some casts that would cause warnings on Windows introduced in
PR #66973. Rewrite some of the path computation for the DLL path to
avoid some unnecessary conversions. Split out some of the merged guards
to allow for split diagnostic emissions.
Use the HeapWalk API for heap iteration instead of the
Heap32First/Next API, which was known to be slow. Since HeapWalk only
works locally, it requires using a remote thread and a DLL.
Remove the reference to `DEVELOPER_DIR` and update the instructions to
actually be usable with a released snapshot (and official releases).
The development setup should mimic the actual layout further and is a
separate issue. This requires a new snapshot with
apple/swift-installer-scripts#128 included.
The `__future__` we relied on is now, where the 3 specific things are
all included [since Python 3.0](https://docs.python.org/3/library/__future__.html):
* absolute_import
* print_function
* unicode_literals
* division
These import statements are no-ops and are no longer necessary.
Support inspecting the swift-inspect process itself. `pidFromHint` skips the process it's in, so we manually check the requested name against `argv[0]` as a special case.
Add a `--fork-corpse` flag which uses `task_generate_corpse` on the target task before inspecting it. This allows the target to keep running while we inspect it, and also works around a bug when self-inspecting.
When possible, decode the DrainLock/ExecutionLock fields of tasks and actors in concurrency runtimes built with priority escalation, and show the corresponding thread info in swift-inspect output.
We weren't properly decoding actor flags previously, so fix that up as well and have Remote Mirror split them out into separate fields so clients don't have to. We were missing the Job Storage field from the definition of DefaultActorImpl in RuntimeInternals.h, fix that so we actually read the right data.
rdar://88598003
Have RemoteMirror internally decode these flags fields and return them as separate fields in the task/actor info. Handle the structures both with and without task escalation support.
Also show when a task is the current task on a thread in swift-inspect's task listing.
rdar://88598003
Hoist `iterateHeaps` into the `RemoteProcess` protocol, requiring an
implementation on all platforms. If the platform is unable to implement
heap traversal, it would be possible to simply leave the callback
uncalled.
Be more careful about memory queries, we may receive invalid memory
addresses.
This adds some documentation about swift-inspect and how to build it on
Windows, which requires additional flags to locate the SwiftRemoteMirror
library from the toolchain.
This adds an initial port to Windows which allows inspection of the
processes. It is not possible to port `dump-arrays` or
`dump-concurrency` due to the need to iterate the heap. This still
allows for gaining some insight into the metadata and protocol caches.
Fix the many typos and missing `)` instances. Replace the inline array
removal with explicit duplication due to the behaviour of `#if`. This
allows the tool to build after the changes for the refactoring.
This restructures and refactors the project to split up the
implementation into smaller fragments. The majority of the operations
are portable: the ones which are not require iterating the heap
allocations which is not guaranteed to be a portable operation.
Additionally, the `Inspector` class is renamed into `RemoteProcess`
which is also converted to a protocol to allow adding in an
implementation for other targets. The inspection operations are split
off into individual files to make it easier to follow. Take the
opportunity to use `@main` for the entry point.
Most of the new inspection logic is in Remote Mirror. New code in swift-inspect calls the new Remote Mirror functions and formats the resulting information for display.
Specific Remote Mirror changes:
* Add a call to check if a given metadata is an actor.
* Add calls to get information about actors and tasks.
* Add a `readObj` call to MemoryReader that combines the read and the cast, greatly simplifying code chasing pointers in the remote process.
* Add a generalized facility to the C shims that can allocate a temporary object that remains valid until at least the next call, which is used to return various temporary arrays from the new calls. Remove the existing `lastString` and `lastChunks` member variables in favor of this new facility.
Swift-inspect changes:
* Add a new dump-concurrency command.
* Add a new `ConcurrencyDumper.swift` file with the implementation. The dumper needs to do some additional work with the results from Remote Mirror to build up the task tree and this keeps it all organized.
* Extend `Inspector` to query the target's threads and fetch each thread's current task.
Concurrency runtime changes:
* Add `_swift_concurrency_debug` variables pointing to the various future adapters. Remote Mirror uses these to provide a better view of a tasks's resume pointer.
rdar://85231338
to use it.
ConcurrentReadableHashMap is lock-free for readers, with writers using a lock to
ensure mutual exclusion amongst each other. The intent is to eventually replace
all uses ConcurrentMap with ConcurrentReadableHashMap.
ConcurrentReadableHashMap provides for relatively quick lookups by using a hash
table. Rearders perform an atomic increment/decrement in order to inform writers
that there are active readers. The design attempts to minimize wasted memory by
storing the actual elements out-of-line, and having the table store indices into
a separate array of elements.
The protocol conformance cache now uses ConcurrentReadableHashMap, which
provides faster lookups and less memory use than the previous ConcurrentMap
implementation. The previous implementation caches
ProtocolConformanceDescriptors and extracts the WitnessTable after the cache
lookup. The new implementation directly caches the WitnessTable, removing an
extra step (potentially a quite slow one) from the fast path.
The previous implementation used a generational scheme to detect when negative
cache entries became obsolete due to new dynamic libraries being loaded, and
update them in place. The new implementation just clears the entire cache when
libraries are loaded, greatly simplifying the code and saving the memory needed
to track the current generation in each negative cache entry. This means we need
to re-cache all requested conformances after loading a dynamic library, but
loading libraries at runtime is rare and slow anyway.
rdar://problem/67268325