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

Fix extern "C" naming issues on OSX #3020

Merged
merged 2 commits into from
Oct 4, 2018
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
8 changes: 7 additions & 1 deletion runtime/compiler/control/CompilationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define J9_EXTERNAL_TO_VM

#if SOLARIS || AIXPPC || LINUX
#if SOLARIS || AIXPPC || LINUX || OSX
#include <strings.h>
#define J9OS_STRNCMP strncasecmp
#else
Expand Down Expand Up @@ -4707,7 +4707,11 @@ bool TR::CompilationInfo::isQueuedForCompilation(J9Method * method, void *oldSta
return linkageInfo->isBeingCompiled();
}

#if defined(OSX)
JIT_HELPER(initialInvokeExactThunkGlue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the JIT_HELPER macro be updated to include _ on OSX? That would minimize the other required changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The leading _ is needed for platforms other than OSX. So what we would need is to have JIT_HELPER(x) defined to extern "C" void x() on mac and extern "C" void _x() on other platforms. We would then also need to enclose any calls to these functions in C/C++ in another macro, say, CALL_JIT_HELPER.

However, I did not go with that solution because the problem is that there is a lack of consistency here. The method calls/declarations with leading underscore in C also are named with leading underscores in the MASM code. Most of the methods are missing a leading underscore (and also in the assembly code), and so using our single JIT_HELPER macro that expands differently on OSX would not work. We would then need to divide them into 2 different categories, requiring 4 different macros: JIT_HELPER(x), JIT_HELPER_UNDERSCORE(x), CALL_JIT_HELPER(x), CALL_JIT_HELPER_UNDERSCORE(x).

Did you have a different idea in mind?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The VM handles this somewhat differently by hiding the platform differences in the macros. Looking at the JIT code, the approach there is to handle it with ifdefs throughout.

I don't want this to block this PR from moving forward. Though I think it would be worth looking at cleaning this up in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be cleaned up once the NASM assembly files are set up to be used by Windows and xLinux. We will no longer need to have the code in the #else blocks of #if defined(OSX) in this PR.

#else
JIT_HELPER(_initialInvokeExactThunkGlue);
#endif

void *TR::CompilationInfo::startPCIfAlreadyCompiled(J9VMThread * vmThread, TR::IlGeneratorMethodDetails & details, void *oldStartPC)
{
Expand Down Expand Up @@ -4737,6 +4741,8 @@ 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)
initialInvokeExactThunkGlueAddress = (void*)initialInvokeExactThunkGlue;
#else
initialInvokeExactThunkGlueAddress = (void*)_initialInvokeExactThunkGlue;
#endif
Expand Down
7 changes: 6 additions & 1 deletion runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9095,8 +9095,11 @@ TR_J9VMBase::classNameChars(TR::Compilation *comp, TR::SymbolReference * symRef,

// Native method bodies
//

#if defined(OSX)
JIT_HELPER(initialInvokeExactThunkGlue);
#else
JIT_HELPER(_initialInvokeExactThunkGlue);
#endif

JNIEXPORT jlong JNICALL Java_java_lang_invoke_ThunkTuple_initialInvokeExactThunk
(JNIEnv *env, jclass clazz)
Expand All @@ -9105,6 +9108,8 @@ 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)
return (jlong)initialInvokeExactThunkGlue;
#else
return (jlong)_initialInvokeExactThunkGlue;
#endif
Expand Down
6 changes: 5 additions & 1 deletion runtime/compiler/runtime/CRuntimeImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* 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 Down Expand Up @@ -41,7 +41,11 @@

// To transfer control to VM during OSR
extern "C" {
#if defined(OSX)
void prepareForOSR(uintptrj_t vmThreadArg, int32_t currentInlinedSiteIndex, int32_t slotData)
#else
void _prepareForOSR(uintptrj_t vmThreadArg, int32_t currentInlinedSiteIndex, int32_t slotData)
#endif
{
const bool details = TR::Options::getCmdLineOptions()->getVerboseOption(TR_VerboseOSRDetails);
const bool trace = TR::Options::getCmdLineOptions()->getVerboseOption(TR_VerboseOSR) || details;
Expand Down
41 changes: 37 additions & 4 deletions runtime/compiler/runtime/JitRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1106,14 +1106,26 @@ extern "C" void _patchJNICallSite(J9Method *method, uint8_t *pc, uint8_t *newAdd
}
#endif

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

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

#elif defined(TR_HOST_POWER)

Expand Down Expand Up @@ -1197,25 +1209,35 @@ void initializeJitRuntimeHelperTable(char isSMP)

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

#ifdef TR_HOST_X86

# if defined(TR_HOST_64BIT)
#if defined(TR_HOST_64BIT)
#if defined(OSX)
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 */
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
#endif /* OSX */
#else /* TR_HOST_64BIT */
SET(TR_IA32samplingRecompileMethod, (void *)_samplingRecompileMethod, TR_Helper);
SET(TR_IA32countingRecompileMethod, (void *)_countingRecompileMethod, TR_Helper);
SET(TR_IA32samplingPatchCallSite, (void *)_samplingPatchCallSite, TR_Helper);
SET(TR_IA32countingPatchCallSite, (void *)_countingPatchCallSite, TR_Helper);
SET(TR_IA32induceRecompilation, (void *)_induceRecompilation, TR_Helper);
# endif
#endif /* TR_HOST_64BIT */

#elif defined(TR_HOST_POWER)

Expand Down Expand Up @@ -1589,7 +1611,11 @@ uint8_t *compileMethodHandleThunk(j9object_t methodHandle, j9object_t arg, J9VMT
return startPC;
}

#if defined(OSX)
JIT_HELPER(initialInvokeExactThunkGlue);
#else
JIT_HELPER(_initialInvokeExactThunkGlue);
#endif

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

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);
#else
bool success = fej9->compareAndSwapInt64Field(thunkTuple, "invokeExactThunk", (uint64_t)(uintptrj_t)_initialInvokeExactThunkGlue, (uint64_t)(uintptrj_t)addressToDispatch);
// If the CAS fails, we don't care much. It just means another thread may already have put a MH thunk pointer in there.

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
}

return addressToDispatch;
}

