Commit Graph

599 Commits

Author SHA1 Message Date
Nadav Rotem
22b722d1c3 Document and explain which parts of the cache are locked.
Swift SVN r24098
2014-12-23 03:01:12 +00:00
Nadav Rotem
9dbd84932c Document some parts of the conformance search process. NFC.
Swift SVN r24093
2014-12-23 00:32:16 +00:00
Nadav Rotem
e2bd14ddfe Fix an 80-col violation.
Swift SVN r24092
2014-12-23 00:32:15 +00:00
Nadav Rotem
c9308b75b7 Remove the locks from the fast path of swift_conformsToProtocol
Swift SVN r24091
2014-12-23 00:32:15 +00:00
Nadav Rotem
fbd3264662 Whitespace.
Swift SVN r24090
2014-12-23 00:32:15 +00:00
Nadav Rotem
a4a835f712 Refactor the code that searches the conformance cache into a new method. NFC.
Swift SVN r24089
2014-12-23 00:32:14 +00:00
Nadav Rotem
65589c8c7a Whitespace
Swift SVN r24088
2014-12-23 00:32:14 +00:00
Nadav Rotem
0d6888dfa6 Refactor the code that installs the dylib inspection callbacks. NFC.
Swift SVN r24087
2014-12-23 00:32:11 +00:00
Dmitri Hrybenko
d6406875d8 Annotate runtime functions that use the Swift +1 parameter convention
with NS_RELEASES_ARGUMENT

Swift SVN r24057
2014-12-20 04:11:44 +00:00
Dmitri Hrybenko
4f819a9cf7 Remove an NSSet.copyObjectPointers() API that was unintentionally added
Swift SVN r24054
2014-12-20 03:01:34 +00:00
Dmitri Hrybenko
9177107940 stdlib/Hashing: move the hash seed variable to C++ code to avoid
dispatch_once calls on every load from it

Performance improvements, as reported by the perf testing buildbot:

Histogram       -18.81%
TwoSum          -17.42%
RGBHistogram    -9.65%

Regressions:

InsertionSort                5.59%
ArrayOfRef                   3.99%
SwiftStructuresInsertionSort 5.29%
PrimeNum                     6.09%

These regressions are bogus.  The tests that "regressed" don't do any
hashing at all.

Swift SVN r23995
2014-12-17 23:45:29 +00:00
Nadav Rotem
e9ba57a342 Replace std::function with llvm::function_ref to avoid memory allocation for large lambdas.
This class does not own the callable and does not allocate memory.

Swift SVN r23952
2014-12-16 00:47:28 +00:00
Nadav Rotem
d7e6386850 Revert "Get rid of a memory allocation on each call to the getXXXMetadata functions."
This reverts r23919.

Swift SVN r23951
2014-12-16 00:47:25 +00:00
Dmitri Hrybenko
e87bcff79d stdlib: move String.{lowercaseString,uppercaseString} to the core
library

Swift SVN r23936
2014-12-15 09:47:03 +00:00
Nadav Rotem
e9ffbd6707 Get rid of a memory allocation on each call to the getXXXMetadata functions.
We were using std::function that allocated memory. Unfortunately c++ lambdas
don't have a type so I had to make the function findOrAdd templated on the
type of the callback. This is not a big deal since the class is already
templated and there is a single call site.

Swift SVN r23919
2014-12-14 05:43:23 +00:00
Maxwell Swadling
63462e64d0 [stdlib] Added ASCII fast path for string hashing
Swift SVN r23896
2014-12-12 22:22:58 +00:00
Dmitri Hrybenko
2a19887dec Allow SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS to work on non-Darwin
Swift SVN r23826
2014-12-10 04:34:19 +00:00
Joe Groff
343f35a81c Runtime: Make sure the superclass of a class is realized before we instantiate it.
Fixes a crash when some programs were run in JIT mode; they instantiated a JITed class before the ObjC subclass was realized. Send a message to super to realize the class before we try to readClassPair it. Fixes rdar://problem/19170232.

Swift SVN r23825
2014-12-10 01:12:29 +00:00
John McCall
3b4e0d307e Intrinsic support for pinning.
Using the intrinsics is obnoxious because I needed them
to return Builtin.NativeObject?, but there's no reasonable
way to safely generate optional types from Builtins.cpp.
Ugh.

Dave and I also decided that there's no need for
swift_tryPin to allow a null object.

Swift SVN r23824
2014-12-10 00:52:48 +00:00
Nadav Rotem
de706b1ae6 Whitespace
Swift SVN r23821
2014-12-09 23:51:26 +00:00
Nadav Rotem
ddfe1cc876 Use size_t for the hash type and fix the undefined behavior that came from shifts on 32bit targets.
Swift SVN r23814
2014-12-09 22:31:27 +00:00
Joe Groff
f229161b9b Runtime: Fix memory management in swift_ClassMirror_quickLookObject.
rdar://problem/18513769. Add tests that exercise all the code paths to ensure we keep everything balanced.

