Skip to content

JIT: enable JIT on Linux #1591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ if(CLR_CMAKE_PLATFORM_XPLAT)
-DUNICODE
-D_SAFECRT_USE_CPP_OVERLOADS=1
-D__STDC_WANT_LIB_EXT1__=1
-DDISABLE_JIT=1 # xplat-todo: enable the JIT for Linux
)

set(CMAKE_CXX_STANDARD 11)
Expand Down Expand Up @@ -254,7 +253,15 @@ if(CLR_CMAKE_PLATFORM_XPLAT)
add_compile_options(
-fasm-blocks
-fms-extensions
-fwrapv # Treat signed integer overflow as two's complement
)

# Clang -fsanitize.
if (CLANG_SANITIZE_SH)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${CLANG_SANITIZE_SH}")
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -fsanitize=${CLANG_SANITIZE_SH}")
unset(CLANG_SANITIZE_SH CACHE) # don't cache
endif()
endif(CLR_CMAKE_PLATFORM_XPLAT)

if(CMAKE_BUILD_TYPE STREQUAL Debug)
Expand Down Expand Up @@ -287,9 +294,19 @@ if(CLR_CMAKE_PLATFORM_XPLAT)
add_definitions(-DFEATURE_PAL)
endif(CLR_CMAKE_PLATFORM_XPLAT)

if(WITHOUT_FEATURES)
add_definitions(${WITHOUT_FEATURES})
endif(WITHOUT_FEATURES)
if(NO_JIT_SH
OR CLR_CMAKE_PLATFORM_DARWIN) # TODO: JIT for OSX
unset(NO_JIT_SH CACHE) # don't cache
unset(BuildJIT CACHE) # also clear it just in case
add_definitions(-DDISABLE_JIT=1)
else()
set(BuildJIT 1)
endif()

if(WITHOUT_FEATURES_SH)
unset(WITHOUT_FEATURES_SH CACHE) # don't cache
add_definitions(${WITHOUT_FEATURES_SH})
endif(WITHOUT_FEATURES_SH)

enable_language(ASM)

Expand Down
4 changes: 2 additions & 2 deletions bin/ChakraCore/TestHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void __stdcall ConnectJITServer(HANDLE processHandle, void* serverSecurityDescri
ThreadContext::SetJITConnectionInfo(processHandle, serverSecurityDescriptor, connectionId);
}
#endif
#endif
#endif

void __stdcall NotifyUnhandledException(PEXCEPTION_POINTERS exceptionInfo)
{
Expand Down Expand Up @@ -162,7 +162,7 @@ HRESULT OnChakraCoreLoaded()
#undef FLAG_NumberSet
#undef FLAG_NumberPairSet
#undef FLAG_NumberRange
#if ENABLE_NATIVE_CODEGEN
#if ENABLE_NATIVE_CODEGEN && _WIN32
ConnectJITServer,
#endif
NotifyUnhandledException
Expand Down
11 changes: 11 additions & 0 deletions bin/ch/ChakraRtInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,18 @@ void ChakraRTInterface::UnloadChakraDll(HINSTANCE library)
{
pDllCanUnloadNow();
}
#ifdef _WIN32
UnloadChakraCore(library);
#else // !_WIN32
// PAL thread shutdown needs more time after execution completion.
// Do not FreeLibrary. Invoke DllMain(DLL_PROCESS_DETACH) directly.
typedef BOOL (__stdcall *PDLLMAIN)(HINSTANCE, DWORD, LPVOID);
PDLLMAIN pDllMain = (PDLLMAIN) GetChakraCoreSymbol(library, "DllMain");
if (pDllMain)
{
pDllMain(library, DLL_PROCESS_DETACH, NULL);
}
#endif
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion bin/ch/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ bool Debugger::CompareOrWriteBaselineFile(LPCSTR fileName)
IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsStringToPointerUtf8Copy(result, &baselineData, &baselineDataLength));