Expand Down
79 changes: 74 additions & 5 deletions runtime/compiler/runtime/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,17 @@ JIT_HELPER(callGPU);
// --------------------------------------------------------------------------------
// X86 COMMON
// --------------------------------------------------------------------------------

#if defined(OSX)
JIT_HELPER(doubleToLong);
JIT_HELPER(doubleToInt);
JIT_HELPER(floatToLong);
JIT_HELPER(floatToInt);
#else
JIT_HELPER(_doubleToLong);
JIT_HELPER(_doubleToInt);
JIT_HELPER(_floatToLong);
JIT_HELPER(_floatToInt);
#endif /* OSX */

JIT_HELPER(interpreterUnresolvedClassGlue);
JIT_HELPER(interpreterUnresolvedClassFromStaticFieldGlue);
Expand All @@ -263,6 +269,22 @@ JIT_HELPER(interpreterUnresolvedFieldGlue);
JIT_HELPER(interpreterUnresolvedFieldSetterGlue);
JIT_HELPER(interpreterUnresolvedConstantDynamicGlue);

#if defined(OSX)
JIT_HELPER(SMPinterpreterUnresolvedStaticGlue);
JIT_HELPER(SMPinterpreterUnresolvedSpecialGlue);
JIT_HELPER(SMPinterpreterUnresolvedDirectVirtualGlue);
JIT_HELPER(SMPinterpreterUnresolvedClassGlue);
JIT_HELPER(SMPinterpreterUnresolvedClassGlue2);
JIT_HELPER(SMPinterpreterUnresolvedStringGlue);
JIT_HELPER(SMPinterpreterUnresolvedMethodTypeGlue);
JIT_HELPER(SMPinterpreterUnresolvedMethodHandleGlue);
JIT_HELPER(SMPinterpreterUnresolvedCallSiteTableEntryGlue);
JIT_HELPER(SMPinterpreterUnresolvedMethodTypeTableEntryGlue);
JIT_HELPER(SMPinterpreterUnresolvedStaticDataGlue);
JIT_HELPER(SMPinterpreterUnresolvedStaticStoreDataGlue);
JIT_HELPER(SMPinterpreterUnresolvedInstanceDataGlue);
JIT_HELPER(SMPinterpreterUnresolvedInstanceStoreDataGlue);
#else
JIT_HELPER(_SMPinterpreterUnresolvedStaticGlue);
JIT_HELPER(_SMPinterpreterUnresolvedSpecialGlue);
JIT_HELPER(_SMPinterpreterUnresolvedDirectVirtualGlue);
Expand All @@ -277,6 +299,7 @@ JIT_HELPER(_SMPinterpreterUnresolvedStaticDataGlue);
JIT_HELPER(_SMPinterpreterUnresolvedStaticStoreDataGlue);
JIT_HELPER(_SMPinterpreterUnresolvedInstanceDataGlue);
JIT_HELPER(_SMPinterpreterUnresolvedInstanceStoreDataGlue);
#endif /* OSX */

