Skip to content

Commit 4cc1035

Browse files
authored
Merge pull request #37919 from mikeash/reserve-more-job-storage
[Concurrency] Reserve two more words in Job.
2 parents 5847452 + c2df244 commit 4cc1035

File tree

7 files changed

+26
-16
lines changed

7 files changed

+26
-16
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ enum {
4545

4646
/// The number of words (in addition to the heap-object header)
4747
/// in a default actor.
48-
NumWords_DefaultActor = 10,
48+
NumWords_DefaultActor = 12,
4949

5050
/// The number of words in a task.
5151
NumWords_AsyncTask = 16,

include/swift/ABI/Task.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class alignas(2 * alignof(void*)) Job :
7171
// Derived classes can use this to store a Job Id.
7272
uint32_t Id = 0;
7373

74+
void *Reserved[2] = {};
75+
7476
// We use this union to avoid having to do a second indirect branch
7577
// when resuming an asynchronous task, which we expect will be the
7678
// common case.
@@ -127,10 +129,10 @@ class alignas(2 * alignof(void*)) Job :
127129

128130
// The compiler will eventually assume these.
129131
#if SWIFT_POINTER_IS_8_BYTES
130-
static_assert(sizeof(Job) == 6 * sizeof(void*),
132+
static_assert(sizeof(Job) == 8 * sizeof(void*),
131133
"Job size is wrong");
132134
#else
133-
static_assert(sizeof(Job) == 8 * sizeof(void*),
135+
static_assert(sizeof(Job) == 10 * sizeof(void*),
134136
"Job size is wrong");
135137
#endif
136138
static_assert(alignof(Job) == 2 * alignof(void*),
@@ -200,7 +202,7 @@ class AsyncTask : public Job {
200202

201203
/// Private storage for the use of the runtime.
202204
struct alignas(2 * alignof(void*)) OpaquePrivateStorage {
203-
void *Storage[8];
205+
void *Storage[6];
204206

205207
/// Initialize this storage during the creation of a task.
206208
void initialize(AsyncTask *task);

lib/IRGen/IRGenFunction.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,15 @@ static llvm::Value *unsafeContinuationFromTask(IRGenFunction &IGF,
526526

527527
static llvm::Value *emitLoadOfResumeContextFromTask(IRGenFunction &IGF,
528528
llvm::Value *task) {
529+
// Task.ResumeContext is at field index 8 within SwiftTaskTy. The offset comes
530+
// from 7 pointers (two within the single RefCountedStructTy) and 2 Int32
531+
// fields.
532+
const unsigned taskResumeContextIndex = 8;
533+
const Size taskResumeContextOffset = (7 * IGF.IGM.getPointerSize()) + Size(8);
534+
529535
auto addr = Address(task, IGF.IGM.getPointerAlignment());
530536
auto resumeContextAddr = IGF.Builder.CreateStructGEP(
531-
addr, 6, (5 * IGF.IGM.getPointerSize()) + Size(8));
537+
addr, taskResumeContextIndex, taskResumeContextOffset);
532538
llvm::Value *resumeContext = IGF.Builder.CreateLoad(resumeContextAddr);
533539
if (auto &schema = IGF.getOptions().PointerAuth.TaskResumeContext) {
534540
auto info = PointerAuthInfo::emit(IGF, schema,

lib/IRGen/IRGenModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
612612
Int8PtrTy, Int8PtrTy, // Job.SchedulerPrivate
613613
Int32Ty, // Job.Flags
614614
Int32Ty, // Job.ID
615+
Int8PtrTy, Int8PtrTy, // Reserved
615616
FunctionPtrTy, // Job.RunJob/Job.ResumeTask
616617
SwiftContextPtrTy, // Task.ResumeContext
617618
IntPtrTy // Task.Status
@@ -632,6 +633,7 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
632633
Int8PtrTy, Int8PtrTy, // SchedulerPrivate
633634
Int32Ty, // flags
634635
Int32Ty, // ID
636+
Int8PtrTy, Int8PtrTy, // Reserved
635637
FunctionPtrTy, // RunJob/ResumeTask
636638
});
637639
SwiftJobPtrTy = SwiftJobTy->getPointerTo(DefaultAS);

test/IRGen/actor_class.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
// CHECK: %T11actor_class7MyClassC = type <{ %swift.refcounted, %swift.defaultactor, %TSi }>
6-
// CHECK: %swift.defaultactor = type { [10 x i8*] }
6+
// CHECK: %swift.defaultactor = type { [12 x i8*] }
77

88
// CHECK-objc-LABEL: @"$s11actor_class7MyClassCMm" = global
99
// CHECK-objc-SAME: @"OBJC_METACLASS_$__TtCs12_SwiftObject{{(.ptrauth)?}}"
@@ -15,13 +15,13 @@
1515
// Flags: uses Swift refcounting
1616
// CHECK-SAME: i32 2,
1717
// Instance size
18-
// CHECK-64-SAME: i32 104,
19-
// CHECK-32-SAME: i32 52,
18+
// CHECK-64-SAME: i32 120,
19+
// CHECK-32-SAME: i32 60,
2020
// Alignment mask
2121
// CHECK-64-SAME: i16 15,
2222
// CHECK-32-SAME: i16 7,
2323
// Field offset for 'x'
24-
// CHECK-objc-SAME: [[INT]] {{48|96}},
24+
// CHECK-objc-SAME: [[INT]] {{56|112}},
2525

2626
// Type descriptor.
2727
// CHECK-LABEL: @"$s11actor_class9ExchangerCMn" = {{.*}}constant

test/IRGen/actor_class_objc.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import Foundation
66

77
// CHECK: %T16actor_class_objc7MyClassC = type <{ %swift.refcounted, %swift.defaultactor, %TSi }>
8-
// CHECK: %swift.defaultactor = type { [10 x i8*] }
8+
// CHECK: %swift.defaultactor = type { [12 x i8*] }
99

1010
// CHECK-LABEL: @"OBJC_METACLASS_$__TtC16actor_class_objc7MyClass" = global
1111
// Metaclass is an instance of the root class.
@@ -20,14 +20,14 @@ import Foundation
2020
// Flags: uses Swift refcounting
2121
// CHECK-SAME: i32 2,
2222
// Instance size
23-
// CHECK-64-SAME: i32 104,
24-
// CHECK-32-SAME: i32 52,
23+
// CHECK-64-SAME: i32 120,
24+
// CHECK-32-SAME: i32 60,
2525
// Alignment mask
2626
// CHECK-64-SAME: i16 15,
2727
// CHECK-32-SAME: i16 7,
2828
// Field offset for 'x'
29-
// CHECK-64-SAME: i64 96,
30-
// CHECK-32-SAME: i32 48,
29+
// CHECK-64-SAME: i64 112,
30+
// CHECK-32-SAME: i32 56,
3131

3232
public actor MyClass: NSObject {
3333
public var x: Int

test/IRGen/async/builtins.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ bb0(%0 : $Int, %1: @guaranteed $@async @callee_owned @substituted <τ_0_0> () ->
6363
sil hidden [ossa] @resume_nonthrowing_continuation : $(@in Builtin.NativeObject, Builtin.RawUnsafeContinuation) -> () {
6464
bb0(%0 : $*Builtin.NativeObject, %1 : $Builtin.RawUnsafeContinuation):
6565
// CHECK: [[CONT:%.*]] = bitcast i8* %1 to %swift.task*
66-
// CHECK-NEXT: [[CONTEXT_SLOT:%.*]] = getelementptr inbounds %swift.task, %swift.task* [[CONT]], i32 0, i32 6
66+
// CHECK-NEXT: [[CONTEXT_SLOT:%.*]] = getelementptr inbounds %swift.task, %swift.task* [[CONT]], i32 0, i32 8
6767
// CHECK-NEXT: [[CONTEXT_OPAQUE:%.*]] = load %swift.context*, %swift.context** [[CONTEXT_SLOT]], align
6868
// CHECK-NEXT: [[CONTEXT:%.*]] = bitcast %swift.context* [[CONTEXT_OPAQUE]] to %swift.continuation_context*
6969
// CHECK-NEXT: [[RESULT_ADDR_SLOT:%.*]] = getelementptr inbounds %swift.continuation_context, %swift.continuation_context* [[CONTEXT]], i32 0, i32 3
@@ -82,7 +82,7 @@ bb0(%0 : $*Builtin.NativeObject, %1 : $Builtin.RawUnsafeContinuation):
8282
sil hidden [ossa] @resume_throwing_continuation : $(@in Builtin.NativeObject, Builtin.RawUnsafeContinuation) -> () {
8383
bb0(%0 : $*Builtin.NativeObject, %1 : $Builtin.RawUnsafeContinuation):
8484
// CHECK: [[CONT:%.*]] = bitcast i8* %1 to %swift.task*
85-
// CHECK-NEXT: [[CONTEXT_SLOT:%.*]] = getelementptr inbounds %swift.task, %swift.task* [[CONT]], i32 0, i32 6
85+
// CHECK-NEXT: [[CONTEXT_SLOT:%.*]] = getelementptr inbounds %swift.task, %swift.task* [[CONT]], i32 0, i32 8
8686
// CHECK-NEXT: [[CONTEXT_OPAQUE:%.*]] = load %swift.context*, %swift.context** [[CONTEXT_SLOT]], align
8787
// CHECK-NEXT: [[CONTEXT:%.*]] = bitcast %swift.context* [[CONTEXT_OPAQUE]] to %swift.continuation_context*
8888
// CHECK-NEXT: [[RESULT_ADDR_SLOT:%.*]] = getelementptr inbounds %swift.continuation_context, %swift.continuation_context* [[CONTEXT]], i32 0, i32 3

0 commit comments

Comments
 (0)