Smarter process abandoned foreign references. (#3568)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ inline bool isValidRuntime() {
|
||||
return ::runtimeState != kInvalidRuntime;
|
||||
}
|
||||
|
||||
int aliveRuntimesCount = 0;
|
||||
volatile int aliveRuntimesCount = 0;
|
||||
|
||||
RuntimeState* initRuntime() {
|
||||
SetKonanTerminateHandler();
|
||||
|
||||
Reference in New Issue
Block a user