Skip to content

Commit 14a3ab6

Browse files
committed
Use dynamic runtime instrumentation for dtrace instead of static instrumentation.
When I originally added this I did not understand how dtrace worked well enough. Turns out we do not need any of this runtime instrumentation and we can just dynamically instrument the calls. This commit rips out the all of the static calls and replaces the old runtime_statistics dtrace file with a new one that does the dynamic instrumentation for you. To do this one does the following: sudo dtrace -s ./swift/utils/runtime_statistics.d -c "$CMD" The statistics are currently focused around dynamic retain/release counts.
1 parent 73adca7 commit 14a3ab6

File tree

6 files changed

+8
-61
lines changed

6 files changed

+8
-61
lines changed

CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,6 @@ set(SWIFT_EXPERIMENTAL_EXTRA_REGEXP_FLAGS "" CACHE STRING
185185
set(SWIFT_EXPERIMENTAL_EXTRA_NEGATIVE_REGEXP_FLAGS "" CACHE STRING
186186
"A list of [module_regexp1;flags1;module_regexp2;flags2,...] which can be used to apply specific flags to modules that do not match a cmake regexp. It always applies the first regexp that does not match. The reason this is necessary is that cmake does not provide negative matches in the regex. Instead you have to use NOT in the if statement requiring a separate variable.")
187187

188-
option(SWIFT_RUNTIME_ENABLE_DTRACE
189-
"Should the runtime be built with dtrace instrumentation enabled"
190-
FALSE)
191-
192188
option(SWIFT_RUNTIME_ENABLE_LEAK_CHECKER
193189
"Should the runtime be built with support for non-thread-safe leak detecting entrypoints"
194190
FALSE)

stdlib/public/runtime/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ if(SWIFT_RUNTIME_ENABLE_LEAK_CHECKER)
1717
set(swift_runtime_leaks_sources Leaks.mm)
1818
endif()
1919

20-
set(swift_runtime_dtrace_sources)
21-
if (SWIFT_RUNTIME_ENABLE_DTRACE)
22-
set(swift_runtime_dtrace_sources SwiftRuntimeDTraceProbes.d)
23-
list(APPEND swift_runtime_compile_flags
24-
"-DSWIFT_RUNTIME_ENABLE_DTRACE=1")
25-
endif()
26-
2720
# Acknowledge that the following sources are known.
2821
set(LLVM_OPTIONAL_SOURCES
2922
Remangle.cpp)
@@ -53,7 +46,6 @@ add_swift_library(swiftRuntime IS_STDLIB IS_STDLIB_CORE
5346
Reflection.cpp
5447
SwiftObject.cpp
5548
${swift_runtime_objc_sources}
56-
${swift_runtime_dtrace_sources}
5749
${swift_runtime_leaks_sources}
5850
C_COMPILE_FLAGS ${swift_runtime_compile_flags}
5951
INSTALL_IN_COMPONENT stdlib)

stdlib/public/runtime/HeapObject.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@
3838
# include <objc/objc.h>
3939
#include "swift/Runtime/ObjCBridge.h"
4040
#endif
41-
#if SWIFT_RUNTIME_ENABLE_DTRACE
42-
# include "SwiftRuntimeDTraceProbes.h"
43-
#else
44-
# define SWIFT_ALLOCATEOBJECT()
45-
# define SWIFT_DEALLOCATEOBJECT()
46-
# define SWIFT_RELEASE()
47-
# define SWIFT_RETAIN()
48-
#endif
4941
#include "Leaks.h"
5042

5143
using namespace swift;
@@ -54,7 +46,6 @@ HeapObject *
5446
swift::swift_allocObject(HeapMetadata const *metadata,
5547
size_t requiredSize,
5648
size_t requiredAlignmentMask) {
57-
SWIFT_ALLOCATEOBJECT();
5849
return _swift_allocObject(metadata, requiredSize, requiredAlignmentMask);
5950
}
6051
static HeapObject *
@@ -268,7 +259,6 @@ void _swift_release_dealloc(HeapObject *object)
268259
__attribute__((noinline,used));
269260

270261
void swift::swift_retain(HeapObject *object) {
271-
SWIFT_RETAIN();
272262
_swift_retain(object);
273263
}
274264
static void _swift_retain_(HeapObject *object) {
@@ -277,7 +267,6 @@ static void _swift_retain_(HeapObject *object) {
277267
auto swift::_swift_retain = _swift_retain_;
278268

279269
void swift::swift_retain_n(HeapObject *object, uint32_t n) {
280-
SWIFT_RETAIN();
281270
_swift_retain_n(object, n);
282271
}
283272
static void _swift_retain_n_(HeapObject *object, uint32_t n) {
@@ -288,7 +277,6 @@ static void _swift_retain_n_(HeapObject *object, uint32_t n) {
288277
auto swift::_swift_retain_n = _swift_retain_n_;
289278

290279
void swift::swift_release(HeapObject *object) {
291-
SWIFT_RELEASE();
292280
return _swift_release(object);
293281
}
294282
static void _swift_release_(HeapObject *object) {
@@ -299,7 +287,6 @@ static void _swift_release_(HeapObject *object) {
299287
auto swift::_swift_release = _swift_release_;
300288

301289
void swift::swift_release_n(HeapObject *object, uint32_t n) {
302-
SWIFT_RELEASE();
303290
return _swift_release_n(object, n);
304291
}
305292
static void _swift_release_n_(HeapObject *object, uint32_t n) {
@@ -497,7 +484,6 @@ static inline void memset_pattern8(void *b, const void *pattern8, size_t len) {
497484

498485
void swift::swift_deallocObject(HeapObject *object, size_t allocatedSize,
499486
size_t allocatedAlignMask) {
500-
SWIFT_DEALLOCATEOBJECT();
501487
assert(isAlignmentMask(allocatedAlignMask));
502488
assert(object->refCount.isDeallocating());
503489
#ifdef SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS

stdlib/public/runtime/SwiftObject.mm

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@
4444
# include <malloc/malloc.h>
4545
# include <dispatch/dispatch.h>
4646
#endif
47-
#if SWIFT_RUNTIME_ENABLE_DTRACE
48-
# include "SwiftRuntimeDTraceProbes.h"
49-
#else
50-
#define SWIFT_ISUNIQUELYREFERENCED()
51-
#define SWIFT_ISUNIQUELYREFERENCEDORPINNED()
52-
#endif
5347

5448
using namespace swift;
5549

@@ -1231,7 +1225,6 @@ static bool usesNativeSwiftReferenceCounting_nonNull(
12311225
) {
12321226
assert(object != nullptr);
12331227
assert(!object->refCount.isDeallocating());
1234-
SWIFT_ISUNIQUELYREFERENCED();
12351228
return object->refCount.isUniquelyReferenced();
12361229
}
12371230

@@ -1335,7 +1328,6 @@ static bool usesNativeSwiftReferenceCounting_nonNull(
13351328
/// pinned flag is set.
13361329
bool swift::swift_isUniquelyReferencedOrPinned_nonNull_native(
13371330
const HeapObject* object) {
1338-
SWIFT_ISUNIQUELYREFERENCEDORPINNED();
13391331
assert(object != nullptr);
13401332
assert(!object->refCount.isDeallocating());
13411333
return object->refCount.isUniquelyReferencedOrPinned();

stdlib/public/runtime/SwiftRuntimeDTraceProbes.d

Lines changed: 0 additions & 9 deletions
This file was deleted.

utils/runtime_statistics.d

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
11

2-
swift*:::retain
2+
pid$target:*:swift_retain:entry
33
{
4-
@counts["num retain calls"] = count();
4+
@counts["swift_retain"] = count();
55
}
66

7-
swift*:::release
7+
pid$target:*:swift_release:entry
88
{
9-
@counts["num release calls"] = count();
9+
@counts["swift_release"] = count();
1010
}
1111

12-
swift*:::allocateObject
12+
pid$target:*:objc_retain:entry
1313
{
14-
@counts["num allocated objects"] = count();
14+
@counts["objc_retain"] = count();
1515
}
1616

17-
swift*:::deallocateObject
17+
pid$target:*:objc_release:entry
1818
{
19-
@counts["num deallocated objects"] = count();
20-
}
21-
22-
swift*:::isUniquelyReferenced
23-
{
24-
@counts["num calls to isUniquelyReferenced"] = count();
25-
}
26-
27-
swift*:::isUniquelyReferencedOrPinned
28-
{
29-
@counts["num calls to isUniquelyReferencedOrPinned"] = count();
19+
@counts["objc_release"] = count();
3020
}

0 commit comments

Comments
 (0)