JIT_HELPER(resolveIPicClass);
JIT_HELPER(populateIPicSlotClass);
Expand Down Expand Up @@ -315,36 +338,62 @@ JIT_HELPER(newPrefetchTLH);
JIT_HELPER(outlinedNewObject);
JIT_HELPER(outlinedNewArray);

#if defined(OSX)
JIT_HELPER(arrayTranslateTRTO);
JIT_HELPER(arrayTranslateTROTNoBreak);
JIT_HELPER(arrayTranslateTROT);
#else
JIT_HELPER(_arrayTranslateTRTO);
JIT_HELPER(_arrayTranslateTROTNoBreak);
JIT_HELPER(_arrayTranslateTROT);
#endif /* OSX */

// --------------------------------------------------------------------------------
// AMD64
// --------------------------------------------------------------------------------

#ifdef TR_HOST_64BIT
#if defined(OSX)
JIT_HELPER(SSEdoubleRemainder);
JIT_HELPER(SSEfloatRemainder);
#else
JIT_HELPER(_SSEdoubleRemainder);
JIT_HELPER(_SSEfloatRemainder);
#endif /* OSX */
JIT_HELPER(icallVMprJavaSendVirtual0);
JIT_HELPER(icallVMprJavaSendVirtual1);
JIT_HELPER(icallVMprJavaSendVirtualJ);
JIT_HELPER(icallVMprJavaSendVirtualL);
JIT_HELPER(icallVMprJavaSendVirtualF);
JIT_HELPER(icallVMprJavaSendVirtualD);

#if defined(OSX)
JIT_HELPER(compressString);
JIT_HELPER(compressStringNoCheck);
JIT_HELPER(compressStringJ);
JIT_HELPER(compressStringNoCheckJ);
JIT_HELPER(andORString);
JIT_HELPER(encodeUTF16Big);
JIT_HELPER(encodeUTF16Little);
#else
JIT_HELPER(_compressString);
JIT_HELPER(_compressStringNoCheck);
JIT_HELPER(_compressStringJ);
JIT_HELPER(_compressStringNoCheckJ);
JIT_HELPER(_andORString);
JIT_HELPER(_encodeUTF16Big);
JIT_HELPER(_encodeUTF16Little);
#endif /* OSX */

#ifdef J9VM_OPT_JAVA_CRYPTO_ACCELERATION
#if defined (OSX)
JIT_HELPER(doAESENCEncrypt);
JIT_HELPER(doAESENCDecrypt);
#else
JIT_HELPER(_doAESENCEncrypt);
JIT_HELPER(_doAESENCDecrypt);
#endif
#endif /* OSX */
#endif /* J9VM_OPT_JAVA_CRYPTO_ACCELERATION */

JIT_HELPER(interpreterEAXStaticGlue);
JIT_HELPER(interpreterRAXStaticGlue);
Expand Down Expand Up @@ -1159,9 +1208,13 @@ void initializeCodeRuntimeHelperTable(J9JITConfig *jitConfig, char isSMP)
SET(TR_X86interpreterSyncDoubleStaticGlue, (void *)interpreterSyncXMM0DStaticGlue, TR_Helper);
SET(TR_X86interpreterAddressStaticGlue, (void *)interpreterRAXStaticGlue, TR_Helper);
SET(TR_X86interpreterSyncAddressStaticGlue, (void *)interpreterSyncRAXStaticGlue, TR_Helper);

