Commit Graph

58 Commits

Author SHA1 Message Date
David Smith
78c693ba2d Avoid mishandling retain_n of immortal objects where n >= 3 2020-03-25 15:53:31 -07:00
David Smith
4bd56334ef Avoid incorrectly asserting when we disable pure Swift deallocation on an object that has a side table 2020-02-18 11:44:37 -08:00
Dario Rexin
d913eefcc9 Remove dependency on libatomic on Linux
Due to some unfortunate interplay between clang and libstdc++, clang was
not able to correctly identify to alignment of PoolRange and
SideTableRefCountBits, causing it to emit library calls instead of
inlining atomic operations. This was fixed by adding the appropriate
alignment to those types. In addition to that the march for the Linux
target was set to 'core2', which is the earliest architecture to support
cx16, which is necessary for the atomic operations on PoolRange.
2020-01-31 15:59:54 -08:00
David Smith
f36a4db856 Update fast dealloc to use new-style interposing and support objc weak refs 2020-01-22 13:55:27 -08:00
Saleem Abdulrasool
beafad9651 SwiftShims: unify assertion paths (NFC)
Use the C++ spelling for the static assertions.  This is a C11
extension, but GCC and MSVC both object to the reserved spelling
(`_Static_assert`).  Use the compatibility spelling of `static_assert`
on all targets instead.
2019-12-27 10:17:43 -08:00
Saleem Abdulrasool
13c1391138 SwiftShims: restrict AArch64 workaround to C++
`RefCount.h` can be included in a C context - e.g. building the
SwiftShims module.  Restrict the C++ overloads to the C++ context only.
This partially improves the build for Windows ARM64.
2019-07-14 14:01:40 -07:00
Parker Schuh
fa69a73ee4 Add -enable-cxx-interop flag and support for extern "C" {} 2019-07-08 11:43:35 -07:00
Saleem Abdulrasool
c0fb0036a3 Runtime: add a workaround for Windows ARM64
Unfortunately, `std::atomic` in msvcprt as of 14.21.27702 is broken for
double-width atomics on ARM64.  This has been reported to Microsoft and
is going to be fixed in VC++ 2019u3.  For the time being, add a partial
template specialisation for the two double-word sized types temporarily
as a workaround.  This allows the standard library build to get further.
2019-07-03 09:27:59 -07:00
David Smith
a84af6f68b Revert "Revert "Revert "Use the remaining half bit in the refcount to bypass ObjC deallocation overhead"""
This reverts commit c51294671b.
2019-07-01 14:29:40 -07:00
David Smith
c51294671b Revert "Revert "Use the remaining half bit in the refcount to bypass ObjC deallocation overhead""
And add availability checking for back deployment

This reverts commit 817ea129f2.
2019-06-18 16:16:38 -07:00
Mishal Shah
817ea129f2 Revert "Use the remaining half bit in the refcount to bypass ObjC deallocation overhead" 2019-06-05 23:10:34 -07:00
David Smith
8abffa7d89 Use the remaining half bit in the refcount to bypass ObjC deallocation overhead 2019-06-05 14:10:19 -07:00
Saleem Abdulrasool
0983ea66ae stdlib: use placement new on Windows, disable asserts
The assertions here are based around the idea that `std::atomic` is
trivially constructible which is not a guarantee that the standard fully
provides.  The default initialization of the `std::atomic` type may
leave it in an undetermined state.  These were caught using the Visual
C++ preview runtime.

Ideally, the object constructor would use a placement new operator.
However, prior to C++17, the C++ standard mandated that there be a
NULL pointer check in the placement new operator.  This is something
which is no longer the case with C++17.  Switch to the placement new
operator for C++17 and newer and enable that codepath for Windows as
well (which seemingly elides the null-pointer check with clang-cl).
2019-02-27 15:29:06 -08:00
Saleem Abdulrasool
90fd8a5d34 stdlib: define and use SWIFT_{,UN}LIKELY
Rather than directly using the extension `__builtin_expect`, use a macro
to permit the removal of the builtin on compilers which do not support
this (i.e. cl).  This permits us to build the swift compiler with MSVC
again.
2019-02-24 13:58:18 -08:00
David Smith
78c45e77b7 Add a flag to allow Swift objects (such as the singleton empty collections) to ignore refcounting 2019-02-19 18:22:39 -08:00
Mike Ash
1afd079b78 [Runtime] Fix swift_retainCount for deiniting objects and BridgeObject tagged values. Make swift_bridgeObjectRetain/Release bail out early for tagged values.
The Allocations Instrument overrides swift_retain with a function that records the retain count by calling swift_retainCount. Its assert for bits.getIsDeiniting() is incorrect in that case, so remove it.

