Extract FreezeHooks and make them testable (#4654)

This commit is contained in:
Alexander Shabalin
2021-01-29 10:51:13 +03:00
committed by Vasily Levchenko
parent e2280ce855
commit d84c83d7da
13 changed files with 189 additions and 9 deletions
@@ -0,0 +1,42 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
#include "FreezeHooks.hpp"
#include "Memory.h"
#include "Types.h"
#include "WorkerBoundReference.h"
using namespace kotlin;
namespace {
void (*g_hookOverrideForTesting)(ObjHeader*) = nullptr;
NO_INLINE void RunFreezeHooksImpl(ObjHeader* object, const TypeInfo* type) noexcept {
if (g_hookOverrideForTesting != nullptr) {
g_hookOverrideForTesting(object);
return;
}
// TODO: Consider some global registration.
if (type == theWorkerBoundReferenceTypeInfo) {
WorkerBoundReferenceFreezeHook(object);
}
}
} // namespace
void kotlin::RunFreezeHooks(ObjHeader* object) noexcept {
auto* type = object->type_info();
if ((type->flags_ & TF_HAS_FREEZE_HOOK) == 0) {
return;
}
// This is a cold path.
RunFreezeHooksImpl(object, type);
}
void kotlin::SetFreezeHookForTesting(void (*hook)(ObjHeader*)) noexcept {
g_hookOverrideForTesting = hook;
}