Skip to content
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: 8 additions & 0 deletions Source/JavaScriptCore/assembler/AbstractMacroAssembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,14 @@ class AbstractMacroAssembler : public AbstractMacroAssemblerBase {
{
}

#if OS(WINDOWS)
template<typename ReturnType, typename... Arguments>
explicit TrustedImmPtr(ReturnType(SYSV_ABI *value)(Arguments...))
: m_value(reinterpret_cast<void*>(value))
{
}
#endif

explicit constexpr TrustedImmPtr(std::nullptr_t)
{
}
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/assembler/MacroAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void MacroAssembler::jitAssert(const ScopedLambda<Jump(void)>& functor)
}
}

static void stdFunctionCallback(Probe::Context& context)
static void SYSV_ABI stdFunctionCallback(Probe::Context& context)
{
auto func = context.arg<const Function<void(Probe::Context&)>*>();
(*func)(context);
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/assembler/MacroAssembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ enum class SavedFPWidth {
};

class Context;
typedef void (*Function)(Context&);
typedef void SYSV_ABI (*Function)(Context&);

} // namespace Probe

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void printMemory(PrintStream& out, Context& context)
out.print("\n");
}

void printCallback(Probe::Context& probeContext)
void SYSV_ABI printCallback(Probe::Context& probeContext)
{
auto& out = WTF::dataFile();
PrintRecordList& list = *probeContext.arg<PrintRecordList*>();
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/assembler/MacroAssemblerPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ struct Printer<MemWord<IntType>> : public Printer<Memory> {
{ }
};

void printCallback(Probe::Context&);
void SYSV_ABI printCallback(Probe::Context&);

} // namespace Printer

Expand Down
47 changes: 0 additions & 47 deletions Source/JavaScriptCore/assembler/MacroAssemblerX86_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,57 +195,10 @@ class MacroAssemblerX86_64 : public MacroAssemblerX86Common {
store8(reg, Address(scratchRegister()));
}

#if OS(WINDOWS)
Call callWithUGPRPair(PtrTag)
{
DataLabelPtr label = moveWithPatch(TrustedImmPtr(nullptr), scratchRegister());
Call result = Call(m_assembler.call(scratchRegister()), Call::Linkable);
// Copy the return value into rax and rdx.
load64(Address(X86Registers::eax, sizeof(int64_t)), X86Registers::edx);
load64(Address(X86Registers::eax), X86Registers::eax);

ASSERT_UNUSED(label, differenceBetween(label, result) == REPATCH_OFFSET_CALL_R11);
return result;
}

void callWithUGPRPair(Address address, PtrTag)
{
m_assembler.call_m(address.offset, address.base);
// Copy the return value into rax and rdx.
load64(Address(X86Registers::eax, sizeof(int64_t)), X86Registers::edx);
load64(Address(X86Registers::eax), X86Registers::eax);
}
#endif

