@@ -421,20 +421,6 @@ namespace {
421
421
422
422
class DefaultActorImpl ;
423
423
424
- // / A job to process a default actor. Allocated inline in the actor.
425
- class ProcessInlineJob : public Job {
426
- public:
427
- ProcessInlineJob (JobPriority priority)
428
- : Job({JobKind::DefaultActorInline, priority}, &process) {}
429
-
430
- SWIFT_CC (swiftasync)
431
- static void process (Job *job);
432
-
433
- static bool classof (const Job *job) {
434
- return job->Flags .getKind () == JobKind::DefaultActorInline;
435
- }
436
- };
437
-
438
424
// / A job to process a default actor that's allocated separately from
439
425
// / the actor.
440
426
class ProcessOutOfLineJob : public Job {
@@ -452,25 +438,6 @@ class ProcessOutOfLineJob : public Job {
452
438
}
453
439
};
454
440
455
- // / Information about the currently-running processing job.
456
- struct RunningJobInfo {
457
- enum KindType : uint8_t {
458
- Inline, Other
459
- };
460
- KindType Kind;
461
-
462
- bool wasInlineJob () const {
463
- return Kind == Inline;
464
- }
465
-
466
- static RunningJobInfo forOther () {
467
- return {Other};
468
- }
469
- static RunningJobInfo forInline () {
470
- return {Inline};
471
- }
472
- };
473
-
474
441
class JobRef {
475
442
enum : uintptr_t {
476
443
NeedsPreprocessing = 0x1 ,
@@ -531,12 +498,6 @@ class JobRef {
531
498
}
532
499
};
533
500
534
- // / TODO (rokhinip): The layout of the ActiveActorStatus seems to be broken in
535
- // / arm64_32 with priority escalation support, disable this for now.
536
- #if SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION && SWIFT_POINTER_IS_4_BYTES
537
- #define SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION 0
538
- #endif
539
-
540
501
// / Similar to the ActiveTaskStatus, this denotes the ActiveActorState for
541
502
// / tracking the atomic state of the actor
542
503
// /
@@ -903,24 +864,15 @@ static_assert(sizeof(ActiveActorStatus) == ACTIVE_ACTOR_STATUS_SIZE,
903
864
// / We must either release the actor or create a new processing job
904
865
// / for it to maintain the balance.
905
866
// /
906
- // / The current behaviour of actors is such that we only use the inline
907
- // / processing job to schedule the actor and not OOL jobs. As a result, the
908
- // / subset of rules that currently apply are (1), (3), (5), (6).
867
+ // / The current behaviour of actors is such that we only have a single
868
+ // / processing job for an actor at a given time. Stealers jobs support does not
869
+ // / exist yet. As a result, the subset of rules that currently apply
870
+ // / are (1), (3), (5), (6).
909
871
class DefaultActorImpl : public HeapObject {
910
- friend class ProcessInlineJob ;
911
- union {
912
- // When the ProcessInlineJob storage is initialized, its metadata pointer
913
- // will point to Job's metadata. When it isn't, the metadata pointer is
914
- // NULL. Use HeapObject to initialize the metadata pointer to NULL and allow
915
- // it to be checked without fully initializing the ProcessInlineJob.
916
- HeapObject JobStorageHeapObject{nullptr };
917
-
918
- ProcessInlineJob JobStorage;
919
- };
920
- // This field needs to be aligned to ACTIVE_ACTOR_STATUS but we need to
921
- // hide this from the compiler cause otherwise it adds a bunch of extra
922
- // padding to the structure. We will enforce this via static asserts.
923
- char StatusStorage[sizeof (ActiveActorStatus)];
872
+ // Note: There is some padding that is added here by the compiler in order to
873
+ // enforce alignment. This is space that is available for us to use in
874
+ // the future
875
+ alignas (sizeof (ActiveActorStatus)) char StatusStorage[sizeof (ActiveActorStatus)];
924
876
925
877
public:
926
878
// / Properly construct an actor, except for the heap header.
@@ -932,7 +884,6 @@ class DefaultActorImpl : public HeapObject {
932
884
_status ().store (status, std::memory_order_relaxed);
933
885
934
886
SWIFT_TASK_DEBUG_LOG (" Creating default actor %p" , this );
935
- JobStorageHeapObject.metadata = nullptr ;
936
887
concurrency::trace::actor_create (this );
937
888
}
938
889
@@ -986,26 +937,20 @@ class DefaultActorImpl : public HeapObject {
986
937
987
938
void deallocateUnconditional ();
988
939
989
- // / Schedule an inline processing job. This can generally only be
940
+ // / Schedule a processing job. This can generally only be
990
941
// / done if we know nobody else is trying to do it at the same time,
991
942
// / e.g. if this thread just sucessfully transitioned the actor from
992
943
// / Idle to Scheduled.
993
- void scheduleActorProcessJob (JobPriority priority,
994
- bool hasActiveInlineJob);
995
-
996
- static DefaultActorImpl *fromInlineJob (Job *job) {
997
- assert (isa<ProcessInlineJob>(job));
998
- #pragma clang diagnostic push
999
- #pragma clang diagnostic ignored "-Winvalid-offsetof"
1000
- return reinterpret_cast <DefaultActorImpl*>(
1001
- reinterpret_cast <char *>(job) - offsetof (DefaultActorImpl, JobStorage));
1002
- #pragma clang diagnostic pop
1003
- }
944
+ void scheduleActorProcessJob (JobPriority priority);
1004
945
};
1005
946
1006
947
} // / end anonymous namespace
1007
948
1008
- static_assert (sizeof (DefaultActorImpl) <= sizeof(DefaultActor) &&
949
+ // We can't use sizeof(DefaultActor) since the alignment requirement on the
950
+ // default actor means that we have some padding added when calculating
951
+ // sizeof(DefaultActor). However that padding isn't available for us to use
952
+ // in DefaultActorImpl.
953
+ static_assert (sizeof (DefaultActorImpl) <= ((sizeof (void *) * NumWords_DefaultActor) + sizeof(HeapObject)) &&
1009
954
alignof(DefaultActorImpl) <= alignof(DefaultActor),
1010
955
"DefaultActorImpl doesn't fit in DefaultActor");
1011
956
static_assert (DefaultActorImpl::offsetOfActiveActorStatus() % ACTIVE_ACTOR_STATUS_SIZE == 0,
@@ -1205,32 +1150,19 @@ dispatch_lock_t *DefaultActorImpl::drainLockAddr() {
1205
1150
void DefaultActorImpl::deallocateUnconditional () {
1206
1151
concurrency::trace::actor_deallocate (this );
1207
1152
1208
- if (JobStorageHeapObject.metadata != nullptr )
1209
- JobStorage.~ProcessInlineJob ();
1210
1153
auto metadata = cast<ClassMetadata>(this ->metadata );
1211
1154
swift_deallocClassInstance (this , metadata->getInstanceSize (),
1212
1155
metadata->getInstanceAlignMask ());
1213
1156
}
1214
1157
1215
- void DefaultActorImpl::scheduleActorProcessJob (JobPriority priority, bool useInlineJob) {
1216
- Job *job;
1217
- if (useInlineJob) {
1218
- if (JobStorageHeapObject.metadata != nullptr )
1219
- JobStorage.~ProcessInlineJob ();
1220
- job = new (&JobStorage) ProcessInlineJob (priority);
1221
- } else {
1222
- assert (false && " Should not be here - we don't have support for any OOL actor process jobs yet" );
1223
- // TODO (rokhinip): Don't we need to take a +1 per ref count rules specified?
1224
- swift_retain (this );
1225
- job = new ProcessOutOfLineJob (this , priority);
1226
- }
1158
+ void DefaultActorImpl::scheduleActorProcessJob (JobPriority priority) {
1159
+ Job *job = new ProcessOutOfLineJob (this , priority);
1227
1160
SWIFT_TASK_DEBUG_LOG (
1228
1161
" Scheduling processing job %p for actor %p at priority %#zx" , job, this ,
1229
1162
priority);
1230
1163
swift_task_enqueueGlobal (job);
1231
1164
}
1232
1165
1233
-
1234
1166
bool DefaultActorImpl::tryLock (bool asDrainer) {
1235
1167
#if SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION
1236
1168
SWIFT_TASK_DEBUG_LOG (" Thread %#x attempting to jump onto %p, as drainer = %d" , dispatch_lock_value_for_self (), this , asDrainer);
@@ -1326,7 +1258,7 @@ void DefaultActorImpl::enqueue(Job *job, JobPriority priority) {
1326
1258
if (!oldState.isScheduled () && newState.isScheduled ()) {
1327
1259
// We took responsibility to schedule the actor for the first time. See
1328
1260
// also ownership rule (1)
1329
- return scheduleActorProcessJob (newState.getMaxPriority (), true );
1261
+ return scheduleActorProcessJob (newState.getMaxPriority ());
1330
1262
}
1331
1263
1332
1264
#if SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION
@@ -1412,7 +1344,7 @@ bool DefaultActorImpl::unlock(bool forceUnlock)
1412
1344
if (newState.isScheduled ()) {
1413
1345
// See ownership rule (6) in DefaultActorImpl
1414
1346
assert (newState.getFirstJob ());
1415
- scheduleActorProcessJob (newState.getMaxPriority (), true );
1347
+ scheduleActorProcessJob (newState.getMaxPriority ());
1416
1348
} else {
1417
1349
// See ownership rule (5) in DefaultActorImpl
1418
1350
SWIFT_TASK_DEBUG_LOG (" Actor %p is idle now" , this );
@@ -1557,7 +1489,7 @@ static void defaultActorDrain(DefaultActorImpl *actor) {
1557
1489
// Leave the tracking info.
1558
1490
trackingInfo.leave ();
1559
1491
1560
- // Balances with the retain taken in Process{Inline,OutOfLine}Job ::process
1492
+ // Balances with the retain taken in ProcessOutOfLineJob ::process
1561
1493
swift_release (actor);
1562
1494
}
1563
1495
@@ -1589,14 +1521,6 @@ static void swift_job_runImpl(Job *job, ExecutorRef executor) {
1589
1521
}
1590
1522
}
1591
1523
1592
- SWIFT_CC (swiftasync)
1593
- void ProcessInlineJob::process(Job *job) {
1594
- DefaultActorImpl *actor = DefaultActorImpl::fromInlineJob (job);
1595
-
1596
- swift_retain (actor);
1597
- return defaultActorDrain (actor); // 'return' forces tail call
1598
- }
1599
-
1600
1524
// Currently unused
1601
1525
SWIFT_CC (swiftasync)
1602
1526
void ProcessOutOfLineJob::process(Job *job) {
@@ -1605,6 +1529,7 @@ void ProcessOutOfLineJob::process(Job *job) {
1605
1529
1606
1530
delete self;
1607
1531
1532
+ // Balances with the swift_release in defaultActorDrain()
1608
1533
swift_retain (actor);
1609
1534
return defaultActorDrain (actor); // 'return' forces tail call
1610
1535
}
0 commit comments