Smarter process abandoned foreign references. (#3568)

This commit is contained in:
Nikolay Igotti
2019-11-15 16:50:57 +03:00
committed by GitHub
parent d4028ad13a
commit bcfd837363
2 changed files with 11 additions and 10 deletions
+10 -9
View File
@@ -375,22 +375,23 @@ private:
void processAbandoned() {
if (this->releaseList != nullptr) {
bool hadNoRuntimeInitialized = (memoryState == nullptr);
bool hadNoStateInitialized = (memoryState == nullptr);
if (hadNoRuntimeInitialized) {
Kotlin_initRuntimeIfNeeded(); // Required by ReleaseHeapRef.
if (hadNoStateInitialized) {
// Disregard request if all runtimes are no longer alive.
if (atomicGet(&aliveMemoryStatesCount) == 0)
return;
memoryState = InitMemory(); // Required by ReleaseHeapRef.
}
processEnqueuedReleaseRefsWith([](ObjHeader* obj) {
ReleaseHeapRef(obj);
});
if (hadNoRuntimeInitialized) {
// This thread is likely not intended to run Kotlin code.
// In this case it has no chances to process the release-refs enqueued above using
// the general heuristics, so do this manually:
garbageCollect();
// TODO: how to handle subsequent processAbandoned() calls?
if (hadNoStateInitialized) {
// Discard the memory state.
DeinitMemory(memoryState);
}
}
}
+1 -1
View File
@@ -83,7 +83,7 @@ inline bool isValidRuntime() {
return ::runtimeState != kInvalidRuntime;
}
int aliveRuntimesCount = 0;
volatile int aliveRuntimesCount = 0;
RuntimeState* initRuntime() {
SetKonanTerminateHandler();