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

New refcount representation #5282

Merged
merged 44 commits into from
Feb 24, 2017
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
79f090f
WIP: New refcount representation.
Aug 30, 2016
fcdf121
WIP: New refcount representation.
Aug 30, 2016
dcd0f51
WIP: Bias strong refcount. Add strong refcount overflow checking.
Sep 1, 2016
46228cf
WIP: Side table. Separate weak refcount.
Sep 9, 2016
c734c9a
Add long test infrastructure for test/Unit. Use it for max-refcount t…
Sep 1, 2016
43c1063
WIP: Fix debug build. Fix getHeapObject() for side table access.
Sep 16, 2016
d9793d5
WIP: Delete side table entries. Document stuff.
Oct 12, 2016
df0020b
WIP: Record unowned-retain error message to the crash log and console.
Oct 13, 2016
9c7a88a
WIP: Fix leak in swift_weakTakeStrong().
Oct 13, 2016
d3a2363
WIP: nits
Oct 13, 2016
b8decdb
WIP: Add refcounting lifecycle tests.
Oct 13, 2016
42e12f0
WIP: Fix Linux build. Fold Errors.h into Debug.h.
Oct 14, 2016
6a0b6aa
WIP: Fix Linux build.
Oct 14, 2016
6113aab
WIP: Fix Linux build.
Oct 14, 2016
095a795
WIP: Fix 32-bit build.
Oct 18, 2016
6107d43
WIP: Fix some whitespace style.
Oct 19, 2016
23eff3f
WIP: Introduce fake_memory_order_consume. Improve some memory barriers.
Nov 4, 2016
bdbb9be
WIP: Hide a group of assertions behind an NDEBUG check.
Nov 4, 2016
4515d70
WIP: Compact 32-bit inline refcounts.
Nov 4, 2016
3d258c6
Merge branch 'master' of github.com:apple/swift into new-refcount-rep…
Dec 9, 2016
a21ea82
Merge branch 'master' of github.com:apple/swift into new-refcount-rep…
Dec 9, 2016
88882d9
Formatting
Dec 10, 2016
1af09fe
Restore optimization of isUniquelyReferenced and isUniquelyReferenced…
Dec 10, 2016
963b9cf
fake_memory_order_consume -> SWIFT_MEMORY_ORDER_CONSUME
Dec 13, 2016
de7e517
fake_memory_order_consume -> SWIFT_MEMORY_ORDER_CONSUME
Dec 14, 2016
596a3a0
Undo unnecessary diffs.
Dec 15, 2016
3c94ba1
fake_memory_order_consume -> SWIFT_MEMORY_ORDER_CONSUME
Dec 15, 2016
ab2e310
Remove FIXMEs for canBeFreedNow() optimization, which looks fine.
Dec 15, 2016
68755ca
Merge branch 'master' into new-refcount-representation
gparker42 Dec 15, 2016
1f26bb8
Implement out-of-line path of tryIncrementAndPin().
Dec 15, 2016
5ed05f5
Fix Linux build.
Dec 15, 2016
dedcbec
Fix Linux build, maybe.
Dec 15, 2016
43e4a24
Fix Linux test.
Dec 15, 2016
7adaffa
Try to fix Linux tests.
Dec 15, 2016
7c2c0cd
Fix Linux tests.
Dec 15, 2016
c853530
Fix `swiftc -static-stdlib` on Linux.
Dec 15, 2016
af5f37d
Add -latomic to -static-executable.
Dec 16, 2016
e144f79
Merge branch 'master' of github.com:apple/swift into new-refcount-rep…
Feb 9, 2017
1b5b8c4
LLVM_ATTRIBUTE_UNUSED_RESULT has become LLVM_NODISCARD.
Feb 9, 2017
24d1fc2
Add descriptors of weak reference bits for lldb.
Feb 17, 2017
810fc35
Merge branch 'master' into new-refcount-representation
Feb 17, 2017
20d8d0f
Don't static_assert ObjC bits on non-ObjC platforms.
Feb 18, 2017
7880bae
Merge branch 'master' of github.com:apple/swift into new-refcount-rep…
Feb 24, 2017
3910e43
Fix LongRefcounting test.
Feb 24, 2017
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
2 changes: 1 addition & 1 deletion cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ function(_add_variant_link_flags)
RESULT_VAR_NAME result)

