Move everything under kotlin-native folder

I was forced to manually do update the following files, because otherwise
they would be ignored according .gitignore settings. Probably they
should be deleted from repo.

Interop/.idea/compiler.xml
Interop/.idea/gradle.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml
Interop/.idea/modules.xml
Interop/.idea/modules/Indexer/Indexer.iml
Interop/.idea/modules/Runtime/Runtime.iml
Interop/.idea/modules/StubGenerator/StubGenerator.iml
backend.native/backend.native.iml
backend.native/bc.frontend/bc.frontend.iml
backend.native/cli.bc/cli.bc.iml
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt
backend.native/tests/link/lib/foo.kt
backend.native/tests/link/lib/foo2.kt
backend.native/tests/teamcity-test.property
This commit is contained in:
Stanislav Erokhin
2020-10-27 21:00:28 +03:00
parent 91e4162dad
commit f624800b84
2830 changed files with 0 additions and 0 deletions
@@ -0,0 +1,256 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "Alloc.h"
#include "Atomic.h"
#include "Cleaner.h"
#include "Exceptions.h"
#include "KAssert.h"
#include "Memory.h"
#include "ObjCExportInit.h"
#include "Porting.h"
#include "Runtime.h"
#include "Worker.h"
typedef void (*Initializer)(int initialize, MemoryState* memory);
struct InitNode {
Initializer init;
InitNode* next;
};
namespace {
InitNode* initHeadNode = nullptr;
InitNode* initTailNode = nullptr;
enum class RuntimeStatus {
kUninitialized,
kRunning,
kDestroying,
};
struct RuntimeState {
MemoryState* memoryState;
Worker* worker;
RuntimeStatus status = RuntimeStatus::kUninitialized;
};
enum {
INIT_GLOBALS = 0,
INIT_THREAD_LOCAL_GLOBALS = 1,
DEINIT_THREAD_LOCAL_GLOBALS = 2,
DEINIT_GLOBALS = 3
};
void InitOrDeinitGlobalVariables(int initialize, MemoryState* memory) {
InitNode* currentNode = initHeadNode;
while (currentNode != nullptr) {
currentNode->init(initialize, memory);
currentNode = currentNode->next;
}
}
KBoolean g_checkLeaks = KonanNeedDebugInfo;
KBoolean g_checkLeakedCleaners = KonanNeedDebugInfo;
constexpr RuntimeState* kInvalidRuntime = nullptr;
THREAD_LOCAL_VARIABLE RuntimeState* runtimeState = kInvalidRuntime;
THREAD_LOCAL_VARIABLE int isMainThread = 0;
inline bool isValidRuntime() {
return ::runtimeState != kInvalidRuntime;
}
volatile int aliveRuntimesCount = 0;
RuntimeState* initRuntime() {
SetKonanTerminateHandler();
RuntimeState* result = konanConstructInstance<RuntimeState>();
if (!result) return kInvalidRuntime;
RuntimeCheck(!isValidRuntime(), "No active runtimes allowed");
::runtimeState = result;
result->memoryState = InitMemory();
result->worker = WorkerInit(true);
bool firstRuntime = atomicAdd(&aliveRuntimesCount, 1) == 1;
// Keep global variables in state as well.
if (firstRuntime) {
isMainThread = 1;
konan::consoleInit();
#if KONAN_OBJC_INTEROP
Kotlin_ObjCExport_initialize();
#endif
InitOrDeinitGlobalVariables(INIT_GLOBALS, result->memoryState);
}
InitOrDeinitGlobalVariables(INIT_THREAD_LOCAL_GLOBALS, result->memoryState);
RuntimeAssert(result->status == RuntimeStatus::kUninitialized, "Runtime must still be in the uninitialized state");
result->status = RuntimeStatus::kRunning;
return result;
}
void deinitRuntime(RuntimeState* state) {
RuntimeAssert(state->status == RuntimeStatus::kRunning, "Runtime must be in the running state");
state->status = RuntimeStatus::kDestroying;
// This may be called after TLS is zeroed out, so ::memoryState in Memory cannot be trusted.
RestoreMemory(state->memoryState);
bool lastRuntime = atomicAdd(&aliveRuntimesCount, -1) == 0;
InitOrDeinitGlobalVariables(DEINIT_THREAD_LOCAL_GLOBALS, state->memoryState);
if (lastRuntime)
InitOrDeinitGlobalVariables(DEINIT_GLOBALS, state->memoryState);
auto workerId = GetWorkerId(state->worker);
WorkerDeinit(state->worker);
DeinitMemory(state->memoryState);
konanDestructInstance(state);
WorkerDestroyThreadDataIfNeeded(workerId);
}
void Kotlin_deinitRuntimeCallback(void* argument) {
auto* state = reinterpret_cast<RuntimeState*>(argument);
deinitRuntime(state);
}
} // namespace
extern "C" {
void AppendToInitializersTail(InitNode *next) {
// TODO: use RuntimeState.
if (initHeadNode == nullptr) {
initHeadNode = next;
} else {
initTailNode->next = next;
}
initTailNode = next;
}
void Kotlin_initRuntimeIfNeeded() {
if (!isValidRuntime()) {
initRuntime();
// Register runtime deinit function at thread cleanup.
konan::onThreadExit(Kotlin_deinitRuntimeCallback, runtimeState);
}
}
void Kotlin_deinitRuntimeIfNeeded() {
if (isValidRuntime()) {
deinitRuntime(::runtimeState);
::runtimeState = kInvalidRuntime;
}
}
void CheckIsMainThread() {
if (!isMainThread)
ThrowIncorrectDereferenceException();
}
KInt Konan_Platform_canAccessUnaligned() {
#if KONAN_NO_UNALIGNED_ACCESS
return 0;
#else
return 1;
#endif
}
KInt Konan_Platform_isLittleEndian() {
#ifdef __BIG_ENDIAN__
return 0;
#else
return 1;
#endif
}
KInt Konan_Platform_getOsFamily() {
#if KONAN_MACOSX
return 1;
#elif KONAN_IOS
return 2;
#elif KONAN_LINUX
return 3;
#elif KONAN_WINDOWS
return 4;
#elif KONAN_ANDROID
return 5;
#elif KONAN_WASM
return 6;
#elif KONAN_TVOS
return 7;
#elif KONAN_WATCHOS
return 8;
#else
#warning "Unknown platform"
return 0;
#endif
}
KInt Konan_Platform_getCpuArchitecture() {
#if KONAN_ARM32
return 1;
#elif KONAN_ARM64
return 2;
#elif KONAN_X86
return 3;
#elif KONAN_X64
return 4;
#elif KONAN_MIPS32
return 5;
#elif KONAN_MIPSEL32
return 6;
#elif KONAN_WASM
return 7;
#else
#warning "Unknown CPU"
return 0;
#endif
}
KInt Konan_Platform_getMemoryModel() {
return IsStrictMemoryModel ? 0 : 1;
}
KBoolean Konan_Platform_isDebugBinary() {
return KonanNeedDebugInfo ? true : false;
}
void Kotlin_zeroOutTLSGlobals() {
if (runtimeState != nullptr && runtimeState->memoryState != nullptr)
InitOrDeinitGlobalVariables(DEINIT_THREAD_LOCAL_GLOBALS, runtimeState->memoryState);
}
bool Kotlin_memoryLeakCheckerEnabled() {
return g_checkLeaks;
}
KBoolean Konan_Platform_getMemoryLeakChecker() {
return g_checkLeaks;
}
void Konan_Platform_setMemoryLeakChecker(KBoolean value) {
g_checkLeaks = value;
}
bool Kotlin_cleanersLeakCheckerEnabled() {
return g_checkLeakedCleaners;
}
KBoolean Konan_Platform_getCleanersLeakChecker() {
return g_checkLeakedCleaners;
}
void Konan_Platform_setCleanersLeakChecker(KBoolean value) {
g_checkLeakedCleaners = value;
}
} // extern "C"