The recent change to ObjC tagged pointer bits on x86-64 also caused the various bridgeObjectRetain/Release functions to call through to swift_retain for BridgeObject tagged values on Mac. swift_retain ignored those values so there was no functional change, except when Instruments overrode it and passed them to swift_retainCount, which tried to dereference them and crashed. Modify bridgeObjectRetain/Release to bail out early again. Also modify swift_retainCount to ignore those values in case anything else expects retainCount to work on any pointer swift_retain accepts.

rdar://problem/45102538
2018-10-09 10:04:06 -04:00
Saleem Abdulrasool
d8efe22eaf stdlib: adjust the shims for MSVC mode compilation
The SwiftStdint.h header is used in the compiler as well.  The compiler may be
built with cl (Visual Studio) on Windows, which does not define
`__INTPTR_TYPE__` nor does it define `__INTPTR_WIDTH__`.  Simply define the
`__swift_{,u}intptr_t` typedefs as Microsoft does on that platform when building
with Visual Studio.
2018-09-12 11:48:41 -07:00
Erik Eckstein
8f35a3eff7 runtime: remove pinning in reference counting and pinning runtime entry points
rdar://problem/35401813
2018-08-25 11:14:18 -07:00
Mike Ash
da4fa67d7e [Runtime] Move ConcurrentReadableArray's allocate/deallocate functions into Storage. Mark ConcurrentReadableArray as un-copyable, un-assignable, and un-movable. Use SWIFT_MEMORY_ORDER_CONSUME instead of std::memory_order_consume. Make read() pass a const pointer.
rdar://problem/37173156
2018-05-15 15:27:33 -04:00
Mike Ash
ed4e3b9bf3 [Runtime] Fix up the URC overflow test and support code after merging the latest master.
rdar://problem/33765960
2018-03-21 15:34:11 -07:00
Mike Ash
f2b89d1b94 Merge branch 'master' into fix-urc-overflow-to-side-table-in-deinit 2018-03-21 15:32:01 -07:00
Michael Gottesman
68e2e708d0 [runtime] Add a dumping method to HeapObject when asserts are enabled.
Given any heap object, this method dumps:

* The pointer address of the heap object.
* The pointer address of the heap metadata of the object.
* The strong reference count.
* The unowned reference count.
* The weak reference count.
* Whether or not the value is in the deinit state.
* Whether or not the heap object uses swift_retain or objc_retain.
* The address of the object's side table if one exists.

This makes it really easy when debugging quickly to get all of the information
that you could possibly need from a HeapObject.
2018-02-07 11:54:48 -08:00
Mike Ash
146833c9b5 [Runtime] Fix unowned refcount overflow to side table during deinit.
32-bit has a 7-bit inline unowned refcount, then 31 bits in the side table. Overflowing the inline count in deinit on an object that didn't already have a side table would crash, because the code assumed that creating a side table in deinit was not allowed.

