Commit Graph

86 Commits

Author SHA1 Message Date
Arnold Schwaighofer
48e889b51b IRGen: EmptyBoxType's representation cannot be nil because of a conflict with extra inhabitant assumption in indirect enums (#10326)
* IRGen: EmptyBoxType's representation cannot be nil because of a conflict with extra inhabitant assumption in indirect enums

We map nil to the .None case of Optional. Instead use a singleton object.

SR-5148
rdar://32618580
2017-06-17 09:33:41 -07:00
Arnold Schwaighofer
67e3d27fd9 Copy-on-write existential performance work (#8369)
* IRGen: Change c-o-w existential implementation functions

* initialzeBufferWith(Copy|Take)OfBuffer value witness implementation for cow existentials

Implement and use initialzeBufferWith(Copy|Take)OfBuffer value witnesses for
copy-on-write existentials.

Before we used a free standing function but the overhead of doing so was
noticable (~20-30%) on micro benchmarks.

* IRGen: Use common getCopyOutOfLineBoxPointerFunction

* Add a runtime function to conditionally make a box unique

* Fix compilation of HeapObject.cpp on i386

* Fix IRGen test case

* Fix test case for i386
2017-03-27 20:51:02 -07:00
Mikio Takeuchi
69768ad540 Update for the new reference counting mechanism 2017-02-27 16:56:32 +09:00
Mikio Takeuchi
4f68ccf86e Add swift_nonatomic_unowned(Retain|Release)_n 2017-02-27 12:25:58 +09:00
Mikio Takeuchi
488d531846 Enhance -assume-single-threaded option (SR-3945) 2017-02-27 12:17:53 +09:00
Joe Groff
24367fa5d9 Runtime: Have native refcounting entry points ignore negative pointer values on x86-64 and arm64.
The high half of the address space is used by the kernel in these architectures, and it would be useful for us to be able to pack small values into places the ABI otherwise requires a refcountable pointer, such as closures and maybe refcounted existentials.
2017-02-24 16:02:11 -08: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
Arnold Schwaighofer
39fa2f0228 Use the swift calling convention for swift functions
Use the generic type lowering algorithm described in
"docs/CallingConvention.rst#physical-lowering" to map from IRGen's explosion
type to the type expected by the ABI.

Change IRGen to use the swift calling convention (swiftcc) for native swift
functions.

Use the 'swiftself' attribute on self parameters and for closures contexts.

Use the 'swifterror' parameter for swift error parameters.

Change functions in the runtime that are called as native swift functions to use
the swift calling convention.

rdar://19978563
2017-02-14 12:17:57 -08:00
Hugh Bellamy
d457742a8d Change getKeyIntValueForDump to use intptr_t rather than long 2017-02-12 09:46:36 +07:00
Greg Parker
ff2f056868 Tweak whitespace. 2017-02-11 12:51:20 -08:00
Hugh Bellamy
00b7c2ed70 Use LLVM_* attributes in the runtime 2017-02-11 17:30:01 +07:00
Hugh Bellamy
1d2aa8dcbd Cleanup uses of SWIFT_RUNTIME_EXPORT in implementation files (#7127) 2017-01-31 19:38:53 -08:00
Hugh Bellamy
d030ae4c94 Cleanup uses of SWIFT_RT_ENTRY_VISIBILITY (#7103) 2017-01-31 15:53:14 -08:00
Hugh Bellamy
a5a4880075 Remove extern "C" uses of SWIFT_RT_ENTRY_VISIBILITY 2017-01-22 18:32:17 +00:00
Hugh Bellamy
63cf2d561e Remove extern "C" from uses of SWIFT_RUNTIME_EXPORT 2017-01-22 18:32:17 +00: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
Erik Eckstein
bd0d2bfed4 Remove the LLVM stack promotion pass and related SIL optimization logic.
It's not needed anymore because array buffers are now allocated with alloc_ref instead of a swift_bufferAllocate runtime call.
2016-09-16 11:02:19 -07:00
Dmitri Gribenko
fbb3cf35a5 Revert "New SIL instructions to support tail-allocated arrays in SIL." 2016-09-15 00:25:25 -07:00
Erik Eckstein
6ae818c9d1 Remove the LLVM stack promotion pass and related SIL optimization logic.
It's not needed anymore because array buffers are now allocated with alloc_ref instead of a swift_bufferAllocate runtime call.
2016-09-14 14:54:18 -07:00
John McCall
4b22a29a7c Change MetadataCache to just use malloc/free.
IIRC we never had any evidence that the performance impact of a
separate allocator here was actually measurable, and it does come
at a significant fragmentation cost because every single cache
allocates at least a page of memory.  Sharing that with the system
allocator makes more sense, even if these allocations are typically
permanent.

This also means that standard memory-debugging tools will actually
find problems with out-of-bounds accesses to metadata.
2016-09-01 14:19:14 -07:00
John McCall
28bbc54bb2 Switch the generic heap box metadata cache over to use ConcurrentMap directly. 2016-09-01 14:09:44 -07:00
Saleem Abdulrasool
91a296fad6 stdlib: avoid posix sched_yield in favour of C++11
Use the C++11 std::this_thread::yield to abstract away platform specific
differences for yield execution time.  This makes the code more portable to
non-POSIX environments (i.e. Windows).  NFC.
2016-06-15 18:18:26 -07:00
Dmitri Gribenko
f47b53350e Runtime: remove unused include 2016-06-03 15:54:42 -07:00
Han Sangjin
be815aabbb [stdlib/msvc] Runtime with MSVC library
This patch is for libswiftCore.lib, linking with the library set of Visual Studio 2015. Clang with the option -fms-extension is used to build this port.
This is the approved subpatch of a large patch.
2016-06-02 08:10:40 +09:00
Bryan Chan
85fde8b1fb Add support for Linux s390x. LLVM's Swift calling convention support is used to ensure correct operations of C++ code in the runtime. This patch also includes some (incomplete) changes to enum handling to make enums work in most common cases. 2016-05-24 20:03:28 -04:00
David Farler
2799cabcfb SwiftRemoteMirror: Dig into generic SIL boxes
Part 1: Generic SIL Boxes always have instatiated metadata with kind
HeapGenericLocalVariable, which includes a metadata pointer for the
boxed type.

Part 2, after this, is to provide some kind of outgoing pointer map for
fixed heap boxes, whose metadata may be shared among different but
destructor-compatible types.

rdar://problem/26240419
2016-05-17 01:30:28 -07: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
Guillaume Lessard
94a9c512b9 [runtime] thread safety for weak references
It has been fairly easy to cause the runtime to crash on multithreaded read-read access to weak references (e.g. https://bugs.swift.org/browse/SR-192). Although weak references are value types, they can get elevated to the heap in multiple ways, such as when captured by a closure or when used as a property in a class object instance. In such cases, race conditions involving weak references could cause the runtime to perform to multiple decrement operations of the unowned reference count for a single increment; this eventually causes early deallocation, leading to use-after-free, modify-after-free and double-free errors.

This commit changes the weak reference operations to use a spinlock rather than assuming thread-exclusive access, when appropriate.
With this change, the crasher discussed in SR-192 no longer encounters crashes due to modify-after-free or double-free errors.
2016-05-03 20:58:44 -06: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
Doug Gregor
3fb06d7442 [Swift runtime] Deallocation of partial class instances for Objective-C-derived classes.
Teach swift_deallocPartialClassInstance how to deal with classes that
have pure Objective-C classes in their hierarchy. In such cases, we
need to make sure a few things happen:

1) We deallocate via objc_release rather than
swift_deallocClassInstance.
2) We only attempt to find an execute ivar destroyers for
Swift-defined classes in the hierarchy
3) When we hit the most-derived pure Objective-C class, make sure that we
only execute the dealloc of that class and not any of the subclasses
(which would end up trying to destroy ivars again).

Fixes rdar://problem/25023544.
2016-03-08 16:47:57 -08:00
Rintaro Ishizaki
8408e12540 [stdlib] Fix an unused function warning on Linux 2016-03-05 10:23:14 +09:00
Roman Levenstein
dbf233318b swift_allocObject should be exposed as a visible runtime entry. 2016-02-25 08:46:57 -08:00
Roman Levenstein
99fd8b6080 Rename some macros based on the PR review comments.
- use  the SWIFT prefix for all macros
- make names of some macros shorter
2016-02-25 05:31:00 -08:00
Roman Levenstein
de3b850ce8 Use more descriptive names for calling conventions.
Rename RuntimeCC into DefaultCC
Rename RuntimeCC1 into RegisterPreservingCC
Remove RuntimeCC0 because it was identical to DefaultCC.
2016-02-25 05:31:00 -08:00
Roman Levenstein
68b6181642 Annotate runtime functions using the newly introduced annotations from runtime/Config.h.
This makes sure that runtime functions use proper calling conventions, get the required visibility, etc.

We annotate the most popular runtime functions in terms of how often they are invoked from Swift code.
- Almost all variants of retain/release functions are annotated to use the new calling convention.
- Some popular non-reference counting functions like swift_getGenericMetadata or swift_dynamicCast are annotated as well.

The set of runtime functions annotated to use the new calling convention should exactly match the definitions in RuntimeFunctions.def!
2016-02-25 05:30:59 -08:00
John McCall
fc261045a5 Optimize the number of accesses performed on ConcurrentMap
and MetadataCache and fix a re-entrancy bug in metadata
instantiation.

The re-entrancy bug is that we were holding the instantiation
lock of a metadata cache while instantiating metadata.  Doing
so prevents us from creating a different instantiation if
it's needed by the outer instantiation.  This is already
possible, but it's much more likely in a patch I'm working on
to only store the minimal metadata for generic parameters
in generic types.

The same bug could also show up as a deadlock between threads,
so a recursive lock would not be a good fix.  Instead, we add
a condition variable to the metadata cache.  When fetching
metadata, we look for a node in the concurrent map, eagerly
creating an empty one if none currently exists.  If lookup
finds an empty node, we wait on the condition variable for
the node to become populated.  If lookup succeeds in creating
an empty node, we instantiate the metadata, grab the lock,
populate the node, and notify the condition variable.

Safely creating an empty node without any metadata present
requires us to move the key data into the map entry.  That,
plus a few other invariant shifts, makes it sensible to
give the user of ConcurrentMap more control over the
allocation of map nodes and the layout of keys.  That, in
turn, allows us to change the contract so that keys can be
more complex than just a hash code.  Instead of incrementing
hash codes and re-performing the lookup, we just insist
that lookup keys be totally ordered.

For now, I've kept the uniform use of hash codes as a
component of the key for MetadataCaches.  However, hash
codes aren't really profitable for small keys, and we should
probably use direct comparisons instead.

We should also switch the safer metadata caches (i.e. the
ones that don't involve calling an arbitrary instantiation
function, like MetatypeMetadataCache) over to directly use
ConcurrentMap.

LLDB's requirement that we maintain a linked list of metadata
cache instantiations with a known layout means we can't yet
remove the CacheEntry's redundant copy of the generic
arguments.
2016-02-25 01:11:57 -08:00
Chris Lattner
92566e3fd8 Merge pull request #1438 from glessard/renamed-weak
Update comment to reflect the renaming of weakRelease
2016-02-24 18:44:00 -08:00
Guillaume Lessard
420ce32258 update comment to reflect that weakRelease was renamed 2016-02-24 08:38:50 -07:00
Joe Groff
ae0e855aaf Revert "Runtime: Remove retainCount entry points."
This reverts commit 51e0594e1c. The retainCount
entry points are used by Instruments.
2016-02-18 09:38:23 -08:00
Slava Pestov
e5dac9c793 Runtime: Fix crash with non-pointer isa in swift_deallocPartialClassInstance()
Deallocation of partially-initialized instances of @objc classes
isn't supported yet, but let's avoid a regression compared to
Swift 2.1 behavior by fixing the one case that used to work,
where the early return occurs after all stored properties have
been initialized.

Fixes SR-704.
2016-02-15 14:36:48 -08:00
Joe Groff
f7291b21ec Runtime: Build with -fvisibility=hidden.
...and explicitly mark symbols we export, either for use by executables or for runtime-stdlib interaction. Until the stdlib supports resilience we have to allow programs to link to these SPI symbols.
2016-02-08 08:06:02 -08:00
Harlan Haskins
b55d8d9c3c [Runtime] Add backtrace reporting on fatalError in debug builds 2016-01-29 13:42:06 -08:00
Joe Groff
7775b9c261 Runtime: Remove swift_retainCount entry points.
These are no longer needed by the corelibs.
2016-01-06 14:12:03 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Michael Gottesman
14a3ab61cb 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.
2015-12-28 18:17:12 -06:00
practicalswift
22e10737e2 Fix typos 2015-12-26 01:19:40 +01:00
Joe Groff
4b7ed84c42 Revert "Runtime: Remove retainCount entry points."
This reverts 51e0594e1c. The corelibs are using this entry point.
2015-12-22 13:06:42 -08:00
Joe Groff
51e0594e1c Runtime: Remove retainCount entry points.
They're only used for testing and ObjC interop, so don't need to be exported from the runtime.
2015-12-22 11:51:59 -08:00