if("${LFLAGS_SDK}" STREQUAL "LINUX")
list(APPEND result "-lpthread" "-ldl")
list(APPEND result "-lpthread" "-ldl" "-latomic")
elseif("${LFLAGS_SDK}" STREQUAL "FREEBSD")
list(APPEND result "-lpthread")
elseif("${LFLAGS_SDK}" STREQUAL "CYGWIN")
Expand Down
20 changes: 14 additions & 6 deletions include/swift/Runtime/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <llvm/Support/Compiler.h>
#include <stdint.h>
#include "swift/Runtime/Config.h"
#include "swift/Runtime/Metadata.h"

#ifdef SWIFT_HAVE_CRASHREPORTERCLIENT

Expand Down Expand Up @@ -63,6 +62,12 @@ static void CRSetCrashLogMessage(const char *) {}

namespace swift {

// Duplicated from Metadata.h. We want to use this header
// in places that cannot themselves include Metadata.h.
struct InProcess;
template <typename Runtime> struct TargetMetadata;
using Metadata = TargetMetadata<InProcess>;

// swift::crash() halts with a crash log message,
// but otherwise tries not to disturb register state.

Expand Down Expand Up @@ -91,11 +96,6 @@ static inline void _failCorruptType(const Metadata *type) {
LLVM_ATTRIBUTE_NORETURN
extern void
fatalError(uint32_t flags, const char *format, ...);

struct InProcess;

template <typename Runtime> struct TargetMetadata;
using Metadata = TargetMetadata<InProcess>;

// swift_dynamicCastFailure halts using fatalError()
// with a description of a failed cast's types.
Expand All @@ -117,6 +117,14 @@ SWIFT_RUNTIME_EXPORT
extern "C"
void swift_reportError(uint32_t flags, const char *message);

// Halt due to an overflow in swift_retain().
LLVM_ATTRIBUTE_NORETURN LLVM_ATTRIBUTE_NOINLINE
void swift_abortRetainOverflow();

// Halt due to reading an unowned reference to a dead object.
LLVM_ATTRIBUTE_NORETURN LLVM_ATTRIBUTE_NOINLINE
void swift_abortRetainUnowned(const void *object);

// namespace swift
}

Expand Down
34 changes: 7 additions & 27 deletions include/swift/Runtime/HeapObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,6 @@ extern "C"
void (*SWIFT_CC(RegisterPreservingCC) _swift_nonatomic_retain_n)(HeapObject *object,
uint32_t n);

static inline void _swift_retain_inlined(HeapObject *object) {
if (object) {
object->refCount.increment();
}
}

static inline void _swift_nonatomic_retain_inlined(HeapObject *object) {
if (object) {
object->refCount.incrementNonAtomic();
}
}

/// Atomically increments the reference count of an object, unless it has
/// already been destroyed. Returns nil if the object is dead.
SWIFT_RT_ENTRY_VISIBILITY
Expand Down Expand Up @@ -532,22 +520,22 @@ struct UnownedReference {
HeapObject *Value;
};

/// Increment the weak/unowned retain count.
/// Increment the unowned retain count.
SWIFT_RT_ENTRY_VISIBILITY
extern "C" void swift_unownedRetain(HeapObject *value)
SWIFT_CC(RegisterPreservingCC);

/// Decrement the weak/unowned retain count.
/// Decrement the unowned retain count.
SWIFT_RT_ENTRY_VISIBILITY
extern "C" void swift_unownedRelease(HeapObject *value)
SWIFT_CC(RegisterPreservingCC);

/// Increment the weak/unowned retain count by n.
/// Increment the unowned retain count by n.
SWIFT_RT_ENTRY_VISIBILITY
extern "C" void swift_unownedRetain_n(HeapObject *value, int n)
SWIFT_CC(RegisterPreservingCC);

/// Decrement the weak/unowned retain count by n.
/// Decrement the unowned retain count by n.
SWIFT_RT_ENTRY_VISIBILITY
extern "C" void swift_unownedRelease_n(HeapObject *value, int n)
SWIFT_CC(RegisterPreservingCC);
Expand All @@ -560,7 +548,7 @@ extern "C" void swift_unownedRetainStrong(HeapObject *value)

/// Increment the strong retain count of an object which may have been
/// deallocated, aborting if it has been deallocated, and decrement its
/// weak/unowned reference count.
/// unowned reference count.
SWIFT_RT_ENTRY_VISIBILITY
extern "C" void swift_unownedRetainStrongAndRelease(HeapObject *value)
SWIFT_CC(RegisterPreservingCC);
Expand Down Expand Up @@ -634,16 +622,8 @@ static inline void swift_unownedTakeAssign(UnownedReference *dest,
/****************************** WEAK REFERENCES ******************************/
/*****************************************************************************/

/// A weak reference value object. This is ABI.
struct WeakReference {
uintptr_t Value;
};

/// Return true if this is a native weak reference
///
/// \param ref - never null
/// \return true if ref is a native weak reference
bool isNativeSwiftWeakReference(WeakReference *ref);
// Defined in Runtime/WeakReference.h
class WeakReference;

/// Initialize a weak reference.
///
Expand Down
13 changes: 1 addition & 12 deletions include/swift/Runtime/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ using TargetFarRelativeIndirectablePointer
= typename Runtime::template FarRelativeIndirectablePointer<Pointee,Nullable>;

struct HeapObject;
struct WeakReference;
class WeakReference;

template <typename Runtime> struct TargetMetadata;
using Metadata = TargetMetadata<InProcess>;
Expand Down Expand Up @@ -1827,17 +1827,6 @@ struct TargetObjCClassWrapperMetadata : public TargetMetadata<Runtime> {
using ObjCClassWrapperMetadata
= TargetObjCClassWrapperMetadata<InProcess>;

// FIXME: Workaround for rdar://problem/18889711. 'Consume' does not require
// a barrier on ARM64, but LLVM doesn't know that. Although 'relaxed'
// is formally UB by C++11 language rules, we should be OK because neither
// the processor model nor the optimizer can realistically reorder our uses
// of 'consume'.
#if __arm64__ || __arm__
# define SWIFT_MEMORY_ORDER_CONSUME (std::memory_order_relaxed)
#else
# define SWIFT_MEMORY_ORDER_CONSUME (std::memory_order_consume)
#endif

/// The structure of metadata for foreign types where the source
/// language doesn't provide any sort of more interesting metadata for
/// us to use.
Expand Down
11 changes: 7 additions & 4 deletions stdlib/public/SwiftShims/HeapObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ typedef struct HeapMetadata HeapMetadata;
// The members of the HeapObject header that are not shared by a
// standard Objective-C instance
#define SWIFT_HEAPOBJECT_NON_OBJC_MEMBERS \
StrongRefCount refCount; \
WeakRefCount weakRefCount
InlineRefCounts refCounts;

/// The Swift heap-object header.
struct HeapObject {
Expand All @@ -48,8 +47,7 @@ struct HeapObject {
// Initialize a HeapObject header as appropriate for a newly-allocated object.
constexpr HeapObject(HeapMetadata const *newMetadata)
: metadata(newMetadata)
, refCount(StrongRefCount::Initialized)
, weakRefCount(WeakRefCount::Initialized)
, refCounts(InlineRefCounts::Initialized)
{ }
#endif
};
Expand All @@ -59,6 +57,11 @@ static_assert(swift::IsTriviallyConstructible<HeapObject>::value,
"HeapObject must be trivially initializable");
static_assert(std::is_trivially_destructible<HeapObject>::value,
"HeapObject must be trivially destructible");
// FIXME: small header for 32-bit
//static_assert(sizeof(HeapObject) == 2*sizeof(void*),
// "HeapObject must be two pointers long");
static_assert(alignof(HeapObject) == alignof(void*),
"HeapObject must be pointer-aligned");

} // end namespace swift
#endif
Expand Down
Loading