Skip to content
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

Use NASM assembler on x86-64 Linux #3293

Merged
merged 10 commits into from
Jan 8, 2019
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ addons:
- libxt-dev
- libxtst-dev
- make
- nasm
- openjdk-8-jdk
- pkg-config
- realpath
Expand Down
10 changes: 10 additions & 0 deletions runtime/compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
#
# Longer term, this will of course have to collapse into the VM builds.

if(OMR_ARCH_X86)
enable_language(ASM_NASM)
# We have to manually append "/" to the paths as NASM versions older than v2.14 requires trailing / in the directory paths
set(asm_inc_dirs
"-I${j9vm_SOURCE_DIR}/oti/"
"-I${CMAKE_CURRENT_SOURCE_DIR}/"
)
omr_append_flags(CMAKE_ASM_NASM_FLAGS ${asm_inc_dirs})
endif()

omr_add_tracegen(env/j9jit.tdf)

# this is a workarround because the jit code is inconsistent about how it includes the tracegen files
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/build/files/host/amd64.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception

ifeq ($(OS),osx)
ifeq ($(NASM_ASSEMBLER),yes)
JIT_PRODUCT_SOURCE_FILES+=\
compiler/x/amd64/runtime/AMD64CompressString.nasm \
compiler/x/amd64/runtime/AMD64Recompilation.nasm
Expand Down
40 changes: 19 additions & 21 deletions runtime/compiler/build/files/host/x.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,29 @@
JIT_PRODUCT_BACKEND_SOURCES+= \
omr/compiler/x/runtime/VirtualGuardRuntime.cpp

ifeq ($(OS),osx)
JIT_PRODUCT_SOURCE_FILES+=\
JIT_PRODUCT_SOURCE_FILES+=\
compiler/x/runtime/Recomp.cpp \
compiler/x/runtime/X86ArrayTranslate.nasm \
compiler/x/runtime/X86Codert.nasm \
compiler/x/runtime/X86EncodeUTF16.nasm \
compiler/x/runtime/X86LockReservation.nasm \
compiler/x/runtime/X86PicBuilder.nasm \
compiler/x/runtime/X86PicBuilderC.cpp \
compiler/x/runtime/X86RelocationTarget.cpp \
compiler/x/runtime/X86Unresolveds.nasm
compiler/x/runtime/X86RelocationTarget.cpp

ifeq ($(NASM_ASSEMBLER),yes)
JIT_PRODUCT_SOURCE_FILES+=\
compiler/x/runtime/X86ArrayTranslate.nasm \
compiler/x/runtime/X86Codert.nasm \
compiler/x/runtime/X86EncodeUTF16.nasm \
compiler/x/runtime/X86LockReservation.nasm \
compiler/x/runtime/X86PicBuilder.nasm \
compiler/x/runtime/X86Unresolveds.nasm

else
JIT_PRODUCT_SOURCE_FILES+=\
compiler/x/runtime/X86ArrayTranslate.asm \
compiler/x/runtime/X86Codert.asm \
compiler/x/runtime/X86EncodeUTF16.asm \
compiler/x/runtime/X86LockReservation.asm \
compiler/x/runtime/X86PicBuilder.pasm \
compiler/x/runtime/X86Unresolveds.pasm

JIT_PRODUCT_SOURCE_FILES+=\
compiler/x/runtime/Recomp.cpp \
compiler/x/runtime/X86ArrayTranslate.asm \
compiler/x/runtime/X86Codert.asm \
compiler/x/runtime/X86EncodeUTF16.asm \
compiler/x/runtime/X86LockReservation.asm \
compiler/x/runtime/X86PicBuilder.pasm \
compiler/x/runtime/X86PicBuilderC.cpp \
compiler/x/runtime/X86RelocationTarget.cpp \
compiler/x/runtime/X86Unresolveds.pasm

endif # OS == osx
endif # NASM_ASSEMBLER == yes

include $(JIT_MAKE_DIR)/files/host/$(HOST_SUBARCH).mk
4 changes: 2 additions & 2 deletions runtime/compiler/build/platform/host/amd64-linux64-clang.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2000, 2017 IBM Corp. and others
# Copyright (c) 2000, 2018 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -24,4 +24,4 @@ HOST_BITS=64
OS=linux
C_COMPILER=clang
TOOLCHAIN=gnu