(64-bit has 31 bits inline and in the side table. Overflowing the inline count immediately overflows the side table as well, so there's no change in behavior there.)

rdar://problem/33765960
2018-01-30 15:38:08 -05:00
Greg Parker
e223f1fc9b [IRGen][runtime] Simplify runtime CCs and entry point ABIs (#14175)
* Remove RegisterPreservingCC. It was unused.
* Remove DefaultCC from the runtime. The distinction between C_CC and DefaultCC
  was unused and inconsistently applied. Separate C_CC and DefaultCC are
  still present in the compiler.
* Remove function pointer indirection from runtime functions except those
  that are used by Instruments. The remaining Instruments interface is
  expected to change later due to function pointer liability.
* Remove swift_rt_ wrappers. Function pointers are an ABI liability that we
  don't want, and there are better ways to get nonlazy binding if we need it.
  The fully custom wrappers were only needed for RegisterPreservingCC and
  for optimizing the Instruments function pointers.
2018-01-29 13:22:30 -08:00
Mike Ash
406ebaddfc [Runtime] Implement overflow check for weak refcounts (#14023)
* Check for overflow in incrementWeak().

This mirrors what is currently done for unowned reference counts, where overflowing the side table field produces a fatal error. Without this, the count silently wrapped from 2^31-1 to 0, which then caused breakage when the balancing releases happened (possibly including use-after-free bugs).

* Fix the implementation of RefCounts::getWeakCount().

The previous implementation was only appropriate for heap objects, but not side tables. This resulted in the weak count always returning 0 or 1. This change specializes the implementation for the two different cases and returns the correct count for side tables.

* Test large weak retain counts.

This tests the largest allowed weak retain count, as well as the overflow check when that count is exceeded.
2018-01-19 19:13:47 -08:00
Greg Parker
96c0ef6e48 [runtime] Clean up an unnecessary C++ template trampoline. (#13381) 2017-12-11 19:26:52 -08:00
Greg Parker
9a38e609af [IRGen][runtime] Reduce object header to 8 bytes on 32-bit platforms. (#12790)
SR-4353, rdar://29765800
2017-11-08 02:50:11 -08:00
Jordan Rose
5f2eb82ebf [runtime] Use an unnamed bitfield to avoid -Wglobal-constructor (#12617)
(instead of an unused field that we'd rather not initialize)

constexpr can't be 100% enforced in a template, so instead it gets
silently dropped if the instantiated function doesn't fulfill all the
requirements of being constexpr. In this case, that was a constructor
not explicitly initializing all fields, even the one we marked
unavailable. This meant we were using a non-constexpr constructor to
instantiate a global, which semantically requires static
initialization.

(The actual initialization is still optimized away at the LLVM
level. But the Clang frontend doesn't know that.)

Note that the warning will still fire unless you update your Clang
build; I just today cherry-picked the change that handles unnamed
bitfields correctly.
2017-10-25 14:23:51 -07:00
Arnold Schwaighofer
bc68d51ad8 Use the preserve_most calling convention for the increment slow path
This improves x86-64 code generation to not having any stack operations on the fast path.
2017-09-19 07:16:37 -07:00
Saleem Abdulrasool
635bb00d61 runtime: make LLP64 clean
This is a blanket pass replacing use of `__LP64__` with
`__POINTER_WIDTH__ == 64`.  The latter is more expressive and also LLP64
clean.  This change is needed to enable support for Windows x86_64 which
is a LLP64 environment.
2017-09-17 18:41:10 -07:00
Greg Parker
c262440e70 [runtime] Fix some const cast warnings. 2017-08-31 18:22:17 -07:00
Károly Lőrentey
3f9abaa1f8 [runtime] Implement sidetable path for isUniquelyReferenced
https://bugs.swift.org/browse/SR-5633
2017-08-05 20:26:28 +02:00
Arnold Schwaighofer
d8abd2fed9 runtime: Fix overflow of swift_unownedRetain reference counts
On 32bit platforms there are 7 bits reserved for the unowned retain count. This
makes overflow a likely scenario. Implement overflow into the side table.

rdar://33495003
2017-08-02 07:12:47 -07:00
Greg Parker
d8b341bc74 [runtime] Fix alignment of HeapObject header on watchOS.
HeapObject contains an InlineRefCounts. The Swift shim definition of
InlineRefCounts used uint64_t, which has the correct size but the incorrect
alignment on armv7k. This caused the Swift stdlib and the Swift runtime
to disagree about object layouts.

rdar://31664545
2017-05-02 18:36:16 -07:00
practicalswift
734ed6834f [gardening] Use correct multi-line block comment 2017-04-14 17:33:24 +02:00
Arnold Schwaighofer
b167b4475d Add SIL and IRGen support for a ConstantStringLiteral instruction
This supports a utf8 or utf16 encoding.

rdar://30545013
2017-04-11 08:43:47 -07:00
Hugh Bellamy
1e919d2f4e Fix attribute fallout from new refcount representation 2017-03-18 17:56:34 +07:00
Hugh Bellamy
fe48ea7cbc Fix MSVC/GCC compilation failures resulting from new refcount representation 2017-03-14 00:18:17 +07:00
Hugh Bellamy
bb34e2a959 Fix attribute fallout from new refcount representation 2017-03-02 19:44:37 +07:00
practicalswift
bf50a9ad4a [gardening] Fix double spaces 2017-02-28 17:14:44 +01:00
Mikio Takeuchi
2741535ee0 Add non-atomic variants to SideTable 2017-02-27 23:41:20 +09:00
Mikio Takeuchi
69768ad540 Update for the new reference counting mechanism 2017-02-27 16:56:32 +09:00
Mikio Takeuchi
488d531846 Enhance -assume-single-threaded option (SR-3945) 2017-02-27 12:17:53 +09:00
Greg Parker
ae1c984920 New refcount representation (#5282)
New refcount representation and weak variable implementation. See SwiftShims/RefCount.h for details.
2017-02-24 14:19:11 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Saleem Abdulrasool
81661fca61 stdlib: use the reserved attribute spellings
This is a purely mechanical change replacing the attributes with the reserved
spelling.  Compilers are to not error when they encounter a reserved spelling
for an attribute which they do not support.
2016-05-11 11:30:24 -07:00
Roman Levenstein
5d22a59e01 Provide non-atomic versions of many reference counting operations.
Provide the same guarantees regrading the barriers as the atomic versions.
2016-03-30 16:43:05 -07:00
Erik Eckstein
e1b94885a2 runtime: add a new runtime function swift_setDeallocating.
It's to be used by code produced by the ReleaseDevirtualizer.
As the function is only used for non-escaping objects, the deallocating bit is set non-atomically.
2016-03-15 12:56:54 -07:00
Michael Gottesman
27b5f930d8 [gardening] Fix two small indentation issues. NFC. 2016-02-02 15:39:14 -08:00