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

osx: JIT support #1744

Merged
merged 1 commit into from
Oct 27, 2016
Merged

osx: JIT support #1744

merged 1 commit into from
Oct 27, 2016

Conversation

obastemur
Copy link
Collaborator

This PR;

  • Enables JIT on macOS
  • Fixes / improvements to xplat exception handling

@obastemur
Copy link
Collaborator Author

@jianchun @curtisman review please.

void PDataManager::RegisterPdata(RUNTIME_FUNCTION* pdataStart, _In_ const ULONG_PTR functionStart, _In_ const ULONG_PTR functionEnd, _Out_ PVOID* pdataTable, ULONG entryCount, ULONG maxEntryCount)
void PDataManager::RegisterPdata(RUNTIME_FUNCTION* pdataStart,
_In_ const ULONG_PTR functionStart, _In_ const ULONG_PTR functionEnd,
_Out_ PVOID* pdataTable, ULONG entryCount, ULONG maxEntryCount)

Choose a reason for hiding this comment

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

nit: Should use 4-space indentation

}
}
}
DEFINE_DYNAMICPROFILEINFO_RECORDMODULUSOPTYPE_FNC

Choose a reason for hiding this comment

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

This approach looks weird. How about removing the "inline" keyword from old implementation instead?

@@ -12,6 +12,10 @@ CompileAssert(false)
#include "XDataAllocator.h"
#include "Core/DelayLoadLibrary.h"

#ifndef _WIN32

Choose a reason for hiding this comment

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

nit: #ifndef ... not needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed not needed. However this is an xplat header file [for now]

Choose a reason for hiding this comment

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

I seem to recall you had this same include elsewhere without #ifndef _WIN32.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From PlatformAgnostic maybe ? My approach is to keep enabling anything non-Windows on lib files to prevent Full project breaks.

} \
Assert(OpCodeUtil::EncodedSize((Js::OpCode)op, SmallLayout) \
== (currentOffset - offset)); \
}

Choose a reason for hiding this comment

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

Similar to other comment, putting the code to multiple places with a macro looks weird. Please try other cleaner solution e.g. moving the template instantiation to header file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed weird. Tried other things [i.e. remove inline / use it from header ].. Older Clang behaves strange :/ Actually, we already define those in multiple places (using include )

Choose a reason for hiding this comment

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

Tried simply removing inline fixes both cases: #1790

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see that, I do recall it fails on my test machine.. will take CI as the base and remove the inlines

--*/

#include "pal/dbgmsg.h"
SET_DEFAULT_DEBUG_CHANNEL(EXCEPT); // some headers have code with asserts, so do this first

Choose a reason for hiding this comment

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

I know nothing about these big changes in PAL. Did you work on these changes, or did you sync them to dotnet coreCLR latest?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some I had to update + sync to PAL.