Swift SVN r23773
2014-12-07 20:55:24 +00:00
John McCall
3f46b30ca4 Add runtime functions to "pin" a native Swift object.
Pinning an object prevents it from being deallocated,
just like retaining it, but only one client can own the
pin at once.  Sensible "sharing" of the pin can occur
if attempts are perfectly nested.  It is efficient to
simultaneously query the pin state of an object in
conjunction with its strong reference count.

This combination of traits makes pinning suitable for
use in tracking whether a data structure backed by
an object is undergoing a non-structural modification:

- A structural change would require unique ownership
  of the object, but two non-structural changes (to
  different parts of the object) can occur at once
  without harm.  So a non-structural change can check
  for either uniqueness or a pin and then, if necessary,
  assert the pin for the duration of the change.
  Meanwhile, this act of asserting the pin prevents
  simultaneous structural changes.

- A very simple code-generation discipline leads to
  changes being perfectly nested as long as they're
  all performed by a single thread (or synchronously).
  Asynchrony can introduce imperfect nesting, but it's
  easy to write that off as a race condition and hence
  undefined behavior.

See Accessors.rst for more on both of these points.

Swift SVN r23761
2014-12-06 09:46:01 +00:00
John McCall
147fb8790a Comment some of the isUniquelyReferenced entrypoints
and remove _swift_isUniquelyReferenced_native_spareBits,
which was killed in favor of BridgeObject.

Swift SVN r23760
2014-12-06 09:45:59 +00:00
Joe Groff
ee5adc1f6e Runtime: Provide reflection for metatypes.
Metatypes have no user-visible structure, but can at least summarize as their type names. This gives us reasonable ad-hoc Printable behavior (thought debugPrint is still wrong, since a type name isn't parsable without being .self'ed).

Swift SVN r23745
2014-12-05 22:58:44 +00:00
Joe Groff
1cf1b4172b Runtime: Use full demangled names when reflecting values.
Use the recursive demangled name generation I implemented in _typeName for metatypes in _stdlib_getDemangledType as well, so that we get fully-qualified generic names and other goodness.

Swift SVN r23743
2014-12-05 21:25:50 +00:00
Nadav Rotem
2321849cff Replace the use of llvm::hash in getGenericMetadata with a fast hash implementation.
Before the change we were spending ~35% of the time of getGenericMetadata in hashing the inputs. I measured the following speedups:

SwiftStructuresQueue  1.11x
Havlak                1.11x
CaptureProp           1.11x
SwiftStructuresStack  1.12x
Life                  1.15x
NestedLoop            1.16x
RangeAssignment       1.24x

Swift SVN r23708
2014-12-05 00:45:48 +00:00
Dmitri Hrybenko
e588ec4906 Fixup for r23613 to allow the runtime to build on non-ObjC platforms
Swift SVN r23637
2014-12-03 03:39:04 +00:00
Joe Groff
58945f3186 Reflection: Drill through artificial subclasses.
Fixes a crash when KVO-observed objects were reflect()ed, and the magic mirror tried to peep the artificial subclass's nonexistent nominal type descriptor. rdar://problem/19060227

Swift SVN r23628
2014-12-03 02:00:01 +00:00
Joe Groff
e665574c13 Runtime: Use size-specific value witnesses for common POD sizes.
We already have these lying around for the Builtin.Int* types, so let's use them.

Swift SVN r23618
2014-12-02 18:25:21 +00:00
Joe Groff
27f49cd19d Runtime: Optional-like enums with single-refcounted payloads can share the refcounted value witnesses.
swift_retain and objc_retain both handle nil already, so we can bypass the generic Optional value witnesses when instantiating Optional on a class type, which happens kind of a lot.

Swift SVN r23613
2014-12-02 17:34:36 +00:00
Joe Groff
d752636387 Runtime: Drop in POD value witnesses when generic structs or enums are instantiated.
If, after layout, we recognize that a generic struct or enum instance is POD, we can replace the generic value witnesses in the image with POD ones.

Swift SVN r23609
2014-12-02 03:33:40 +00:00
David Farler
3c4428dd78 Emit unique metadata for functions with inout
References to functions that take inout parameters crash the compiler
because InOutType isn't a "real" type in itself and has no special type
metadata to emit. It merely further qualifies the function's input
types.

For example, we would like to have a unique entry in the cache for:

var f: (T, T) -> ()

and

var f2: (inout T, T) -> ()

For each argument type metadata pointer in the function's input, take
advantage of pointer alignment and mark the lowest bit if it is inout.
Since the metadata cache uses pointers to create the key, this creates a
unique entry while still being able to extract the actual pointer.

This fixes <rdar://problem/17655125>, and a couple of other similar
crashes.

Swift SVN r23557
2014-11-22 22:01:23 +00:00
Joe Groff
b60a30c84b stdlib: Make isUniquelyReferenced shims properly return bool.
rdar://problem/18573806 is fixed.