Call call(PtrTag)
{
#if OS(WINDOWS)
// JIT relies on the CallerFrame (frame pointer) being put on the stack,
// On Win64 we need to manually copy the frame pointer to the stack, since MSVC may not maintain a frame pointer on 64-bit.
// See http://msdn.microsoft.com/en-us/library/9z1stfyw.aspx where it's stated that rbp MAY be used as a frame pointer.
store64(X86Registers::ebp, Address(X86Registers::esp, -16));

// On Windows we need to copy the arguments that don't fit in registers to the stack location where the callee expects to find them.
// We don't know the number of arguments at this point, so the arguments (5, 6, ...) should always be copied.

// Copy argument 5
load64(Address(X86Registers::esp, 4 * sizeof(int64_t)), scratchRegister());
store64(scratchRegister(), Address(X86Registers::esp, -4 * static_cast<int32_t>(sizeof(int64_t))));

// Copy argument 6
load64(Address(X86Registers::esp, 5 * sizeof(int64_t)), scratchRegister());
store64(scratchRegister(), Address(X86Registers::esp, -3 * static_cast<int32_t>(sizeof(int64_t))));

// We also need to allocate the shadow space on the stack for the 4 parameter registers.
// Also, we should allocate 16 bytes for the frame pointer, and return address (not populated).
// In addition, we need to allocate 16 bytes for two more parameters, since the call can have up to 6 parameters.
sub64(TrustedImm32(8 * sizeof(int64_t)), X86Registers::esp);
#endif
DataLabelPtr label = moveWithPatch(TrustedImmPtr(nullptr), scratchRegister());
Call result = Call(m_assembler.call(scratchRegister()), Call::Linkable);
#if OS(WINDOWS)
add64(TrustedImm32(8 * sizeof(int64_t)), X86Registers::esp);
#endif
ASSERT_UNUSED(label, differenceBetween(label, result) == REPATCH_OFFSET_CALL_R11);
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/assembler/ProbeContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class Context {
friend JS_EXPORT_PRIVATE void* probeStateForContext(Context&); // Not for general use. This should only be for writing tests.
};

extern "C" void executeJSCJITProbe(State*) REFERENCED_FROM_ASM WTF_INTERNAL;
extern "C" void SYSV_ABI executeJSCJITProbe(State*) REFERENCED_FROM_ASM WTF_INTERNAL;

} // namespace Probe
} // namespace JSC
Expand Down
3 changes: 2 additions & 1 deletion Source/JavaScriptCore/bytecode/CodeBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,8 @@ class CodeBlock : public JSCell {
};
/* This check is for normal Release builds; ASSERT_ENABLED changes the size. */
#if !ASSERT_ENABLED
static_assert(sizeof(CodeBlock) <= 232, "Keep it small for memory saving");
// TODO Figure out why this went up on my machine
static_assert(sizeof(CodeBlock) <= 240, "Keep it small for memory saving");
#endif

template <typename ExecutableType>
Expand Down
10 changes: 2 additions & 8 deletions Source/JavaScriptCore/bytecode/InlineCacheCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,9 +1141,7 @@ ScratchRegisterAllocator InlineCacheCompiler::makeDefaultScratchAllocator(GPRReg
return allocator;
}

#if CPU(X86_64) && OS(WINDOWS)
static constexpr size_t prologueSizeInBytesDataIC = 5;
#elif CPU(X86_64)
#if CPU(X86_64)
static constexpr size_t prologueSizeInBytesDataIC = 1;
#elif CPU(ARM64E)
static constexpr size_t prologueSizeInBytesDataIC = 8;
Expand All @@ -1166,11 +1164,7 @@ void InlineCacheCompiler::emitDataICPrologue(CCallHelpers& jit)
size_t startOffset = jit.debugOffset();
#endif

#if CPU(X86_64) && OS(WINDOWS)
static_assert(maxFrameExtentForSlowPathCall);
jit.push(CCallHelpers::framePointerRegister);
jit.subPtr(CCallHelpers::TrustedImm32(maxFrameExtentForSlowPathCall), CCallHelpers::stackPointerRegister);
#elif CPU(X86_64)
#if CPU(X86_64)
static_assert(!maxFrameExtentForSlowPathCall);
jit.push(CCallHelpers::framePointerRegister);
#elif CPU(ARM64)
Expand Down
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/dfg/DFGArithMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ enum class UnaryType : uint32_t {
#undef DFG_ARITH_UNARY_ENUM
};

using UnaryFunction = double(JIT_OPERATION_ATTRIBUTES*)(double);
using UnaryOperation = OperationReturnType<double>(JIT_OPERATION_ATTRIBUTES*)(JSGlobalObject*, EncodedJSValue);
using UnaryFunction = double(JIT_OPERATION_ATTRIBUTES *)(double);
using UnaryOperation = OperationReturnType<double>(JIT_OPERATION_ATTRIBUTES *)(JSGlobalObject*, EncodedJSValue);

} // namespace Arith

Expand Down
18 changes: 0 additions & 18 deletions Source/JavaScriptCore/dfg/DFGJITCompiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,6 @@ class JITCompiler : public CCallHelpers {
return functionCall;
}