extern void mac_fde_wrapper(const char *dataStart, mac_fde_reg_op reg_op)
{
for(const char *head = dataStart, *last = dataStart + CC_FDE_SIZE;
head != last;
Copy link

@jianchun jianchun Oct 17, 2016

Choose a reason for hiding this comment

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

I suggest avoid the last check. FDE is not of fixed size. The check may mislead some to think it is. The CIE/FDE data is guaranteed to terminate from the break in the loop body below. If for any reason the data is wrong and does not, it makes no difference whether it hangs/crashes here or crashes later on. Hanging/crashing here is better in my opinion because it is closer to the source of problem.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no guarantee here for a meaningful hang or crash. Indeed FDE is not a fixed size and shouldn't be bigger than the defined size above. + if it is bigger, see assert below

Choose a reason for hiding this comment

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

My biggest complain is about the misleading for loop. It reads as if it would loop some fixed size and end at last. Actually no, it ends at a terminator and break from inside the loop body.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed it does and I see your complain. I would rather add a comment there instead of removing it.

Choose a reason for hiding this comment

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

I prefer self-explanatory code instead of comment. head != last is meaningless. It is almost always true.

{
const char *op = head;
// Get Length of record [ Read 4 bytes ]
const uint32_t* op_data = (const uint32_t*)op;

Choose a reason for hiding this comment

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

const uint32_t* op_data [](start = 8, length = 23)

Why not const uint32_t length = ...?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

could be... op -> cast to -> op_data?

Choose a reason for hiding this comment

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

I meant the pointer op_data was not as straightforward. Just do const uint32_t length = *(const uint32_t*)op; and use length.

break;
}
// if it's not 0xffffffff,
// there we have the length of the CIE or FDE record.

Choose a reason for hiding this comment

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

nit: Comment is not very clear (as code not checking 0xFFFFFFFF). We actually ignored 0xFFFFFFFF which identifies extended length. Our records are small so we never need extended length.

}
// if it's not 0xffffffff,
// there we have the length of the CIE or FDE record.
head += 4; // get next

Choose a reason for hiding this comment

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

head += 4; // get next [](start = 8, length = 22)

nit: Please comment it is to read next 4 bytes and non zero value identifies FDE (zero is CIE).

extern "C" void __register_frame(const void* ehframe);
extern "C" void __deregister_frame(const void* ehframe);

#if defined(_AMD64_) && !defined(DISABLE_JIT)

Choose a reason for hiding this comment

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

!defined(DISABLE_JIT) [](start = 24, length = 21)

Please use ENABLE_NATIVE_CODEGEN instead of !defined(DISABLE_JIT). The former is used more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is there a reason we define DISABLE_JIT in that case?

Choose a reason for hiding this comment

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

ENABLE_NATIVE_CODEGEN existed from the beginning of this project and used everywhere. DISABLE_JIT used rarely (haven't checked so not sure about history, might be added recently, maybe we should not have added it). I prefer the former for overall consistency.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I recall DISABLE_JIT is used while enabling JIT on linux. Since we have it and naming explains the intention, I prefer keeping it. If we want to remove them all, that's something else.

Choose a reason for hiding this comment

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

I'm ok if you insist. Just want to note that another reason I prefer ENABLE_NATIVE_CODEGEN is it is positive. Easier to read and understand than double negative !defined(DISABLE_JIT).

Copy link
Contributor

Choose a reason for hiding this comment

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

Just noticed this part. ENABLE_NATIVE_CODEGEN is a subset of DISABLE_JIT. ENABLE_NATIVE_CODEGEN is generally meant for JIT-related code directly. DISABLE_JIT was added as part of doing the Interpreter-only version of ChakraCore last year- it implies !ENABLE_NATIVE_CODEGEN but also disables other things like dynamic interpreter thunks, interpreter profiling etc.

Choose a reason for hiding this comment

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

Thanks @digitalinfinity for explanation, now I understand. !defined(DISABLE_JIT) here is fine to me.

typedef void(*mac_fde_reg_op)(const void*addr);
void mac_fde_wrapper(const char *dataStart, mac_fde_reg_op reg_op);
#define __REGISTER_FRAME(addr) mac_fde_wrapper((char*)addr, __register_frame)
#define __DEREGISTER_FRAME(addr) mac_fde_wrapper((char*)addr, __deregister_frame)

Choose a reason for hiding this comment

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

nit: Use (const char*)addr to be consistent with signature.

@obastemur
Copy link
Collaborator Author

@dotnet-bot test Ubuntu ubuntu_linux_debug_static

@obastemur
Copy link
Collaborator Author

@dotnet-bot test Ubuntu ubuntu_linux_test_static

@obastemur
Copy link
Collaborator Author

@dotnet-bot test Ubuntu ubuntu_linux_release

This PR;
- Enables JIT on macOS
- Fixes / improvements to xplat exception handling
}
else
{
divideTypeInfo[profileId] = divideTypeInfo[profileId].Merge(ValueType::Float);
divideTypeInfo[profileId] = divideTypeInfo[profileId]
.Merge(ValueType::Float);
}

Choose a reason for hiding this comment

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

nit: DynamicProfileInfo.cpp contains some formatting changes that are unnecessary (changes when you originally put them into a macro?).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

80 chars. since it is updated, left it.

// jmp _ZN2Js18JavascriptFunction17CallAsmJsFunctionIiEET_PNS_16RecyclableObjectEPFPvS4_NS_8CallInfoEzEjPS5_
//??$CallAsmJsFunction@T__m128@@@JavascriptFunction@Js@@SA?AT__m128@@PEAVRecyclableObject@1@PEAXIPEAPEAX@Z ENDP


Choose a reason for hiding this comment

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

nit: Why moving this section... here they are closer to next implementation.
Also you deleted __m128 version. Commented out currently, maybe needed in future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

osx linker. ordering issues. we add that easily when we need it. it is keep showing up on my auto searches as if I forgot that..

Copy link

@jianchun jianchun left a comment

Choose a reason for hiding this comment

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

@obastemur Thanks for making this change! Left 2 nit comments (can ignore).

@obastemur
Copy link
Collaborator Author

@jianchun Thanks for the review

@chakrabot chakrabot merged commit 4c410fd into chakra-core:master Oct 27, 2016
chakrabot pushed a commit that referenced this pull request Oct 27, 2016
Merge pull request #1744 from obastemur:xoj

This PR;
- Enables JIT on macOS
- Fixes / improvements to xplat exception handling
@obastemur obastemur deleted the xoj branch November 15, 2016 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants