Commit Graph

409 Commits

Author SHA1 Message Date
Max Moiseev
02006f20bc Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-09 16:05:03 -08: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
Max Moiseev
1fae0d1325 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-08 12:48:48 -08:00
David Farler
759cd23a86 Use int32_t for external relative direct pointers 2016-03-07 17:43:13 -08:00
David Farler
6f0a399e5c Use offsetof to calculate offset to Descriptor offset 2016-03-07 17:43:12 -08:00
David Farler
ff75058188 Gardening: indentation 2016-03-07 17:43:12 -08:00
Max Moiseev
7fe6916bf6 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-07 12:10:47 -08:00
David Farler
bd6d657411 Get typerefs for existential type metadata 2016-03-04 17:10:40 -08:00
David Farler
5f169b466c Get typerefs for function type metadata 2016-03-04 17:10:40 -08:00
David Farler
04444c44a2 Get typerefs for tuple type metadata, including their elements 2016-03-04 17:10:40 -08:00
David Farler
5196f5b89c Get typerefs for nominal type metadata
and read their generic arguments, if there are any, too.
2016-03-04 17:10:39 -08:00
practicalswift
5b2800225d [gardening] Fix recently introduced typos
Fixed:
* perfomance → performance
* requirments → requirements
* satisified → satisfied
* template template → template
2016-03-04 11:10:50 +01:00
Max Moiseev
cf4bafe9e3 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-03 13:22:03 -08:00
David Farler
502c10fe12 Fix doc comment for GenericParameterDescriptor::Offset
This was a little confusing because it is actually the offset to
the first generic argument and this isn't well documented
anywhere else.
2016-03-03 11:52:31 -08:00
Slava Pestov
b3103ac7b7 Runtime: Fix alignment issue in default witness tables
The size of a protocol's metadata was not a multiple of 8 bytes, so
on 64-bit platforms, the runtime would copy default witnesses from
the wrong address, because IRGen metadata does not add alignment padding,
whereas the in-memory structure does.

Fix this by adding a 32-bit padding field at the end of the protocol
descriptor. Technically this is not necessary on 32-bit, but this keeps
things simpler for now.

The test case for this is a library evolution test exercising resilient
default protocol requirements, but it is not quite ready to go in yet.
2016-03-03 07:36:59 -08:00
David Farler
0ab31065ff Flesh out remote memory reader
Adds a rough sketch of what will be a test harness, currently only supported
on OS X:
- Launch a child process: an executable written in Swift
- Receive the child process's Mach port
- Receive reflection section addresses and the address of a heap instance
  of interest
- Perform field type lookup on the instance remotely (TODO)
2016-03-02 21:25:04 -08:00
David Farler
cd65a8e0b0 Template metadata structures
- Add RuntimeTarget template This will allow for converting between
  metadata structures for native host and remote target architectures.

- Create InProcess and External templates for stored pointers

Add a few more types to abstract pointer access in the runtime
structures but keep native in-process pointer access the same as that
with a plain old pointer type.

There is now a notion of a "stored pointer", which is just the raw value
of the pointer, and the actual pointer type, which is used for loads.
Decoupling these allows us to fork the behavior when looking at metadata
in an external process, but keep things the same for the in-process
case.

There are two basic "runtime targets" that you can use to work with
metadata:

InProcess: Defines the pointer to be trivially a T* and stored as a
uintptr_t. A Metadata * is exactly as it was before, but defined via
AbstractMetadata<InProcess>.

External: A template that requires a target to specify its pointer size.