Swift SVN r23547
2014-11-22 05:36:38 +00:00
Dmitri Hrybenko
441a84a68d Native runtime: no need to account for ObjC pointers in uniqueness
checking

Addresses review comment by Dave Abrahams.

Swift SVN r23520
2014-11-21 18:28:28 +00:00
Graham Batty
17b1721f8f Implement ELF protocol conformance loading.
This works by loading the protocols from a specially named symbol,
which is generated by the linker through the help of a linker script
that merges all of the protocol conformance blocks into one section
with its size at the start of it and points a global symbol at
the section.

We do all this because unlike MachO, section information does not
survive to be loaded into memory with ELF binaries. Instead,
the mappings that survive are 'segments', which contain one or
more sections. Information about how these relate to their original
sections is difficult, if not impossible, to obtain at runtime.

Swift SVN r23518
2014-11-21 17:09:48 +00:00
Graham Batty
c61e40bbb8 Revert "Implement ELF protocol conformance loading."
This reverts commit r23475 at dgribenko's request.

Swift SVN r23487
2014-11-20 21:31:46 +00:00
Graham Batty
4e479f548c non-objc: Guard use of isNonNative_unTagged_bridgeObject.
Swift SVN r23477
2014-11-20 18:23:31 +00:00
Graham Batty
738a1b4ba0 Implement ELF protocol conformance loading.
This works by loading the protocols from a specially named symbol,
which is generated by the linker through the help of a linker script
that merges all of the protocol conformance blocks into one section
with its size at the start of it and points a global symbol at
the section.

We do all this because unlike MachO, section information does not
survive to be loaded into memory with ELF binaries. Instead,
the mappings that survive are 'segments', which contain one or
more sections. Information about how these relate to their original
sections is difficult, if not impossible, to obtain at runtime.

Swift SVN r23475
2014-11-20 17:40:05 +00:00
Dave Abrahams
c6711afd77 [runtime] Fix BridgeObject refCounting/masking
Previously we weren't accounting for the fact that
heap_object_abi::SwiftSpareBitsMask includes all the tagged pointer
demarcation bits in heap_object_abi::ObjCReservedBitsMask.

Swift SVN r23459
2014-11-20 00:44:32 +00:00
Nadav Rotem
8ce6af50ea Make the node of the concurrent map a ConcurrentList.
Making the type of nodes in the concurrent map a concurrent list will get rid
of the problem of the map itself allocating the node type, which may have a
side effect.

Swift SVN r23443
2014-11-19 19:21:10 +00:00
Nadav Rotem
ed26eb05a1 Use the typedef to make the code more readable. NFC.
Swift SVN r23442
2014-11-19 19:21:05 +00:00
Nadav Rotem
34fbb4f846 Cache map lookups
When we search for metadata we usually search for the same value over and
over again. Instead of searching the value in the binary tree we can save
the value that we found and use it again the next time we search. This
commit adds a cache value. The invariant is that the LastSearch variable
always points to a valid node and the access to the pointer itself is atomic.
This is a major performance win for the current use of getGenericMetadata.

Swift SVN r23434
2014-11-19 08:22:43 +00:00
Nadav Rotem
db4a9ce093 Refactor the hash code into the EntryRef class.
Swift SVN r23433
2014-11-19 08:22:41 +00:00
Dave Abrahams
68fbea2988 BridgeObject: native object with no spare bits set
Naturally, the fast path for things like Array<Int> has to be that no
masking is required to get at the buffer.  Therefore, the state with no
spare bits set needs to be reserved for native objects.  After the
change, an ObjC non-tagged pointer is stored with all spare bits set, and
native objects are stored with 0..<N bits set, where N is the number of
spare bits.  ObjC tagged pointers are still stored verbatim.

Swift SVN r23430
2014-11-19 06:07:19 +00:00
Nadav Rotem
08ff6ed547 Move the less frequently used field to the end of the struct.
This saves one add instruction in the fast path (for calculating the address of .Left).

Swift SVN r23420
2014-11-19 01:42:50 +00:00
Nadav Rotem
02c3aeb717 Split the lookup node lookup cold path from the hot path.
In debug builds getGenericMetadata takes about 10% of the execution time.
Most of this time is spent in searching the binary tree. This commit splits
the search into cold path and hot path, where the less likely checks are
done after the mode likely checks. This reduces the overall runtime of the
test suite in -Onone by ~1%.

Swift SVN r23419
2014-11-19 01:42:37 +00:00
Nadav Rotem
6199b409c5 Use load-acquire store-release for the node pointers in the tree.
Swift SVN r23413
2014-11-18 21:44:17 +00:00
Nadav Rotem
ecd58818ba Use load-acquire store-release for the first element in the linked list.
The use of seq_cst order for all operations is an overkill.

Swift SVN r23412
2014-11-18 21:44:15 +00:00
Nadav Rotem
20f75c7f67 Remove the push_front return value.
Swift SVN r23410
2014-11-18 20:43:19 +00:00