char16 baselineFilename[256];
swprintf_s(baselineFilename, _countof(baselineFilename), HostConfigFlags::flags.dbgbaselineIsEnabled ? _u("%S.dbg.baseline.rebase") : _u("%S.dbg.baseline"), fileName);
swprintf_s(baselineFilename, HostConfigFlags::flags.dbgbaselineIsEnabled ? _u("%S.dbg.baseline.rebase") : _u("%S.dbg.baseline"), fileName);

FILE *file = nullptr;
if (_wfopen_s(&file, baselineFilename, _u("wt")) != 0)
Expand Down
2 changes: 1 addition & 1 deletion bin/ch/ch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int HostExceptionFilter(int exceptionCode, _EXCEPTION_POINTERS *ep)
{
ChakraRTInterface::NotifyUnhandledException(ep);

#if ENABLE_NATIVE_CODEGEN
#if ENABLE_NATIVE_CODEGEN && _WIN32
JITProcessManager::TerminateJITServer();
#endif
bool crashOnException = false;
Expand Down
22 changes: 19 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ PRINT_USAGE() {
echo " --icu=PATH Path to ICU include folder (see example below)"
echo " -j [N], --jobs[=N] Multicore build, allow N jobs at once"
echo " -n, --ninja Build with ninja instead of make"
echo " --no-icu Compile without unicode/icu support"
echo " --no-icu Compile without unicode/icu support"
echo " --no-jit Disable JIT"
echo " --xcode Generate XCode project"
echo " -t, --test-build Test build (by default Release build)"
echo " --static Build as static library (by default shared library)"
echo " --sanitize=CHECKS Build with clang -fsanitize checks,"
echo " e.g. undefined,signed-integer-overflow"
echo " -v, --verbose Display verbose output including all options"
echo " --create-deb=V Create .deb package with given V version"
echo " --without=FEATURE,FEATURE,..."
Expand All @@ -62,8 +65,10 @@ BUILD_TYPE="Release"
CMAKE_GEN=
MAKE=make
MULTICORE_BUILD=""
NO_JIT=
ICU_PATH="-DICU_SETTINGS_RESET=1"
STATIC_LIBRARY="-DSHARED_LIBRARY_SH=1"
SANITIZE=
WITHOUT_FEATURES=""
CREATE_DEB=0
ARCH="-DCC_TARGETS_AMD64_SH=1"
Expand Down Expand Up @@ -191,6 +196,10 @@ while [[ $# -gt 0 ]]; do
ICU_PATH="-DNO_ICU_PATH_GIVEN_SH=1"
;;

--no-jit)
NO_JIT="-DNO_JIT_SH=1"
;;

--xcode)
CMAKE_GEN="-G Xcode -DCC_XCODE_PROJECT=1"
MAKE=0
Expand All @@ -205,13 +214,19 @@ while [[ $# -gt 0 ]]; do
STATIC_LIBRARY="-DSTATIC_LIBRARY_SH=1"
;;

--sanitize=*)
SANITIZE=$1
SANITIZE=${SANITIZE:11} # value after --sanitize=
SANITIZE="-DCLANG_SANITIZE_SH=${SANITIZE}"
;;

--without=*)
FEATURES=$1
FEATURES=${FEATURES:10} # value after --without=
for x in ${FEATURES//,/ } # replace comma with space then split
do
if [[ "$WITHOUT_FEATURES" == "" ]]; then
WITHOUT_FEATURES="-DWITHOUT_FEATURES="
WITHOUT_FEATURES="-DWITHOUT_FEATURES_SH="
else
WITHOUT_FEATURES="$WITHOUT_FEATURES;"
fi
Expand Down Expand Up @@ -306,7 +321,8 @@ else
fi

echo Generating $BUILD_TYPE makefiles
cmake $CMAKE_GEN $CC_PREFIX $ICU_PATH $STATIC_LIBRARY $ARCH -DCMAKE_BUILD_TYPE=$BUILD_TYPE $WITHOUT_FEATURES ../..
cmake $CMAKE_GEN $CC_PREFIX $ICU_PATH $STATIC_LIBRARY $ARCH \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE $SANITIZE $NO_JIT $WITHOUT_FEATURES ../..

_RET=$?
if [[ $? == 0 ]]; then
Expand Down
4 changes: 4 additions & 0 deletions lib/Backend/Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "Backend.h"

#if !ENABLE_OOP_NATIVE_CODEGEN
JITManager JITManager::s_jitManager; // dummy object when OOP JIT disabled
#endif
2 changes: 2 additions & 0 deletions lib/Backend/Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ enum IRDumpFlags
// BackEnd includes
//

#ifdef _WIN32
#include "ChakraJIT.h"
#endif
#include "JITTimeProfileInfo.h"
#include "JITRecyclableObject.h"
#include "JITTimeFixedField.h"
Expand Down
16 changes: 8 additions & 8 deletions lib/Backend/BackwardPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3311,13 +3311,13 @@ BackwardPass::ProcessNoImplicitCallDef(IR::Instr *const instr)
else if(
!(
// LdFld or similar
dst->IsRegOpnd() && src->IsSymOpnd() && src->AsSymOpnd()->m_sym->IsPropertySym() ||
(dst->IsRegOpnd() && src->IsSymOpnd() && src->AsSymOpnd()->m_sym->IsPropertySym()) ||

// StFld or similar. Don't transfer a field opnd from StFld into the reg opnd src unless the field's value type is
// definitely array or object with array, because only those value types require implicit calls to be disabled as
// long as they are live. Other definite value types only require implicit calls to be disabled as long as a live
// field holds the value, which is up to the StFld when going backwards.
src->IsRegOpnd() && dst->GetValueType().IsArrayOrObjectWithArray()
(src->IsRegOpnd() && dst->GetValueType().IsArrayOrObjectWithArray())
) ||
!GlobOpt::TransferSrcValue(instr))
{
Expand Down Expand Up @@ -3972,8 +3972,8 @@ BackwardPass::UpdateArrayBailOutKind(IR::Instr *const instr)
Assert(instr);
Assert(instr->HasBailOutInfo());

if (instr->m_opcode != Js::OpCode::StElemI_A && instr->m_opcode != Js::OpCode::StElemI_A_Strict &&
instr->m_opcode != Js::OpCode::Memcopy && instr->m_opcode != Js::OpCode::Memset ||
if ((instr->m_opcode != Js::OpCode::StElemI_A && instr->m_opcode != Js::OpCode::StElemI_A_Strict &&
instr->m_opcode != Js::OpCode::Memcopy && instr->m_opcode != Js::OpCode::Memset) ||
!instr->GetDst()->IsIndirOpnd())
{
return;
Expand Down Expand Up @@ -5511,7 +5511,7 @@ BackwardPass::TrackIntUsage(IR::Instr *const instr)

if (instr->ignoreNegativeZero ||
(instr->GetSrc1()->IsIntConstOpnd() && instr->GetSrc1()->AsIntConstOpnd()->GetValue() != 0) ||
instr->GetSrc2()->IsIntConstOpnd() && instr->GetSrc2()->AsIntConstOpnd()->GetValue() != 0)
(instr->GetSrc2()->IsIntConstOpnd() && instr->GetSrc2()->AsIntConstOpnd()->GetValue() != 0))
{
SetNegativeZeroDoesNotMatterIfLastUse(instr->GetSrc1());
SetNegativeZeroDoesNotMatterIfLastUse(instr->GetSrc2());
Expand Down Expand Up @@ -5567,7 +5567,7 @@ BackwardPass::TrackIntUsage(IR::Instr *const instr)

if (instr->ignoreNegativeZero ||
(instr->GetSrc1()->IsIntConstOpnd() && instr->GetSrc1()->AsIntConstOpnd()->GetValue() != 0) ||
instr->GetSrc2()->IsIntConstOpnd() && instr->GetSrc2()->AsIntConstOpnd()->GetValue() != 0)
(instr->GetSrc2()->IsIntConstOpnd() && instr->GetSrc2()->AsIntConstOpnd()->GetValue() != 0))
{
SetNegativeZeroDoesNotMatterIfLastUse(instr->GetSrc1());
SetNegativeZeroDoesNotMatterIfLastUse(instr->GetSrc2());
Expand Down Expand Up @@ -5890,7 +5890,7 @@ BackwardPass::TrackIntUsage(IR::Instr *const instr)
!!candidateSymsRequiredToBeLossyInt->Test(srcSymId);
const bool srcNeedsToBeLossless =
!currentBlock->intOverflowDoesNotMatterRange->SymsRequiredToBeLossyInt()->Test(dstSym->m_id) ||
srcIncluded && !srcIncludedAsLossy;
(srcIncluded && !srcIncludedAsLossy);
if(srcIncluded)
{
if(srcIncludedAsLossy && srcNeedsToBeLossless)
Expand Down Expand Up @@ -6362,7 +6362,7 @@ BackwardPass::TrackFloatSymEquivalence(IR::Instr *const instr)
// throughout the function and checking just the sym's non-number bailout bit is insufficient.
FloatSymEquivalenceClass *dstEquivalenceClass;
if(dst->m_requiresBailOnNotNumber ||
floatSymEquivalenceMap->TryGetValue(dst->m_id, &dstEquivalenceClass) && dstEquivalenceClass->RequiresBailOnNotNumber())
(floatSymEquivalenceMap->TryGetValue(dst->m_id, &dstEquivalenceClass) && dstEquivalenceClass->RequiresBailOnNotNumber()))
{
instr->SetBailOutKind(IR::BailOutNumberOnly);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Backend/BailOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ BailOutRecord::BailOutRecord(uint32 bailOutOffset, uint bailOutCacheIndex, IR::B
Output::Flush(); \
} \
}
char16 * const trueString = _u("true");
char16 * const falseString = _u("false");
const char16 * const trueString = _u("true");
const char16 * const falseString = _u("false");
#else
#define REJIT_TESTTRACE(...)
#define REJIT_KIND_TESTTRACE(...)
Expand Down Expand Up @@ -1478,7 +1478,7 @@ BailOutRecord::BailOutHelper(Js::JavascriptCallStackLayout * layout, Js::ScriptF
// Initialize the interpreter stack frame (constants) but not the param, the bailout record will restore the value
#if DBG
// Allocate invalidVar on GC instead of stack since this InterpreterStackFrame will out live the current real frame
Js::RecyclableObject* invalidVar = (Js::RecyclableObject*)RecyclerNewPlusLeaf(functionScriptContext->GetRecycler(), sizeof(Js::RecyclableObject), Js::Var);
Js::Var invalidVar = (Js::RecyclableObject*)RecyclerNewPlusLeaf(functionScriptContext->GetRecycler(), sizeof(Js::RecyclableObject), Js::Var);
memset(invalidVar, 0xFE, sizeof(Js::RecyclableObject));
newInstance = setup.InitializeAllocation(allocation, false, false, loopHeaderArray, stackAddr, invalidVar);
#else
Expand Down Expand Up @@ -1528,7 +1528,7 @@ BailOutRecord::BailOutHelper(Js::JavascriptCallStackLayout * layout, Js::ScriptF

// Initialize the interpreter stack frame (constants) but not the param, the bailout record will restore the value
#if DBG
Js::RecyclableObject * invalidStackVar = (Js::RecyclableObject*)_alloca(sizeof(Js::RecyclableObject));
Js::Var invalidStackVar = (Js::RecyclableObject*)_alloca(sizeof(Js::RecyclableObject));
memset(invalidStackVar, 0xFE, sizeof(Js::RecyclableObject));
newInstance = setup.InitializeAllocation(allocation, false, false, loopHeaderArray, frameStackAddr, invalidStackVar);
#else
Expand Down
Loading