ExternalPointer: An opaque pointer in another address space that can't
(and shouldn't) be indirected with operator* or operator->.  The memory
reader will fetch the data explicitly.
2016-03-02 21:25:04 -08:00
practicalswift
35dbeef034 [gardening] Fix recently introduced typos
* currnet → current
* accidental double space ("  ") → intentional single space (" ")
* recordinf → recording
2016-03-02 22:25:46 +01:00
Dmitri Gribenko
584deec8d0 Merge pull request #1507 from practicalswift/typo-fixes-20160302
[gardening] Fix recently introduced typos
2016-03-02 01:27:50 -08:00
practicalswift
da6f2f3a9e [gardening] Fix formatting of recently introduced file headers 2016-03-02 09:50:27 +01:00
practicalswift
fd829f76c8 [gardening] Fix recently introduced typo: "only only" → "only" 2016-03-02 09:34:03 +01:00
practicalswift
3a4968192b [gardening] Fix recently introduced typo: "enrty" → "entry" 2016-03-02 09:33:45 +01:00
swiftix
2573782c8b Merge pull request #1357 from swiftix/wip-runtime-calling-convention
Prepare the ground for using a new calling convention for functions from the runtime library
2016-03-01 16:22:37 -08:00
Max Moiseev
859db53d87 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-01 12:56:26 -08:00
Davide Italiano
59ed25c208 [FreeBSD] Include <stdio.h>, needed for printf(). 2016-02-29 19:40:22 +00:00
Max Moiseev
488b464f10 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-25 12:21:56 -08:00
John McCall
3ce1ba3e65 Only store the minimal requirements in generic metadata, where
"minimal" is defined as the set of requirements that would be
passed to a function with the type's generic signature that
takes the thick metadata of the parent type as its only argument.
2016-02-25 10:33:33 -08:00
Roman Levenstein
b3e60afcc7 Even if we use wrappers, runtime functions should be visible.
In principle, runtime entries could have a hidden visibility, because they are
never called directly from the code produced by IRGen.
But some of the runtime entries are invoked directly from the foundation.
Therefore they should be visible.
2016-02-25 08:51:19 -08:00
Roman Levenstein
dbf233318b swift_allocObject should be exposed as a visible runtime entry. 2016-02-25 08:46:57 -08:00
Roman Levenstein
2ff5755dc3 Use the "rt_" prefix for all generated wrappers to distinguish them from the actual runtime functions. 2016-02-25 06:00:30 -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
1d7cca9b07 Fix the failing Linux build.
Don't generate global function pointers if the platforms does not need to provide Obj-C interoperability.
2016-02-25 05:31:00 -08:00
Roman Levenstein
0964aecc7d Define functions using a new calling convention RuntimeCC1.
We annotate the most popular runtime functions in terms of how often they are invoked from Swift code:

- Many variants of retain/release functions are annotated to use the new calling convention.
  But those variants of retain/release functions that may result in calls of objc_retain or objc_release
  are not migrated to the new calling convention, because it results in significant performance degradations
  when objects of Obj-C derived classes are used.

- Some popular non-reference counting functions like swift_getGenericMetadata or swift_dynamicCast are annotated as well.
2016-02-25 05:31:00 -08:00
Roman Levenstein
1d0bfcf40e Define runtime functions which should be invoked via a global function pointer.
The list of these functions is pretty much the same as the the set of functions defined in InstrumentsSupport.h
These are basically the functions that can be intercepted by different tools/profilers/etc.
2016-02-25 05:31:00 -08:00
Roman Levenstein
94ab3e2a20 Define a new x-macro FUNCTION_WITH_GLOBAL_SYMBOL_AND_IMPL
This new x-macro should be used to define a runtime function that has an internal implementation
inside the runtime library and a global symbol referring to this internal implementation.

An example of such a runtime function is "swift_retain", which has a global symbol "_swift_retain"
referring to its internal implementation "_swift_retain_".
2016-02-25 05:30:59 -08:00
Roman Levenstein
634579aae2 Move RuntimeFunctions.def into a shared location.
RuntimeFunctions.def was used only by IRGen so far. But it is going to be used by the runtime library as well.
2016-02-25 05:30:59 -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
Roman Levenstein
fd9a22aca1 Prepare the configuration parameters needed for implementing a new runtime calling convention.
Define a number of macro definitions that will be used for:
- proper auto-generation of LLVM IR level declarations of runtime function using RuntimeFunctions.def
- generation of wrappers for runtime functions
- setting proper calling conventions, visibility and other attributes of runtime functions inside the runtime library.
2016-02-25 05:30:58 -08:00
Roman Levenstein
8f5e525d2d Add function to generate an llvm wrapper for performing a runtime function call.
The generated wrapper simply invokes a corresponding entry point by means of
an indirect call via a global the symbol, which is a function pointer referring
to the implementation of a runtime function.

Using such wrappers allows for invocations of runtime functions from dynamic
libraries without the usual indirections via dynamic linker stubs.

If the calling convention and the current target require a wrapper, it will be
generated. Each wrapper gets a hidden linkage and is marked as ODR, so that
a linker can merge all wrappers with the same name.
2016-02-25 05:30:58 -08:00
Roman Levenstein
420d6deda8 Make the functions generating LLVM IR declarations of runtime entry points available outside of IRGen.
This functionality could be re-used by e.g. LLVMPasses, which currently create LLVM IR declarations of runtime entry points on their own.

To make the function re-usable, slightly change the API of the function:
- use llvm::Module instead of IRGenModule.
- use llvm::ArrayRef instead of std::initializer_list, which allows the clients of this API to dynamically form the lists of return types and arguments.
2016-02-25 05:30:58 -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
Max Moiseev
0b759a409c Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-23 14:26:14 -08:00
Han Sangjin
e06c7136cb Porting to Cygwin. rebased and squashed 2016-02-22 13:20:21 +09:00
Dmitri Gribenko
0f36bec31f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-18 16:41:35 -08: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
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -08:00
Nadav Rotem
866b44cbae [Debug] Add add a method to dump dotty style graph.
Add add a method to dump the metadata caches as a dotty graph.
2016-02-09 23:14:27 -08:00
Joe Groff
32872cb74a IRGen/Runtime: Relative-reference the nominal type descriptor and parent type from metadata.
Save a couple relocations per concrete value type, leaving only the value witness table as an absolute symbol.
2016-02-09 15:17:03 -08:00
practicalswift
2e8190016d [gardening] Fix recently introduced typo: "collissions" → "collisions" 2016-02-09 22:46:29 +01:00