2017-08-12 16:48:01 +00:00
|
|
|
/*
|
2022-10-23 02:55:20 +00:00
|
|
|
* Copyright (C) 2008-2020 Apple Inc. All rights reserved.
|
2017-08-12 16:48:01 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of Apple Inc. ("Apple") nor the names of
|
|
|
|
* its contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "InitializeThreading.h"
|
|
|
|
|
|
|
|
#include "ExecutableAllocator.h"
|
2022-10-23 02:55:20 +00:00
|
|
|
#include "JITOperationList.h"
|
|
|
|
#include "JSCConfig.h"
|
2020-08-29 13:27:11 +00:00
|
|
|
#include "JSCPtrTag.h"
|
2017-08-12 16:48:01 +00:00
|
|
|
#include "LLIntData.h"
|
|
|
|
#include "Options.h"
|
2020-08-29 13:27:11 +00:00
|
|
|
#include "SigillCrashAnalyzer.h"
|
2017-08-12 16:48:01 +00:00
|
|
|
#include "SuperSampler.h"
|
2022-10-23 02:55:20 +00:00
|
|
|
#include "VMTraps.h"
|
|
|
|
#include "WasmCalleeRegistry.h"
|
2020-08-29 13:27:11 +00:00
|
|
|
#include "WasmCapabilities.h"
|
2022-10-23 02:55:20 +00:00
|
|
|
#include "WasmFaultSignalHandler.h"
|
2018-01-03 05:16:05 +00:00
|
|
|
#include "WasmThunks.h"
|
2017-08-12 16:48:01 +00:00
|
|
|
#include <mutex>
|
|
|
|
#include <wtf/Threading.h>
|
2022-10-23 02:55:20 +00:00
|
|
|
#include <wtf/threads/Signals.h>
|
2017-08-12 16:48:01 +00:00
|
|
|
|
|
|
|
namespace JSC {
|
|
|
|
|
2020-08-29 13:27:11 +00:00
|
|
|
static_assert(sizeof(bool) == 1, "LLInt and JIT assume sizeof(bool) is always 1 when touching it directly from assembly code.");
|
|
|
|
|
2022-10-23 02:55:20 +00:00
|
|
|
void initialize()
|
2017-08-12 16:48:01 +00:00
|
|
|
{
|
2022-10-23 02:55:20 +00:00
|
|
|
static std::once_flag onceFlag;
|
2017-08-12 16:48:01 +00:00
|
|
|
|
2022-10-23 02:55:20 +00:00
|
|
|
std::call_once(onceFlag, [] {
|
|
|
|
WTF::initialize();
|
2017-08-12 16:48:01 +00:00
|
|
|
Options::initialize();
|
2020-08-29 13:27:11 +00:00
|
|
|
|
|
|
|
initializePtrTagLookup();
|
|
|
|
|
2017-08-12 16:48:01 +00:00
|
|
|
#if ENABLE(WRITE_BARRIER_PROFILING)
|
|
|
|
WriteBarrierCounters::initialize();
|
|
|
|
#endif
|
2022-10-23 02:55:20 +00:00
|
|
|
{
|
|
|
|
Options::AllowUnfinalizedAccessScope scope;
|
|
|
|
JITOperationList::initialize();
|
|
|
|
ExecutableAllocator::initialize();
|
|
|
|
VM::computeCanUseJIT();
|
|
|
|
if (!g_jscConfig.vm.canUseJIT) {
|
|
|
|
Options::useJIT() = false;
|
|
|
|
Options::recomputeDependentOptions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Options::finalize();
|
2020-08-29 13:27:11 +00:00
|
|
|
|
2022-10-23 02:55:20 +00:00
|
|
|
JITOperationList::populatePointersInJavaScriptCore();
|
2020-08-29 13:27:11 +00:00
|
|
|
|
2022-10-23 02:55:20 +00:00
|
|
|
if (Options::useSigillCrashAnalyzer())
|
2020-08-29 13:27:11 +00:00
|
|
|
enableSigillCrashAnalyzer();
|
|
|
|
|
2017-08-12 16:48:01 +00:00
|
|
|
LLInt::initialize();
|
|
|
|
DisallowGC::initialize();
|
2022-10-23 02:55:20 +00:00
|
|
|
|
2017-08-12 16:48:01 +00:00
|
|
|
initializeSuperSampler();
|
2020-08-29 13:27:11 +00:00
|
|
|
Thread& thread = Thread::current();
|
|
|
|
thread.setSavedLastStackTop(thread.stack().origin());
|
2018-01-03 05:16:05 +00:00
|
|
|
|
|
|
|
#if ENABLE(WEBASSEMBLY)
|
2022-10-23 02:55:20 +00:00
|
|
|
if (Wasm::isSupported()) {
|
2020-08-29 13:27:11 +00:00
|
|
|
Wasm::Thunks::initialize();
|
2022-10-23 02:55:20 +00:00
|
|
|
Wasm::CalleeRegistry::initialize();
|
|
|
|
}
|
2018-01-03 05:16:05 +00:00
|
|
|
#endif
|
2020-08-29 13:27:11 +00:00
|
|
|
|
|
|
|
if (VM::isInMiniMode())
|
|
|
|
WTF::fastEnableMiniMode();
|
2022-10-23 02:55:20 +00:00
|
|
|
|
|
|
|
#if HAVE(MACH_EXCEPTIONS)
|
|
|
|
// JSLock::lock() can call registerThreadForMachExceptionHandling() which crashes if this has not been called first.
|
|
|
|
WTF::startMachExceptionHandlerThread();
|
|
|
|
#endif
|
|
|
|
VMTraps::initializeSignals();
|
|
|
|
#if ENABLE(WEBASSEMBLY)
|
|
|
|
Wasm::prepareFastMemory();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
WTF::compilerFence();
|
|
|
|
RELEASE_ASSERT(!g_jscConfig.initializeHasBeenCalled);
|
|
|
|
g_jscConfig.initializeHasBeenCalled = true;
|
2017-08-12 16:48:01 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace JSC
|