haikuwebkit/Source/WTF/wtf/FunctionTraits.h

94 lines
3.2 KiB
C
Raw Permalink Normal View History

Meta-program setupArguments and callOperation https://bugs.webkit.org/show_bug.cgi?id=183263 Rubber-stamped by Filip Pizlo. Source/JavaScriptCore: This patch removes all the custom overrides of callOperation and setupArguments throughout the JITs. In their place there is a new setupArguments that marshalls the arguments into place based on the type of the operation's function pointer. There were a couple of design choices in the implementation of setupArguments: 1) We assume that no TrustedImm floating point values are passed. 2) If ExecState* is the first argument the callFrameRegister should be marshalled implicitly. 3) Types should not be implicitly converted (with the exception of DFG::RegisteredStructure -> Structure*) The new callOperation/setupArguments do their best to make sure it's hard to call a function with the wrong parameters. They will only try to pattern match if the types match up with the next passed argument. Additionally, the base case should static_assert of the number of inferred arguments does not match the arity of the operation's function pointer. * assembler/AbstractMacroAssembler.h: (JSC::AbstractMacroAssembler::TrustedImmPtr::TrustedImmPtr): (JSC::AbstractMacroAssembler::TrustedImmPtr::asPtr): * assembler/MacroAssembler.h: (JSC::MacroAssembler::poke): (JSC::MacroAssembler::move): * assembler/MacroAssemblerARM64.h: (JSC::MacroAssemblerARM64::swap): * assembler/MacroAssemblerX86.h: (JSC::MacroAssemblerX86::storeDouble): * assembler/MacroAssemblerX86Common.h: (JSC::MacroAssemblerX86Common::loadDouble): (JSC::MacroAssemblerX86Common::swap): (JSC::MacroAssemblerX86Common::move): * bytecode/AccessCase.cpp: (JSC::AccessCase::generateImpl): * bytecode/AccessCaseSnippetParams.cpp: (JSC::SlowPathCallGeneratorWithArguments::generateImpl): * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * dfg/DFGCallArrayAllocatorSlowPathGenerator.h: * dfg/DFGNode.h: * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::emitRestoreArguments): * dfg/DFGOSRExitCompilerCommon.cpp: (JSC::DFG::osrWriteBarrier): * dfg/DFGOperations.cpp: * dfg/DFGOperations.h: * dfg/DFGSlowPathGenerator.h: * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileArithDoubleUnaryOp): (JSC::DFG::SpeculativeJIT::compileArithMod): (JSC::DFG::SpeculativeJIT::compileArithRounding): (JSC::DFG::SpeculativeJIT::compileArithSqrt): (JSC::DFG::SpeculativeJIT::compileCreateActivation): (JSC::DFG::SpeculativeJIT::compileCallDOMGetter): (JSC::DFG::SpeculativeJIT::emitSwitchStringOnString): * dfg/DFGSpeculativeJIT.h: (JSC::DFG::SpeculativeJIT::TrustedImmPtr::TrustedImmPtr): (JSC::DFG::SpeculativeJIT::TrustedImmPtr::operator MacroAssembler::TrustedImm const): (JSC::DFG::SpeculativeJIT::initConstantInfo): (JSC::DFG::SpeculativeJIT::callOperation): (JSC::DFG::SpeculativeJIT::callOperationWithCallFrameRollbackOnException): (JSC::DFG::SpeculativeJIT::callCustomGetter): Deleted. * dfg/DFGSpeculativeJIT32_64.cpp: (JSC::DFG::SpeculativeJIT::cachedGetById): (JSC::DFG::SpeculativeJIT::cachedGetByIdWithThis): (JSC::DFG::SpeculativeJIT::cachedPutById): (JSC::DFG::SpeculativeJIT::emitCall): (JSC::DFG::SpeculativeJIT::compileContiguousPutByVal): (JSC::DFG::SpeculativeJIT::compile): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::emitCall): (JSC::DFG::SpeculativeJIT::compile): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstructVarargsSpread): (JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstructVarargs): (JSC::FTL::DFG::LowerDFGToB3::compileCallEval): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * ftl/FTLSlowPathCall.h: (JSC::FTL::callOperation): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::emitStoreStructureWithTypeInfo): * jit/CCallHelpers.cpp: (JSC::CCallHelpers::ensureShadowChickenPacket): * jit/CCallHelpers.h: (JSC::CCallHelpers::setupArgument): (JSC::CCallHelpers::setupStubArgs): (JSC::CCallHelpers::ArgCollection::ArgCollection): (JSC::CCallHelpers::ArgCollection::pushRegArg): (JSC::CCallHelpers::ArgCollection::addGPRArg): (JSC::CCallHelpers::ArgCollection::addStackArg): (JSC::CCallHelpers::ArgCollection::addPoke): (JSC::CCallHelpers::ArgCollection::argCount): (JSC::CCallHelpers::clampArrayToSize): (JSC::CCallHelpers::pokeForArgument): (JSC::CCallHelpers::marshallArgumentRegister): (JSC::CCallHelpers::setupArgumentsImpl): (JSC::CCallHelpers::std::is_integral<CURRENT_ARGUMENT_TYPE>::value): (JSC::CCallHelpers::std::is_pointer<CURRENT_ARGUMENT_TYPE>::value): (JSC::CCallHelpers::setupArguments): (JSC::CCallHelpers::prepareForTailCallSlow): (JSC::CCallHelpers::setupArgumentsWithExecState): Deleted. (JSC::CCallHelpers::resetCallArguments): Deleted. (JSC::CCallHelpers::addCallArgument): Deleted. (JSC::CCallHelpers::setupArgumentsExecState): Deleted. (JSC::CCallHelpers::setupTwoStubArgsGPR): Deleted. (JSC::CCallHelpers::setupThreeStubArgsGPR): Deleted. (JSC::CCallHelpers::setupFourStubArgsGPR): Deleted. (JSC::CCallHelpers::setupFiveStubArgsGPR): Deleted. (JSC::CCallHelpers::setupTwoStubArgsFPR): Deleted. (JSC::CCallHelpers::setupStubArguments): Deleted. (JSC::CCallHelpers::setupArgumentsWithExecStateForCallWithSlowPathReturnType): Deleted. (JSC::CCallHelpers::setupStubArguments134): Deleted. (JSC::CCallHelpers::setupStubArgsGPR): Deleted. * jit/FPRInfo.h: (JSC::toInfoFromReg): * jit/GPRInfo.h: (JSC::JSValueRegs::JSValueRegs): (JSC::toInfoFromReg): * jit/JIT.h: (JSC::JIT::callOperation): (JSC::JIT::callOperationWithProfile): (JSC::JIT::callOperationWithResult): (JSC::JIT::callOperationNoExceptionCheck): (JSC::JIT::callOperationWithCallFrameRollbackOnException): * jit/JITArithmetic.cpp: (JSC::JIT::emitMathICFast): (JSC::JIT::emitMathICSlow): * jit/JITArithmetic32_64.cpp: (JSC::JIT::emit_compareAndJumpSlow): * jit/JITCall32_64.cpp: (JSC::JIT::compileSetupVarargsFrame): * jit/JITInlines.h: (JSC::JIT::callOperation): Deleted. (JSC::JIT::callOperationNoExceptionCheck): Deleted. (JSC::JIT::callOperationWithCallFrameRollbackOnException): Deleted. * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_new_array_with_size): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emitSlow_op_instanceof): (JSC::JIT::emitSlow_op_instanceof_custom): (JSC::JIT::emit_op_set_function_name): (JSC::JIT::emitSlow_op_eq): (JSC::JIT::emitSlow_op_neq): (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_switch_imm): (JSC::JIT::emit_op_switch_char): (JSC::JIT::emit_op_switch_string): (JSC::JIT::emitSlow_op_has_indexed_property): * jit/JITOperations.cpp: * jit/JITOperations.h: * jit/JITPropertyAccess.cpp: (JSC::JIT::emitGetByValWithCachedId): (JSC::JIT::emitSlow_op_get_by_id): (JSC::JIT::emitSlow_op_get_by_id_with_this): (JSC::JIT::emitSlow_op_get_from_scope): * jit/JITPropertyAccess32_64.cpp: (JSC::JIT::emit_op_put_by_index): (JSC::JIT::emit_op_put_setter_by_id): (JSC::JIT::emit_op_put_getter_setter_by_id): (JSC::JIT::emit_op_put_getter_by_val): (JSC::JIT::emit_op_put_setter_by_val): (JSC::JIT::emit_op_del_by_id): (JSC::JIT::emit_op_del_by_val): (JSC::JIT::emitGetByValWithCachedId): (JSC::JIT::emitSlow_op_get_by_val): (JSC::JIT::emitPutByValWithCachedId): (JSC::JIT::emitSlow_op_put_by_val): (JSC::JIT::emitSlow_op_try_get_by_id): (JSC::JIT::emitSlow_op_get_by_id): (JSC::JIT::emitSlow_op_get_by_id_with_this): (JSC::JIT::emitSlow_op_put_by_id): (JSC::JIT::emitSlow_op_get_from_scope): * jit/RegisterSet.h: (JSC::RegisterSet::RegisterSet): * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::slowPathFor): * jsc.cpp: (GlobalObject::finishCreation): (functionBreakpoint): * runtime/JSCJSValue.h: * wasm/js/WasmToJS.cpp: (JSC::Wasm::wasmToJS): Source/WTF: Add a new function traits struct that provides interesting information about the provided function pointer. Right now it only provides information for function pointers, in theory we could also get it to work for other types. * WTF.xcodeproj/project.pbxproj: * wtf/Bitmap.h: (WTF::WordType>::Bitmap): * wtf/CMakeLists.txt: * wtf/FunctionTraits.h: Added. (WTF::slotsForCCallArgument): (WTF::computeCCallSlots): (WTF::FunctionTraits<Result): Canonical link: https://commits.webkit.org/199098@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229391 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-03-08 02:26:55 +00:00
/*
* Copyright (C) 2018 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <type_traits>
namespace WTF {
template<typename T>
struct FunctionTraits;
#if USE(JSVALUE32_64)
template<typename T>
static constexpr unsigned slotsForCCallArgument()
{
static_assert(!std::is_class<T>::value || sizeof(T) <= sizeof(void*), "This doesn't support complex structs.");
static_assert(sizeof(T) == 8 || sizeof(T) <= 4, "");
Meta-program setupArguments and callOperation https://bugs.webkit.org/show_bug.cgi?id=183263 Rubber-stamped by Filip Pizlo. Source/JavaScriptCore: This patch removes all the custom overrides of callOperation and setupArguments throughout the JITs. In their place there is a new setupArguments that marshalls the arguments into place based on the type of the operation's function pointer. There were a couple of design choices in the implementation of setupArguments: 1) We assume that no TrustedImm floating point values are passed. 2) If ExecState* is the first argument the callFrameRegister should be marshalled implicitly. 3) Types should not be implicitly converted (with the exception of DFG::RegisteredStructure -> Structure*) The new callOperation/setupArguments do their best to make sure it's hard to call a function with the wrong parameters. They will only try to pattern match if the types match up with the next passed argument. Additionally, the base case should static_assert of the number of inferred arguments does not match the arity of the operation's function pointer. * assembler/AbstractMacroAssembler.h: (JSC::AbstractMacroAssembler::TrustedImmPtr::TrustedImmPtr): (JSC::AbstractMacroAssembler::TrustedImmPtr::asPtr): * assembler/MacroAssembler.h: (JSC::MacroAssembler::poke): (JSC::MacroAssembler::move): * assembler/MacroAssemblerARM64.h: (JSC::MacroAssemblerARM64::swap): * assembler/MacroAssemblerX86.h: (JSC::MacroAssemblerX86::storeDouble): * assembler/MacroAssemblerX86Common.h: (JSC::MacroAssemblerX86Common::loadDouble): (JSC::MacroAssemblerX86Common::swap): (JSC::MacroAssemblerX86Common::move): * bytecode/AccessCase.cpp: (JSC::AccessCase::generateImpl): * bytecode/AccessCaseSnippetParams.cpp: (JSC::SlowPathCallGeneratorWithArguments::generateImpl): * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * dfg/DFGCallArrayAllocatorSlowPathGenerator.h: * dfg/DFGNode.h: * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::emitRestoreArguments): * dfg/DFGOSRExitCompilerCommon.cpp: (JSC::DFG::osrWriteBarrier): * dfg/DFGOperations.cpp: * dfg/DFGOperations.h: * dfg/DFGSlowPathGenerator.h: * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileArithDoubleUnaryOp): (JSC::DFG::SpeculativeJIT::compileArithMod): (JSC::DFG::SpeculativeJIT::compileArithRounding): (JSC::DFG::SpeculativeJIT::compileArithSqrt): (JSC::DFG::SpeculativeJIT::compileCreateActivation): (JSC::DFG::SpeculativeJIT::compileCallDOMGetter): (JSC::DFG::SpeculativeJIT::emitSwitchStringOnString): * dfg/DFGSpeculativeJIT.h: (JSC::DFG::SpeculativeJIT::TrustedImmPtr::TrustedImmPtr): (JSC::DFG::SpeculativeJIT::TrustedImmPtr::operator MacroAssembler::TrustedImm const): (JSC::DFG::SpeculativeJIT::initConstantInfo): (JSC::DFG::SpeculativeJIT::callOperation): (JSC::DFG::SpeculativeJIT::callOperationWithCallFrameRollbackOnException): (JSC::DFG::SpeculativeJIT::callCustomGetter): Deleted. * dfg/DFGSpeculativeJIT32_64.cpp: (JSC::DFG::SpeculativeJIT::cachedGetById): (JSC::DFG::SpeculativeJIT::cachedGetByIdWithThis): (JSC::DFG::SpeculativeJIT::cachedPutById): (JSC::DFG::SpeculativeJIT::emitCall): (JSC::DFG::SpeculativeJIT::compileContiguousPutByVal): (JSC::DFG::SpeculativeJIT::compile): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::emitCall): (JSC::DFG::SpeculativeJIT::compile): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstructVarargsSpread): (JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstructVarargs): (JSC::FTL::DFG::LowerDFGToB3::compileCallEval): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * ftl/FTLSlowPathCall.h: (JSC::FTL::callOperation): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::emitStoreStructureWithTypeInfo): * jit/CCallHelpers.cpp: (JSC::CCallHelpers::ensureShadowChickenPacket): * jit/CCallHelpers.h: (JSC::CCallHelpers::setupArgument): (JSC::CCallHelpers::setupStubArgs): (JSC::CCallHelpers::ArgCollection::ArgCollection): (JSC::CCallHelpers::ArgCollection::pushRegArg): (JSC::CCallHelpers::ArgCollection::addGPRArg): (JSC::CCallHelpers::ArgCollection::addStackArg): (JSC::CCallHelpers::ArgCollection::addPoke): (JSC::CCallHelpers::ArgCollection::argCount): (JSC::CCallHelpers::clampArrayToSize): (JSC::CCallHelpers::pokeForArgument): (JSC::CCallHelpers::marshallArgumentRegister): (JSC::CCallHelpers::setupArgumentsImpl): (JSC::CCallHelpers::std::is_integral<CURRENT_ARGUMENT_TYPE>::value): (JSC::CCallHelpers::std::is_pointer<CURRENT_ARGUMENT_TYPE>::value): (JSC::CCallHelpers::setupArguments): (JSC::CCallHelpers::prepareForTailCallSlow): (JSC::CCallHelpers::setupArgumentsWithExecState): Deleted. (JSC::CCallHelpers::resetCallArguments): Deleted. (JSC::CCallHelpers::addCallArgument): Deleted. (JSC::CCallHelpers::setupArgumentsExecState): Deleted. (JSC::CCallHelpers::setupTwoStubArgsGPR): Deleted. (JSC::CCallHelpers::setupThreeStubArgsGPR): Deleted. (JSC::CCallHelpers::setupFourStubArgsGPR): Deleted. (JSC::CCallHelpers::setupFiveStubArgsGPR): Deleted. (JSC::CCallHelpers::setupTwoStubArgsFPR): Deleted. (JSC::CCallHelpers::setupStubArguments): Deleted. (JSC::CCallHelpers::setupArgumentsWithExecStateForCallWithSlowPathReturnType): Deleted. (JSC::CCallHelpers::setupStubArguments134): Deleted. (JSC::CCallHelpers::setupStubArgsGPR): Deleted. * jit/FPRInfo.h: (JSC::toInfoFromReg): * jit/GPRInfo.h: (JSC::JSValueRegs::JSValueRegs): (JSC::toInfoFromReg): * jit/JIT.h: (JSC::JIT::callOperation): (JSC::JIT::callOperationWithProfile): (JSC::JIT::callOperationWithResult): (JSC::JIT::callOperationNoExceptionCheck): (JSC::JIT::callOperationWithCallFrameRollbackOnException): * jit/JITArithmetic.cpp: (JSC::JIT::emitMathICFast): (JSC::JIT::emitMathICSlow): * jit/JITArithmetic32_64.cpp: (JSC::JIT::emit_compareAndJumpSlow): * jit/JITCall32_64.cpp: (JSC::JIT::compileSetupVarargsFrame): * jit/JITInlines.h: (JSC::JIT::callOperation): Deleted. (JSC::JIT::callOperationNoExceptionCheck): Deleted. (JSC::JIT::callOperationWithCallFrameRollbackOnException): Deleted. * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_new_array_with_size): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emitSlow_op_instanceof): (JSC::JIT::emitSlow_op_instanceof_custom): (JSC::JIT::emit_op_set_function_name): (JSC::JIT::emitSlow_op_eq): (JSC::JIT::emitSlow_op_neq): (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_switch_imm): (JSC::JIT::emit_op_switch_char): (JSC::JIT::emit_op_switch_string): (JSC::JIT::emitSlow_op_has_indexed_property): * jit/JITOperations.cpp: * jit/JITOperations.h: * jit/JITPropertyAccess.cpp: (JSC::JIT::emitGetByValWithCachedId): (JSC::JIT::emitSlow_op_get_by_id): (JSC::JIT::emitSlow_op_get_by_id_with_this): (JSC::JIT::emitSlow_op_get_from_scope): * jit/JITPropertyAccess32_64.cpp: (JSC::JIT::emit_op_put_by_index): (JSC::JIT::emit_op_put_setter_by_id): (JSC::JIT::emit_op_put_getter_setter_by_id): (JSC::JIT::emit_op_put_getter_by_val): (JSC::JIT::emit_op_put_setter_by_val): (JSC::JIT::emit_op_del_by_id): (JSC::JIT::emit_op_del_by_val): (JSC::JIT::emitGetByValWithCachedId): (JSC::JIT::emitSlow_op_get_by_val): (JSC::JIT::emitPutByValWithCachedId): (JSC::JIT::emitSlow_op_put_by_val): (JSC::JIT::emitSlow_op_try_get_by_id): (JSC::JIT::emitSlow_op_get_by_id): (JSC::JIT::emitSlow_op_get_by_id_with_this): (JSC::JIT::emitSlow_op_put_by_id): (JSC::JIT::emitSlow_op_get_from_scope): * jit/RegisterSet.h: (JSC::RegisterSet::RegisterSet): * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::slowPathFor): * jsc.cpp: (GlobalObject::finishCreation): (functionBreakpoint): * runtime/JSCJSValue.h: * wasm/js/WasmToJS.cpp: (JSC::Wasm::wasmToJS): Source/WTF: Add a new function traits struct that provides interesting information about the provided function pointer. Right now it only provides information for function pointers, in theory we could also get it to work for other types. * WTF.xcodeproj/project.pbxproj: * wtf/Bitmap.h: (WTF::WordType>::Bitmap): * wtf/CMakeLists.txt: * wtf/FunctionTraits.h: Added. (WTF::slotsForCCallArgument): (WTF::computeCCallSlots): (WTF::FunctionTraits<Result): Canonical link: https://commits.webkit.org/199098@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229391 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-03-08 02:26:55 +00:00
// This assumes that all integral values are passed on the stack.
if (sizeof(T) == 8)
return 2;
return 1;
}
template<typename T>
static constexpr unsigned computeCCallSlots() { return slotsForCCallArgument<T>(); }
template<typename T, typename... Ts>
static constexpr std::enable_if_t<!!sizeof...(Ts), unsigned> computeCCallSlots() { return computeCCallSlots<Ts...>() + slotsForCCallArgument<T>(); }
#endif
template<typename Result, typename... Args>
struct FunctionTraits<Result(Args...)> {
using ResultType = Result;
static constexpr bool hasResult = !std::is_same<ResultType, void>::value;
static constexpr std::size_t arity = sizeof...(Args);
template <std::size_t n, typename = std::enable_if_t<(n < arity)>>
using ArgumentType = typename std::tuple_element<n, std::tuple<Args...>>::type;
using ArgumentTypes = std::tuple<Args...>;
#if USE(JSVALUE64)
static constexpr unsigned cCallArity() { return arity; }
#else
static constexpr unsigned cCallArity() { return computeCCallSlots<Args...>(); }
#endif // USE(JSVALUE64)
};
template<typename Result, typename... Args>
struct FunctionTraits<Result(*)(Args...)> : public FunctionTraits<Result(Args...)> {
};
FullGCActivityCallback should use the percentage of pages uncompressed in RAM to determine deferral. https://bugs.webkit.org/show_bug.cgi?id=224817 Reviewed by Filip Pizlo. Source/JavaScriptCore: Right now we try to determine if too many pages are paged out by dereferencing them and bailing out of the GC if we go over a deadline. While this works if the only goal is to avoid causing extensive thrashing on spinny disks (HDD), it doesn't prevent thrashing when access to disk is fast (e.g. SSD). This is because on fast disks the proportional time to load the memory from disk is much lower. Additionally, on SSDs in particular we don't want to load the pages into RAM then bail as that will force a different page onto disk, increasing wear. This patch switches to asking the OS if each MarkedBlock is paged out. Then if we are over a threshold we wait until we would have GC'd anyway. This patch uses the (maxVMGrowthFactor - 1) as the percentage of "slow" pages (paged out or compressed) needed to defer the GC. The idea behind that threshold is that if we add that many pages then the same number of pages would be forced out of RAM for us to do a GC anyway (in the limit). * heap/BlockDirectory.cpp: (JSC::BlockDirectory::updatePercentageOfPagedOutPages): (JSC::BlockDirectory::isPagedOut): Deleted. * heap/BlockDirectory.h: * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): * heap/Heap.cpp: (JSC::Heap::isPagedOut): * heap/Heap.h: * heap/MarkedSpace.cpp: (JSC::MarkedSpace::isPagedOut): * heap/MarkedSpace.h: * runtime/OptionsList.h: Source/WebKit: Add mincore to the acceptable syscall list. * WebProcess/com.apple.WebProcess.sb.in: Source/WTF: Add a noexcept flavor of FunctionTraits. On Linux mincore (and probably other syscalls) are marked noexcept so the existing overloads don't work. * wtf/FunctionTraits.h: Canonical link: https://commits.webkit.org/236804@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@276324 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-04-20 22:42:05 +00:00
template<typename Result, typename... Args>
struct FunctionTraits<Result(Args...) noexcept> : public FunctionTraits<Result(Args...)> {
};
template<typename Result, typename... Args>
struct FunctionTraits<Result(*)(Args...) noexcept> : public FunctionTraits<Result(Args...)> {
};
Meta-program setupArguments and callOperation https://bugs.webkit.org/show_bug.cgi?id=183263 Rubber-stamped by Filip Pizlo. Source/JavaScriptCore: This patch removes all the custom overrides of callOperation and setupArguments throughout the JITs. In their place there is a new setupArguments that marshalls the arguments into place based on the type of the operation's function pointer. There were a couple of design choices in the implementation of setupArguments: 1) We assume that no TrustedImm floating point values are passed. 2) If ExecState* is the first argument the callFrameRegister should be marshalled implicitly. 3) Types should not be implicitly converted (with the exception of DFG::RegisteredStructure -> Structure*) The new callOperation/setupArguments do their best to make sure it's hard to call a function with the wrong parameters. They will only try to pattern match if the types match up with the next passed argument. Additionally, the base case should static_assert of the number of inferred arguments does not match the arity of the operation's function pointer. * assembler/AbstractMacroAssembler.h: (JSC::AbstractMacroAssembler::TrustedImmPtr::TrustedImmPtr): (JSC::AbstractMacroAssembler::TrustedImmPtr::asPtr): * assembler/MacroAssembler.h: (JSC::MacroAssembler::poke): (JSC::MacroAssembler::move): * assembler/MacroAssemblerARM64.h: (JSC::MacroAssemblerARM64::swap): * assembler/MacroAssemblerX86.h: (JSC::MacroAssemblerX86::storeDouble): * assembler/MacroAssemblerX86Common.h: (JSC::MacroAssemblerX86Common::loadDouble): (JSC::MacroAssemblerX86Common::swap): (JSC::MacroAssemblerX86Common::move): * bytecode/AccessCase.cpp: (JSC::AccessCase::generateImpl): * bytecode/AccessCaseSnippetParams.cpp: (JSC::SlowPathCallGeneratorWithArguments::generateImpl): * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * dfg/DFGCallArrayAllocatorSlowPathGenerator.h: * dfg/DFGNode.h: * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::emitRestoreArguments): * dfg/DFGOSRExitCompilerCommon.cpp: (JSC::DFG::osrWriteBarrier): * dfg/DFGOperations.cpp: * dfg/DFGOperations.h: * dfg/DFGSlowPathGenerator.h: * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileArithDoubleUnaryOp): (JSC::DFG::SpeculativeJIT::compileArithMod): (JSC::DFG::SpeculativeJIT::compileArithRounding): (JSC::DFG::SpeculativeJIT::compileArithSqrt): (JSC::DFG::SpeculativeJIT::compileCreateActivation): (JSC::DFG::SpeculativeJIT::compileCallDOMGetter): (JSC::DFG::SpeculativeJIT::emitSwitchStringOnString): * dfg/DFGSpeculativeJIT.h: (JSC::DFG::SpeculativeJIT::TrustedImmPtr::TrustedImmPtr): (JSC::DFG::SpeculativeJIT::TrustedImmPtr::operator MacroAssembler::TrustedImm const): (JSC::DFG::SpeculativeJIT::initConstantInfo): (JSC::DFG::SpeculativeJIT::callOperation): (JSC::DFG::SpeculativeJIT::callOperationWithCallFrameRollbackOnException): (JSC::DFG::SpeculativeJIT::callCustomGetter): Deleted. * dfg/DFGSpeculativeJIT32_64.cpp: (JSC::DFG::SpeculativeJIT::cachedGetById): (JSC::DFG::SpeculativeJIT::cachedGetByIdWithThis): (JSC::DFG::SpeculativeJIT::cachedPutById): (JSC::DFG::SpeculativeJIT::emitCall): (JSC::DFG::SpeculativeJIT::compileContiguousPutByVal): (JSC::DFG::SpeculativeJIT::compile): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::emitCall): (JSC::DFG::SpeculativeJIT::compile): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstructVarargsSpread): (JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstructVarargs): (JSC::FTL::DFG::LowerDFGToB3::compileCallEval): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * ftl/FTLSlowPathCall.h: (JSC::FTL::callOperation): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::emitStoreStructureWithTypeInfo): * jit/CCallHelpers.cpp: (JSC::CCallHelpers::ensureShadowChickenPacket): * jit/CCallHelpers.h: (JSC::CCallHelpers::setupArgument): (JSC::CCallHelpers::setupStubArgs): (JSC::CCallHelpers::ArgCollection::ArgCollection): (JSC::CCallHelpers::ArgCollection::pushRegArg): (JSC::CCallHelpers::ArgCollection::addGPRArg): (JSC::CCallHelpers::ArgCollection::addStackArg): (JSC::CCallHelpers::ArgCollection::addPoke): (JSC::CCallHelpers::ArgCollection::argCount): (JSC::CCallHelpers::clampArrayToSize): (JSC::CCallHelpers::pokeForArgument): (JSC::CCallHelpers::marshallArgumentRegister): (JSC::CCallHelpers::setupArgumentsImpl): (JSC::CCallHelpers::std::is_integral<CURRENT_ARGUMENT_TYPE>::value): (JSC::CCallHelpers::std::is_pointer<CURRENT_ARGUMENT_TYPE>::value): (JSC::CCallHelpers::setupArguments): (JSC::CCallHelpers::prepareForTailCallSlow): (JSC::CCallHelpers::setupArgumentsWithExecState): Deleted. (JSC::CCallHelpers::resetCallArguments): Deleted. (JSC::CCallHelpers::addCallArgument): Deleted. (JSC::CCallHelpers::setupArgumentsExecState): Deleted. (JSC::CCallHelpers::setupTwoStubArgsGPR): Deleted. (JSC::CCallHelpers::setupThreeStubArgsGPR): Deleted. (JSC::CCallHelpers::setupFourStubArgsGPR): Deleted. (JSC::CCallHelpers::setupFiveStubArgsGPR): Deleted. (JSC::CCallHelpers::setupTwoStubArgsFPR): Deleted. (JSC::CCallHelpers::setupStubArguments): Deleted. (JSC::CCallHelpers::setupArgumentsWithExecStateForCallWithSlowPathReturnType): Deleted. (JSC::CCallHelpers::setupStubArguments134): Deleted. (JSC::CCallHelpers::setupStubArgsGPR): Deleted. * jit/FPRInfo.h: (JSC::toInfoFromReg): * jit/GPRInfo.h: (JSC::JSValueRegs::JSValueRegs): (JSC::toInfoFromReg): * jit/JIT.h: (JSC::JIT::callOperation): (JSC::JIT::callOperationWithProfile): (JSC::JIT::callOperationWithResult): (JSC::JIT::callOperationNoExceptionCheck): (JSC::JIT::callOperationWithCallFrameRollbackOnException): * jit/JITArithmetic.cpp: (JSC::JIT::emitMathICFast): (JSC::JIT::emitMathICSlow): * jit/JITArithmetic32_64.cpp: (JSC::JIT::emit_compareAndJumpSlow): * jit/JITCall32_64.cpp: (JSC::JIT::compileSetupVarargsFrame): * jit/JITInlines.h: (JSC::JIT::callOperation): Deleted. (JSC::JIT::callOperationNoExceptionCheck): Deleted. (JSC::JIT::callOperationWithCallFrameRollbackOnException): Deleted. * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_new_array_with_size): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emitSlow_op_instanceof): (JSC::JIT::emitSlow_op_instanceof_custom): (JSC::JIT::emit_op_set_function_name): (JSC::JIT::emitSlow_op_eq): (JSC::JIT::emitSlow_op_neq): (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_switch_imm): (JSC::JIT::emit_op_switch_char): (JSC::JIT::emit_op_switch_string): (JSC::JIT::emitSlow_op_has_indexed_property): * jit/JITOperations.cpp: * jit/JITOperations.h: * jit/JITPropertyAccess.cpp: (JSC::JIT::emitGetByValWithCachedId): (JSC::JIT::emitSlow_op_get_by_id): (JSC::JIT::emitSlow_op_get_by_id_with_this): (JSC::JIT::emitSlow_op_get_from_scope): * jit/JITPropertyAccess32_64.cpp: (JSC::JIT::emit_op_put_by_index): (JSC::JIT::emit_op_put_setter_by_id): (JSC::JIT::emit_op_put_getter_setter_by_id): (JSC::JIT::emit_op_put_getter_by_val): (JSC::JIT::emit_op_put_setter_by_val): (JSC::JIT::emit_op_del_by_id): (JSC::JIT::emit_op_del_by_val): (JSC::JIT::emitGetByValWithCachedId): (JSC::JIT::emitSlow_op_get_by_val): (JSC::JIT::emitPutByValWithCachedId): (JSC::JIT::emitSlow_op_put_by_val): (JSC::JIT::emitSlow_op_try_get_by_id): (JSC::JIT::emitSlow_op_get_by_id): (JSC::JIT::emitSlow_op_get_by_id_with_this): (JSC::JIT::emitSlow_op_put_by_id): (JSC::JIT::emitSlow_op_get_from_scope): * jit/RegisterSet.h: (JSC::RegisterSet::RegisterSet): * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::slowPathFor): * jsc.cpp: (GlobalObject::finishCreation): (functionBreakpoint): * runtime/JSCJSValue.h: * wasm/js/WasmToJS.cpp: (JSC::Wasm::wasmToJS): Source/WTF: Add a new function traits struct that provides interesting information about the provided function pointer. Right now it only provides information for function pointers, in theory we could also get it to work for other types. * WTF.xcodeproj/project.pbxproj: * wtf/Bitmap.h: (WTF::WordType>::Bitmap): * wtf/CMakeLists.txt: * wtf/FunctionTraits.h: Added. (WTF::slotsForCCallArgument): (WTF::computeCCallSlots): (WTF::FunctionTraits<Result): Canonical link: https://commits.webkit.org/199098@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229391 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-03-08 02:26:55 +00:00
} // namespace WTF
using WTF::FunctionTraits;