NASM_ASSEMBLER=yes
4 changes: 2 additions & 2 deletions runtime/compiler/build/platform/host/amd64-linux64-gcc.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2000, 2017 IBM Corp. and others
# Copyright (c) 2000, 2018 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -24,4 +24,4 @@ HOST_BITS=64
OS=linux
C_COMPILER=gcc
TOOLCHAIN=gnu

NASM_ASSEMBLER=yes
1 change: 1 addition & 0 deletions runtime/compiler/build/platform/host/amd64-osx-clang.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ HOST_BITS=64
OS=osx
C_COMPILER=clang
TOOLCHAIN=gnu
NASM_ASSEMBLER=yes
1 change: 1 addition & 0 deletions runtime/compiler/build/platform/host/amd64-osx-gcc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ HOST_BITS=64
OS=osx
C_COMPILER=gcc
TOOLCHAIN=gnu
NASM_ASSEMBLER=yes
4 changes: 2 additions & 2 deletions runtime/compiler/control/CompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4708,7 +4708,7 @@ bool TR::CompilationInfo::isQueuedForCompilation(J9Method * method, void *oldSta
return linkageInfo->isBeingCompiled();
}

#if defined(OSX)
#if defined(NASM_ASSEMBLER)
JIT_HELPER(initialInvokeExactThunkGlue);
#else
JIT_HELPER(_initialInvokeExactThunkGlue);
Expand Down Expand Up @@ -4742,7 +4742,7 @@ void *TR::CompilationInfo::startPCIfAlreadyCompiled(J9VMThread * vmThread, TR::I
initialInvokeExactThunkGlueAddress = (void*)TOC_UNWRAP_ADDRESS(_initialInvokeExactThunkGlue);
#elif defined(TR_HOST_POWER) && (defined(TR_HOST_64BIT) || defined(AIXPPC)) && !defined(__LITTLE_ENDIAN__)
initialInvokeExactThunkGlueAddress = (*(void **)_initialInvokeExactThunkGlue);
#elif defined(OSX)
#elif defined(NASM_ASSEMBLER)
initialInvokeExactThunkGlueAddress = (void*)initialInvokeExactThunkGlue;
#else
initialInvokeExactThunkGlueAddress = (void*)_initialInvokeExactThunkGlue;
Expand Down
4 changes: 2 additions & 2 deletions runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9436,7 +9436,7 @@ TR_J9VMBase::classNameChars(TR::Compilation *comp, TR::SymbolReference * symRef,

// Native method bodies
//
#if defined(OSX)
#if defined(NASM_ASSEMBLER)
JIT_HELPER(initialInvokeExactThunkGlue);
#else
JIT_HELPER(_initialInvokeExactThunkGlue);
Expand All @@ -9449,7 +9449,7 @@ JNIEXPORT jlong JNICALL Java_java_lang_invoke_ThunkTuple_initialInvokeExactThunk
return (jlong)TOC_UNWRAP_ADDRESS(_initialInvokeExactThunkGlue);
#elif defined(TR_HOST_POWER) && (defined(TR_HOST_64BIT) || defined(AIXPPC)) && !defined(__LITTLE_ENDIAN__)
return (jlong)(*(void **)_initialInvokeExactThunkGlue);
#elif defined(OSX)
#elif defined(NASM_ASSEMBLER)
return (jlong)initialInvokeExactThunkGlue;
#else
return (jlong)_initialInvokeExactThunkGlue;
Expand Down
3 changes: 2 additions & 1 deletion runtime/compiler/runtime/CRuntimeImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@
#include "env/jittypes.h"
#include "runtime/MethodMetaData.h"
#include "env/VMJ9.h"
#include "runtime/asmprotos.h"

// To transfer control to VM during OSR
extern "C" {
#if defined(OSX)
#if defined(NASM_ASSEMBLER)
void prepareForOSR(uintptrj_t vmThreadArg, int32_t currentInlinedSiteIndex, int32_t slotData)
#else
void _prepareForOSR(uintptrj_t vmThreadArg, int32_t currentInlinedSiteIndex, int32_t slotData)
Expand Down
26 changes: 13 additions & 13 deletions runtime/compiler/runtime/JitRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,26 +1105,26 @@ extern "C" void _patchJNICallSite(J9Method *method, uint8_t *pc, uint8_t *newAdd
}
#endif

#if defined(OSX)
#if defined(NASM_ASSEMBLER)
JIT_HELPER(prepareForOSR);
#else
JIT_HELPER(_prepareForOSR);
#endif /* OSX */
#endif

#ifdef TR_HOST_X86
#if defined(OSX)
#if defined(NASM_ASSEMBLER)
JIT_HELPER(countingRecompileMethod);
JIT_HELPER(samplingRecompileMethod);
JIT_HELPER(countingPatchCallSite);
JIT_HELPER(samplingPatchCallSite);
JIT_HELPER(induceRecompilation);
#else
#else /* NASM_ASSEMBLER */
JIT_HELPER(_countingRecompileMethod);
JIT_HELPER(_samplingRecompileMethod);
JIT_HELPER(_countingPatchCallSite);
JIT_HELPER(_samplingPatchCallSite);
JIT_HELPER(_induceRecompilation);
#endif /* OSX */
#endif /* NASM_ASSEMBLER */

#elif defined(TR_HOST_POWER)

Expand Down Expand Up @@ -1208,28 +1208,28 @@ void initializeJitRuntimeHelperTable(char isSMP)

#if defined(J9ZOS390)
SET_CONST(TR_prepareForOSR, (void *)_prepareForOSR);
#elif defined(OSX)
#elif defined(NASM_ASSEMBLER)
SET(TR_prepareForOSR, (void *)prepareForOSR, TR_Helper);
#else
SET(TR_prepareForOSR, (void *)_prepareForOSR, TR_Helper);
#endif
#endif /* NASM_ASSEMBLER */

#ifdef TR_HOST_X86

#if defined(TR_HOST_64BIT)
#if defined(OSX)
#if defined(NASM_ASSEMBLER)
SET(TR_AMD64samplingRecompileMethod, (void *)samplingRecompileMethod, TR_Helper);
SET(TR_AMD64countingRecompileMethod, (void *)countingRecompileMethod, TR_Helper);
SET(TR_AMD64samplingPatchCallSite, (void *)samplingPatchCallSite, TR_Helper);
SET(TR_AMD64countingPatchCallSite, (void *)countingPatchCallSite, TR_Helper);
SET(TR_AMD64induceRecompilation, (void *)induceRecompilation, TR_Helper);
#else /* OSX */
#else /* NASM_ASSEMBLER */
SET(TR_AMD64samplingRecompileMethod, (void *)_samplingRecompileMethod, TR_Helper);
SET(TR_AMD64countingRecompileMethod, (void *)_countingRecompileMethod, TR_Helper);
SET(TR_AMD64samplingPatchCallSite, (void *)_samplingPatchCallSite, TR_Helper);
SET(TR_AMD64countingPatchCallSite, (void *)_countingPatchCallSite, TR_Helper);
SET(TR_AMD64induceRecompilation, (void *)_induceRecompilation, TR_Helper);
#endif /* OSX */
#endif /* NASM_ASSEMBLER */
#else /* TR_HOST_64BIT */
SET(TR_IA32samplingRecompileMethod, (void *)_samplingRecompileMethod, TR_Helper);
SET(TR_IA32countingRecompileMethod, (void *)_countingRecompileMethod, TR_Helper);
Expand Down Expand Up @@ -1610,7 +1610,7 @@ uint8_t *compileMethodHandleThunk(j9object_t methodHandle, j9object_t arg, J9VMT
return startPC;
}

#if defined(OSX)
#if defined(NASM_ASSEMBLER)
JIT_HELPER(initialInvokeExactThunkGlue);
#else
JIT_HELPER(_initialInvokeExactThunkGlue);
Expand Down Expand Up @@ -1682,7 +1682,7 @@ void *initialInvokeExactThunk(j9object_t methodHandle, J9VMThread *vmThread)
else
{
uintptrj_t fieldOffset = fej9->getInstanceFieldOffset(fej9->getObjectClass(thunkTuple), "invokeExactThunk", "J");
#if defined(OSX)
#if defined(NASM_ASSEMBLER)
bool success = fej9->compareAndSwapInt64Field(thunkTuple, "invokeExactThunk", (uint64_t)(uintptrj_t)initialInvokeExactThunkGlue, (uint64_t)(uintptrj_t)addressToDispatch);

if (details)
Expand All @@ -1695,7 +1695,7 @@ void *initialInvokeExactThunk(j9object_t methodHandle, J9VMThread *vmThread)
if (details)
TR_VerboseLog::writeLineLocked(TR_Vlog_MHD, "%p %s updating ThunkTuple %p field %+d from %p to %p",
vmThread, success? "Succeeded" : "Failed", thunkTuple, (int)fieldOffset, _initialInvokeExactThunkGlue, addressToDispatch);
#endif
#endif /* NASM_ASSEMBLER */
}
return addressToDispatch;
}
Expand Down
Loading