Tweak TLS init/deinit (#4551)

* Delete the entire TLS in one go
* Put TLS allocation separately
* Keep TLS in a single array
This commit is contained in:
Alexander Shabalin
2020-11-26 11:25:25 +03:00
committed by Stanislav Erokhin
parent 0e12c55770
commit 5fc17ce5fa
7 changed files with 101 additions and 70 deletions
@@ -35,7 +35,6 @@ void EnsureDeclarationsEmitted() {
ensureUsed(EnterFrame);
ensureUsed(LeaveFrame);
ensureUsed(AddTLSRecord);
ensureUsed(ClearTLSRecord);
ensureUsed(LookupTLS);
ensureUsed(MutationCheck);
ensureUsed(CheckLifetimesConstraint);
+4 -2
View File
@@ -225,8 +225,10 @@ void FreezeSubgraph(ObjHeader* obj);
void EnsureNeverFrozen(ObjHeader* obj);
// Add TLS object storage, called by the generated code.
void AddTLSRecord(MemoryState* memory, void** key, int size) RUNTIME_NOTHROW;
// Clear TLS object storage, called by the generated code.
void ClearTLSRecord(MemoryState* memory, void** key) RUNTIME_NOTHROW;
// Allocate storage for TLS. `AddTLSRecord` cannot be called after this.
void CommitTLSStorage(MemoryState* memory) RUNTIME_NOTHROW;
// Clear TLS object storage.
void ClearTLS(MemoryState* memory) RUNTIME_NOTHROW;
// Lookup element in TLS object storage.
ObjHeader** LookupTLS(void** key, int index) RUNTIME_NOTHROW;
@@ -55,10 +55,11 @@ struct RuntimeState {
RuntimeStatus status = RuntimeStatus::kUninitialized;
};
// Must be synchronized with IrToBitcode.kt
enum {
INIT_GLOBALS = 0,
INIT_THREAD_LOCAL_GLOBALS = 1,
DEINIT_THREAD_LOCAL_GLOBALS = 2,
ALLOC_THREAD_LOCAL_GLOBALS = 0,
INIT_GLOBALS = 1,
INIT_THREAD_LOCAL_GLOBALS = 2,
DEINIT_GLOBALS = 3
};
@@ -120,6 +121,8 @@ RuntimeState* initRuntime() {
result->worker = WorkerInit(true);
}
InitOrDeinitGlobalVariables(ALLOC_THREAD_LOCAL_GLOBALS, result->memoryState);
CommitTLSStorage(result->memoryState);
// Keep global variables in state as well.
if (firstRuntime) {
konan::consoleInit();
@@ -148,7 +151,7 @@ void deinitRuntime(RuntimeState* state, bool destroyRuntime) {
// Nothing to do.
break;
}
InitOrDeinitGlobalVariables(DEINIT_THREAD_LOCAL_GLOBALS, state->memoryState);
ClearTLS(state->memoryState);
if (destroyRuntime)
InitOrDeinitGlobalVariables(DEINIT_GLOBALS, state->memoryState);
auto workerId = GetWorkerId(state->worker);