#if defined(OSX)
SET(TR_AMD64floatRemainder, (void *)SSEfloatRemainder, TR_Helper);
SET(TR_AMD64doubleRemainder, (void *)SSEdoubleRemainder, TR_Helper);
#else
SET(TR_AMD64floatRemainder, (void *)_SSEfloatRemainder, TR_Helper);
SET(TR_AMD64doubleRemainder, (void *)_SSEdoubleRemainder, TR_Helper);
#endif /* OSX */

SET(TR_AMD64icallVMprJavaSendVirtual0, (void *)icallVMprJavaSendVirtual0, TR_Helper);
SET(TR_AMD64icallVMprJavaSendVirtual1, (void *)icallVMprJavaSendVirtual1, TR_Helper);
Expand All @@ -1171,7 +1224,22 @@ void initializeCodeRuntimeHelperTable(J9JITConfig *jitConfig, char isSMP)
SET(TR_AMD64icallVMprJavaSendVirtualD, (void *)icallVMprJavaSendVirtualD, TR_Helper);

SET(TR_AMD64jitCollapseJNIReferenceFrame, (void *)jitCollapseJNIReferenceFrame, TR_Helper);

#if defined(OSX)
SET(TR_AMD64compressString, (void *)compressString, TR_Helper);
SET(TR_AMD64compressStringNoCheck, (void *)compressStringNoCheck, TR_Helper);
SET(TR_AMD64compressStringJ, (void *)compressStringJ, TR_Helper);
SET(TR_AMD64compressStringNoCheckJ, (void *)compressStringNoCheckJ, TR_Helper);
SET(TR_AMD64andORString, (void *)andORString, TR_Helper);
SET(TR_AMD64arrayTranslateTRTO, (void *)arrayTranslateTRTO, TR_Helper);
SET(TR_AMD64arrayTranslateTROTNoBreak, (void *)arrayTranslateTROTNoBreak, TR_Helper);
SET(TR_AMD64arrayTranslateTROT, (void *)arrayTranslateTROT, TR_Helper);
SET(TR_AMD64encodeUTF16Big, (void *)encodeUTF16Big, TR_Helper);
SET(TR_AMD64encodeUTF16Little, (void *)encodeUTF16Little, TR_Helper);
#ifdef J9VM_OPT_JAVA_CRYPTO_ACCELERATION
SET(TR_AMD64doAESENCEncrypt, (void *)doAESENCEncrypt, TR_Helper);
SET(TR_AMD64doAESENCDecrypt, (void *)doAESENCDecrypt, TR_Helper);
#endif /* J9VM_OPT_JAVA_CRYPTO_ACCELERATION */
#else /* OSX */
SET(TR_AMD64compressString, (void *)_compressString, TR_Helper);
SET(TR_AMD64compressStringNoCheck, (void *)_compressStringNoCheck, TR_Helper);
SET(TR_AMD64compressStringJ, (void *)_compressStringJ, TR_Helper);
Expand All @@ -1185,7 +1253,8 @@ void initializeCodeRuntimeHelperTable(J9JITConfig *jitConfig, char isSMP)
#ifdef J9VM_OPT_JAVA_CRYPTO_ACCELERATION
SET(TR_AMD64doAESENCEncrypt, (void *)_doAESENCEncrypt, TR_Helper);
SET(TR_AMD64doAESENCDecrypt, (void *)_doAESENCDecrypt, TR_Helper);
#endif
#endif /* J9VM_OPT_JAVA_CRYPTO_ACCELERATION */
#endif /* OSX */
#if defined(LINUX)
SET(TR_AMD64clockGetTime, (void *)clock_gettime, TR_System);
#endif
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/runtime/asmprotos.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C" {
#else /* J9VM_ENV_LITTLE_ENDIAN */
#define JIT_HELPER(x) extern "C" void * x
#endif /* J9VM_ENV_LITTLE_ENDIAN */
#elif defined(MVS) || defined(LINUX) || defined(J9ZOS390) || defined (J9HAMMER) || defined (WINDOWS)
#elif defined(MVS) || defined(LINUX) || defined(J9ZOS390) || defined (J9HAMMER) || defined (WINDOWS) || defined (OSX)
#define JIT_HELPER(x) extern "C" void x()
#elif defined(NEUTRINO)
#define JIT_HELPER(x) extern "C" char* x[]
Expand Down