#if OS(WINDOWS) && CPU(X86_64)
template<PtrTag tag>
requires (tag != NoPtrTag)
JITCompiler::Call appendCallWithUGPRPair(const CodePtr<tag> function)
{
Call functionCall = callWithUGPRPair(OperationPtrTag);
m_calls.append(CallLinkRecord(functionCall, function.template retagged<OperationPtrTag>()));
return functionCall;
}
#endif

Call appendOperationCall(const CodePtr<OperationPtrTag> function)
{
Call functionCall = call(OperationPtrTag);
Expand All @@ -178,13 +167,6 @@ class JITCompiler : public CCallHelpers {
call(address, OperationPtrTag);
}

#if OS(WINDOWS) && CPU(X86_64)
void appendCallWithUGPRPair(CCallHelpers::Address address)
{
callWithUGPRPair(address, OperationPtrTag);
}
#endif

void exceptionJumpWithCallFrameRollback();

OSRExitCompilationInfo& appendExitInfo(MacroAssembler::JumpList jumpsToFail = MacroAssembler::JumpList())
Expand Down
22 changes: 0 additions & 22 deletions Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -1209,31 +1209,13 @@ class SpeculativeJIT : public JITCompiler {
return Base::appendCall(function);
}

#if OS(WINDOWS) && CPU(X86_64)
JITCompiler::Call appendCallWithUGPRPair(const CodePtr<OperationPtrTag> function)
{
prepareForExternalCall();
emitStoreCodeOrigin(m_currentNode->origin.semantic);
return Base::appendCallWithUGPRPair(function);
}
#endif

void appendCall(Address address)
{
prepareForExternalCall();
emitStoreCodeOrigin(m_currentNode->origin.semantic);
Base::appendCall(address);
}

#if OS(WINDOWS) && CPU(X86_64)
void appendCallWithUGPRPair(Address address)
{
prepareForExternalCall();
emitStoreCodeOrigin(m_currentNode->origin.semantic);
Base::appendCallWithUGPRPair(address);
}
#endif

JITCompiler::Call appendOperationCall(const CodePtr<OperationPtrTag> function)
{
prepareForExternalCall();
Expand All @@ -1244,11 +1226,7 @@ class SpeculativeJIT : public JITCompiler {
// FIXME: We can remove this when we don't support MSVC since on clang-cl we could use systemV ABI for JIT operations.
JITCompiler::Call appendCallSetResult(const CodePtr<OperationPtrTag> function, GPRReg result1, GPRReg result2)
{
#if OS(WINDOWS) && CPU(X86_64)
JITCompiler::Call call = appendCallWithUGPRPair(function);
#else
JITCompiler::Call call = appendCall(function);
#endif
setupResults(result1, result2);
return call;
}
Expand Down
1 change: 1 addition & 0 deletions Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,7 @@ void SpeculativeJIT::emitCall(Node* node)

if (isDirect) {
ASSERT(!m_graph.m_plan.isUnlinked());
// FIXME: Could this be done after sysv_abi?
#if !OS(WINDOWS)
Edge calleeEdge = m_graph.child(node, 0);
JSGlobalObject* calleeScope = nullptr;
Expand Down
9 changes: 9 additions & 0 deletions Source/JavaScriptCore/interpreter/CallFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,22 @@ using JSInstruction = BaseInstruction<JSOpcodeTraits>;
JS_EXPORT_PRIVATE bool isFromJSCode(void* returnAddress);

#if USE(BUILTIN_FRAME_ADDRESS)
#if OS(WINDOWS)
// On Windows, __builtin_frame_address(1) doesn't work, it returns __builtin_frame_address(0)
// We can't use __builtin_frame_address(0) either, as if the stack pointer is decremented
// then __builtin_frame_address(0) points at the first empty home space.
// Could be implemented on Windows with __builtin_stack_address() once implemented in clang,
// as that returns the stack pointer at the time of function entry.
#error "Not implemented on platform https://bugs.webkit.org/show_bug.cgi?id=275567"
#else // !OS(WINDOWS)
// FIXME (see rdar://72897291): Work around a Clang bug where __builtin_return_address()
// sometimes gives us a signed pointer, and sometimes does not.
#define DECLARE_CALL_FRAME(vm) \
({ \
ASSERT(JSC::isFromJSCode(removeCodePtrTag<void*>(__builtin_return_address(0)))); \
bitwise_cast<JSC::CallFrame*>(__builtin_frame_address(1)); \
})
#endif // !OS(WINDOWS)
#else
#define DECLARE_CALL_FRAME(vm) ((vm).topCallFrame)
#endif
Expand Down
43 changes: 1 addition & 42 deletions Source/JavaScriptCore/jit/CCallHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@

namespace JSC {

#if OS(WINDOWS) && CPU(X86_64)
#define POKE_ARGUMENT_OFFSET 4
#else
#define POKE_ARGUMENT_OFFSET 0
Copy link
Contributor

Choose a reason for hiding this comment

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

You can prolly just get rid of this define either now or in a later patch.

#endif

class CallFrame;
class Structure;
Expand Down Expand Up @@ -304,13 +300,8 @@ class CCallHelpers : public AssemblyHelpers {
return ArgCollection<numGPRArgs, numGPRSources, numFPRArgs, numFPRSources, numCrossSources, extraGPRArgs, nonArgGPRs, extraPoke + 1>(*this);
}

#if OS(WINDOWS) && CPU(X86_64)
unsigned argCount(GPRReg) { return numGPRArgs + numFPRArgs; }
unsigned argCount(FPRReg) { return numGPRArgs + numFPRArgs; }
#else
unsigned argCount(GPRReg) { return numGPRArgs + extraGPRArgs; }
unsigned argCount(FPRReg) { return numFPRArgs; }
#endif

// store GPR -> GPR assignments
std::array<GPRReg, GPRInfo::numberOfRegisters> gprSources;
Expand Down Expand Up @@ -354,11 +345,10 @@ class CCallHelpers : public AssemblyHelpers {

currentGPRArgument += extraGPRArgs;
currentFPRArgument -= numCrossSources;
#if !(OS(WINDOWS) && CPU(X86_64))

IGNORE_WARNINGS_BEGIN("type-limits")
ASSERT(currentGPRArgument >= GPRInfo::numberOfArgumentRegisters || currentFPRArgument >= FPRInfo::numberOfArgumentRegisters);
IGNORE_WARNINGS_END
#endif

unsigned pokeOffset = POKE_ARGUMENT_OFFSET + extraPoke;
pokeOffset += std::max(currentGPRArgument, numberOfGPArgumentRegisters) - numberOfGPArgumentRegisters;
Expand Down Expand Up @@ -401,22 +391,14 @@ class CCallHelpers : public AssemblyHelpers {
{
using InfoType = InfoTypeForReg<RegType>;
unsigned numArgRegisters = InfoType::numberOfArgumentRegisters;
#if OS(WINDOWS) && CPU(X86_64)
unsigned currentArgCount = argSourceRegs.argCount(arg) + (std::is_same<RESULT_TYPE, UGPRPair>::value ? 1 : 0);
#else
unsigned currentArgCount = argSourceRegs.argCount(arg);
#endif
if (currentArgCount < numArgRegisters) {
auto updatedArgSourceRegs = argSourceRegs.pushRegArg(arg, InfoType::toArgumentRegister(currentArgCount));
setupArgumentsImpl<OperationType>(updatedArgSourceRegs, args...);
return;
}

#if OS(WINDOWS) && CPU(X86_64)
pokeForArgument(arg, numGPRArgs + (std::is_same<RESULT_TYPE, UGPRPair>::value ? 1 : 0), numFPRArgs, numCrossSources, extraGPRArgs, nonArgGPRs, extraPoke);
#else
pokeForArgument(arg, numGPRArgs, numFPRArgs, numCrossSources, extraGPRArgs, nonArgGPRs, extraPoke);
#endif
setupArgumentsImpl<OperationType>(argSourceRegs.addStackArg(arg), args...);
}

Expand Down Expand Up @@ -568,22 +550,14 @@ class CCallHelpers : public AssemblyHelpers {
// gross so it's probably better to do that marshalling before the call operation...
static_assert(!std::is_floating_point<CURRENT_ARGUMENT_TYPE>::value, "We don't support immediate floats/doubles in setupArguments");
auto numArgRegisters = GPRInfo::numberOfArgumentRegisters;
#if OS(WINDOWS) && CPU(X86_64)
auto currentArgCount = numGPRArgs + numFPRArgs + (std::is_same<RESULT_TYPE, UGPRPair>::value ? 1 : 0);
#else
auto currentArgCount = numGPRArgs + extraGPRArgs;
#endif
if (currentArgCount < numArgRegisters) {
setupArgumentsImpl<OperationType>(argSourceRegs.addGPRArg(), args...);
move(arg, GPRInfo::toArgumentRegister(currentArgCount));
return;
}

#if OS(WINDOWS) && CPU(X86_64)
pokeForArgument(arg, numGPRArgs + (std::is_same<RESULT_TYPE, UGPRPair>::value ? 1 : 0), numFPRArgs, numCrossSources, extraGPRArgs, nonArgGPRs, extraPoke);
#else
pokeForArgument(arg, numGPRArgs, numFPRArgs, numCrossSources, extraGPRArgs, nonArgGPRs, extraPoke);
#endif
setupArgumentsImpl<OperationType>(argSourceRegs.addGPRArg(), args...);
}

Expand Down Expand Up @@ -632,23 +606,15 @@ class CCallHelpers : public AssemblyHelpers {
{
static_assert(!std::is_floating_point<CURRENT_ARGUMENT_TYPE>::value, "We don't support immediate floats/doubles in setupArguments");
auto numArgRegisters = GPRInfo::numberOfArgumentRegisters;
#if OS(WINDOWS) && CPU(X86_64)
auto currentArgCount = numGPRArgs + numFPRArgs + (std::is_same<RESULT_TYPE, UGPRPair>::value ? 1 : 0);
#else
auto currentArgCount = numGPRArgs + extraGPRArgs;
#endif
if (currentArgCount < numArgRegisters) {
setupArgumentsImpl<OperationType>(argSourceRegs.addGPRArg(), args...);
arg.materialize(*this, GPRInfo::toArgumentRegister(currentArgCount));
return;
}


#if OS(WINDOWS) && CPU(X86_64)
pokeForArgument(arg, numGPRArgs + (std::is_same<RESULT_TYPE, UGPRPair>::value ? 1 : 0), numFPRArgs, numCrossSources, extraGPRArgs, nonArgGPRs, extraPoke);
#else
pokeForArgument(arg, numGPRArgs, numFPRArgs, numCrossSources, extraGPRArgs, nonArgGPRs, extraPoke);
#endif
setupArgumentsImpl<OperationType>(argSourceRegs.addGPRArg(), args...);
}

Expand Down Expand Up @@ -715,13 +681,6 @@ class CCallHelpers : public AssemblyHelpers {
static_assert(!numCrossSources, "shouldn't be used on this architecture.");

setupStubArgs<numFPRSources, FPRReg>(clampArrayToSize<numFPRSources, FPRReg>(argSourceRegs.fprDestinations), clampArrayToSize<numFPRSources, FPRReg>(argSourceRegs.fprSources));

#if OS(WINDOWS) && CPU(X86_64)
if constexpr (std::is_same<RESULT_TYPE, UGPRPair>::value) {
unsigned pokeOffset = calculatePokeOffset(numGPRArgs + /* implicit first parameter */ 1, numFPRArgs, numCrossSources, extraGPRArgs, nonArgGPRs, extraPoke);
addPtr(TrustedImm32(pokeOffset * sizeof(CPURegister)), stackPointerRegister, GPRInfo::argumentGPR0);
}
#endif
}

template<typename OperationType, unsigned numGPRArgs, unsigned numGPRSources, unsigned numFPRArgs, unsigned numFPRSources, unsigned numCrossSources, unsigned extraGPRArgs, unsigned nonArgGPRs, unsigned extraPoke, typename... Args>
Expand Down
Loading