2017-07-24 Carlos Garcia Campos Unreviewed. Fix the build with GCC 4.9 after merge r217438. * bytecompiler/BytecodeGenerator.h: (JSC::StructureForInContext::addGetInst): 2017-06-26 Saam Barati Crash in JSC::Lexer::setCode https://bugs.webkit.org/show_bug.cgi?id=172754 Reviewed by Mark Lam. The lexer was asking one of its buffers to reserve initial space that was O(text size in bytes). For large sources, this would end up causing the vector to overflow and crash. This patch changes this code be like the Lexer's other buffers and to only reserve a small starting buffer. * parser/Lexer.cpp: (JSC::Lexer::setCode): 2017-04-13 Mark Lam Should use flushDirect() when flushing the scopeRegister due to needsScopeRegister(). https://bugs.webkit.org/show_bug.cgi?id=170661 Reviewed by Filip Pizlo. Previously, we were using flush() to flush the outermost frame's scopeRegister. This is incorrect because flush() expects the VirtualRegister value passed to it to be that of the top most inlined frame. In the event that we reach a terminal condition while inside an inlined frame, flush() will end up flushing the wrong register. The fix is simply to use flushDirect() instead. * dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::flush): 2017-04-20 Mark Lam virtualThunkFor() needs to materialize its of tagMaskRegister for tail calls. https://bugs.webkit.org/show_bug.cgi?id=171079 Reviewed by Saam Barati. This is needed because tail calls would restore callee saved registers (and therefore, potentially clobber the tag registers) before jumping to the thunk. * jit/ThunkGenerators.cpp: (JSC::virtualThunkFor): 2017-05-05 Keith Miller Put does not properly consult the prototype chain https://bugs.webkit.org/show_bug.cgi?id=171754 Reviewed by Saam Barati. We should do a follow up that cleans up the rest of put. See: https://bugs.webkit.org/show_bug.cgi?id=171759 * runtime/JSCJSValue.cpp: (JSC::JSValue::putToPrimitive): * runtime/JSObject.cpp: (JSC::JSObject::putInlineSlow): * runtime/JSObjectInlines.h: (JSC::JSObject::canPerformFastPutInline): 2017-07-24 Carlos Garcia Campos Unreviewed. Fix merge r217438. See bug #174781. * bytecompiler/BytecodeGenerator.cpp: (JSC::StructureForInContext::finalize): Use operand instead of unsignedValue. 2017-05-05 Saam Barati putDirectIndex does not properly do defineOwnProperty https://bugs.webkit.org/show_bug.cgi?id=171591 Reviewed by Geoffrey Garen. This patch fixes putDirectIndex and its JIT implementations to be compatible with the ES6 spec. I think our code became out of date when we implemented ArraySpeciesCreate since ArraySpeciesCreate may return arbitrary objects. We perform putDirectIndex on that arbitrary object. The behavior we want is as if we performed defineProperty({configurable:true, enumerable:true, writable:true}). However, we weren't doing this. putDirectIndex assumed it could just splat data into any descendent of JSObject's butterfly. For example, this means we'd just splat into the butterfly of a typed array, even though a typed array doesn't use its butterfly to store its indexed properties in the usual way. Also, typed array properties are non-configurable, so this operation should throw. This also means if we saw a ProxyObject, we'd just splat into its butterfly, but this is obviously wrong because ProxyObject should intercept the defineProperty operation. This patch fixes this issue by adding a whitelist of cell types that can go down putDirectIndex's fast path. Anything not in that whitelist will simply call into defineOwnProperty. * bytecode/ByValInfo.h: (JSC::jitArrayModePermitsPutDirect): * dfg/DFGArrayMode.cpp: (JSC::DFG::ArrayMode::refine): * jit/JITOperations.cpp: * runtime/ArrayPrototype.cpp: (JSC::arrayProtoFuncSplice): * runtime/ClonedArguments.cpp: (JSC::ClonedArguments::createStructure): * runtime/JSGenericTypedArrayViewInlines.h: (JSC::JSGenericTypedArrayView::defineOwnProperty): * runtime/JSObject.cpp: (JSC::canDoFastPutDirectIndex): (JSC::JSObject::defineOwnIndexedProperty): (JSC::JSObject::putDirectIndexSlowOrBeyondVectorLength): (JSC::JSObject::putDirectIndexBeyondVectorLength): Deleted. * runtime/JSObject.h: (JSC::JSObject::putDirectIndex): (JSC::JSObject::canSetIndexQuicklyForPutDirect): Deleted. * runtime/JSType.h: 2017-05-17 Filip Pizlo JSC: Incorrect LoadVarargs handling in ArgumentsEliminationPhase::transform https://bugs.webkit.org/show_bug.cgi?id=172208 Reviewed by Saam Barati. * dfg/DFGArgumentsEliminationPhase.cpp: 2017-04-17 Mark Lam JSArray::appendMemcpy() needs to handle copying from Undecided indexing type too. https://bugs.webkit.org/show_bug.cgi?id=170896 Reviewed by JF Bastien and Keith Miller. * runtime/JSArray.cpp: (JSC::JSArray::appendMemcpy): 2017-05-25 Saam Barati Our for-in optimization in the bytecode generator does its static analysis incorrectly https://bugs.webkit.org/show_bug.cgi?id=172532 Reviewed by Mark Lam. Our static analysis for when a for-in induction variable is written to tried to its analysis as we generate bytecode. This has issues, since it does not account for the dynamic execution path of the program. Let's consider a program where our old analysis worked: ``` for (let p in o) { o[p]; // We can transform this into a fast get_direct_pname p = 20; o[p]; // We cannot transform this since p has been changed. } ``` However, our static analysis did not account for loops, which exist in JavaScript. e.g, it would incorrectly compile this program as: ``` for (let p in o) { for (let i = 0; i < 20; ++i) { o[p]; // It transforms this to use get_direct_pname even though p will be over-written if we get here from the inner loop back edge! p = 20; o[p]; // We correctly do not transform this. } } ``` Because of this flaw, I've made the optimization more conservative. We now optimistically emit code for the optimized access. However, if a for-in context is *ever* invalidated, before we pop it off the stack, we rewrite the program's optimized accesses to no longer be optimized. To do this, each context keeps track of its optimized accesses. This patch also adds a new bytecode, op_nop, which is just a no-op. It was helpful to add this because reverting get_direct_pname to get_by_val will leave us with an extra instruction word because get_direct_pname is has a length of 7 where get_by_val has a length of 6. This leaves us with an extra slot that we fill with an op_nop. * bytecode/BytecodeDumper.cpp: (JSC::BytecodeDumper::dumpBytecode): * bytecode/BytecodeList.json: * bytecode/BytecodeUseDef.h: (JSC::computeUsesForBytecodeOffset): (JSC::computeDefsForBytecodeOffset): * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::emitGetByVal): (JSC::BytecodeGenerator::popIndexedForInScope): (JSC::BytecodeGenerator::popStructureForInScope): (JSC::BytecodeGenerator::invalidateForInContextForLocal): (JSC::StructureForInContext::pop): (JSC::IndexedForInContext::pop): * bytecompiler/BytecodeGenerator.h: (JSC::StructureForInContext::addGetInst): (JSC::IndexedForInContext::addGetInst): * dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::parseBlock): * dfg/DFGCapabilities.cpp: (JSC::DFG::capabilityLevel): * jit/JIT.cpp: (JSC::JIT::privateCompileMainPass): * jit/JIT.h: * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_nop): * llint/LowLevelInterpreter.asm: 2017-04-14 Saam Barati ParseInt intrinsic in DFG backend doesn't properly flush its operands https://bugs.webkit.org/show_bug.cgi?id=170865 Reviewed by Mark Lam and Geoffrey Garen. The DFG backend code needed to first call .gpr()/.jsValueRegs() before calling flushRegisters(), or the input JSValueOperand would not be flushed. * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileParseInt): 2017-06-16 Konstantin Tokarev REGRESSION(r166799): LogsPageMessagesToSystemConsoleEnabled corrupts non-ASCII characters https://bugs.webkit.org/show_bug.cgi?id=173470 Reviewed by Joseph Pecoraro. ConsoleClient::printConsoleMessageWithArguments() incorrectly uses const char* overload of StringBuilder::append() that assummes Latin1 encoding, not UTF8. * runtime/ConsoleClient.cpp: (JSC::ConsoleClient::printConsoleMessageWithArguments): 2017-06-01 Tomas Popela , Mark Lam RELEASE_ASSERT_NOT_REACHED() in InferredType::kindForFlags() on Big-Endians https://bugs.webkit.org/show_bug.cgi?id=170945 Reviewed by Mark Lam. Re-define PutByIdFlags as a int32_t enum explicitly because it is stored as an int32_t value in UnlinkedInstruction. This prevents a bug on 64-bit big endian architectures where the word order is inverted (when we convert the UnlinkedInstruction into a CodeBlock Instruction), resulting in the PutByIdFlags value not being stored in the 32-bit word that the rest of the code expects it to be in. * bytecode/PutByIdFlags.h: 2017-05-10 Mark Lam Crash in JavaScriptCore GC when using JSC on dispatch queues (thread_get_state returns NULL stack pointer). https://bugs.webkit.org/show_bug.cgi?id=160337 Reviewed by Filip Pizlo and Geoffrey Garen. This is a workaround for . During thread initialization, for some target platforms, thread state is momentarily set to 0 before being filled in with the target thread's real register values. As a result, there's a race condition that may result in us getting a null stackPointer during a GC scan. This issue may manifest with workqueue threads where the OS may choose to recycle a thread for an expired task. The workaround is simply to indicate that there's nothing to copy and return. This is correct because we will only ever observe a null pointer during thread initialization. Hence, by definition, there's nothing there that we need to scan yet, and therefore, nothing that needs to be copied. * heap/MachineStackMarker.cpp: (JSC::MachineThreads::tryCopyOtherThreadStack): 2017-05-10 Filip Pizlo Null pointer dereference in WTF::RefPtr::operator!() under slow_path_get_direct_pname https://bugs.webkit.org/show_bug.cgi?id=171801 Reviewed by Michael Saboff. This was a goofy oversight. The for-in optimization relies on the bytecode generator to detect when the loop's index variable gets mutated. We forgot to have the hooks for detecting this in prefix and postfix operations (++i and i++). * bytecompiler/NodesCodegen.cpp: (JSC::PostfixNode::emitResolve): (JSC::PrefixNode::emitResolve): 2017-05-09 Filip Pizlo Heap::heap() should behave gracefully for null pointers https://bugs.webkit.org/show_bug.cgi?id=171888 Reviewed by Mark Lam. Some callers of Heap::heap() can pass a null cell and they will behave gracefully if we return a null Heap. So, let's do that. This fixes a crash and it does not hurt performance. I'm seeing a possible 0.5% regression with 74% probability. That's a neutral result by our usual 95% standard. * heap/HeapInlines.h: (JSC::Heap::heap): 2017-04-05 Guilherme Iscaro Do not use BLX for immediates (ARM-32) https://bugs.webkit.org/show_bug.cgi?id=170351 Reviewed by Mark Lam. Currently the offline asm generator for 32-bit ARM code translates the 'call' meta-instruction (which may be found in LowLevelInterpreter.asm and friends) to the ARM's BLX instrunction. The BLX instruction may be used for labels (immediates) and registers and one side effect of BLX is that it may switch the processor's instruction set. A 'BLX register' instruction will change/remain the processor state to ARM if the register_bit[0] is set to 0 or change/remain to Thumb if register_bit[0] is set to 1. However, a 'BLX label' instruction will always switch the processor state. It switches ARM to thumb and vice-versa. This behaviour is unwanted, since the C++ code and the offlineasm generated code are both compiled using the same instruction set, thus a instruction set change will likely produce a crash. In order to fix the problem the BL instruction can be used for labels. It will branch just like BLX, but it won't change the instruction set. It's important to note that Darwin is not affected by this problem, thus to minimize the impact of this change the BL instruction will only be used on non-darwin targets. BLX reference: http://infocenter.arm.com/help/topic/com.arm.doc.dui0489i/CIHBJCDC.html?resultof=%22%62%6c%78%22%20 * offlineasm/arm.rb: 2017-05-04 Konstantin Tokarev Fix compilation with ICU 59.1 https://bugs.webkit.org/show_bug.cgi?id=171612 Reviewed by Mark Lam. ICU 59.1 has broken source compatibility. Now it defines UChar as char16_t, which does not allow automatic type conversion from unsigned short in C++ code. * API/JSStringRef.cpp: (JSStringCreateWithCharacters): (JSStringCreateWithCharactersNoCopy): (JSStringGetCharactersPtr): * runtime/DateConversion.cpp: (JSC::formatDateTime): 2017-04-19 Yusuke Suzuki r211670 broke double to int conversion. https://bugs.webkit.org/show_bug.cgi?id=170961 Reviewed by Mark Lam. In this patch, we take a template parameter way. While it reduces duplicate code, it effectively produces optimized code for operationToInt32SensibleSlow, and fixes kraken pbkdf2 regression on Linux. And this patch also fixes undefined behavior by changing int32_t to uint32_t. If exp is 31, missingOne is 1 << 31, INT32_MIN. Thus missingOne - 1 will cause int32_t overflow, and it is an undefined behavior. * runtime/MathCommon.cpp: (JSC::operationToInt32SensibleSlow): * runtime/MathCommon.h: (JSC::toInt32Internal): (JSC::toInt32): 2017-04-18 Mark Lam r211670 broke double to int conversion. https://bugs.webkit.org/show_bug.cgi?id=170961 Reviewed by Yusuke Suzuki. This is because operationToInt32SensibleSlow() assumes that left shifts of greater than 31 bits on an 31-bit value will produce a 0. However, the spec says that "if the value of the right operand is negative or is greater or equal to the number of bits in the promoted left operand, the behavior is undefined." See http://en.cppreference.com/w/cpp/language/operator_arithmetic#Bitwise_shift_operators. This patch fixes this by restoring the check to prevent a shift of greater than 31 bits. It also consolidates the optimization in operationToInt32SensibleSlow() back into toInt32() so that we don't have 2 copies of the same code with only a slight variation. JSC benchmarks shows that performance is neutral with this patch. * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileValueToInt32): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::sensibleDoubleToInt32): * runtime/MathCommon.cpp: (JSC::operationToInt32SensibleSlow): Deleted. * runtime/MathCommon.h: (JSC::toInt32): 2017-03-23 Yusuke Suzuki [JSC] MachineThreads does not consider situation that one thread has multiple VMs https://bugs.webkit.org/show_bug.cgi?id=169819 Reviewed by Mark Lam. The Linux port of PlatformThread suspend/resume mechanism relies on having a thread specific singleton thread data, and was relying on MachineThreads::Thread to be this thread specific singleton. But because MachineThreads::Thread is not a thread specific singleton, we can get a deadlock in the GTK port's DatabaseProcess. This patch fixes this issue by moving per thread data from MachineThreads::Thread to MachineThreads::ThreadData, where there will only be one instance of MachineThreads::ThreadData per thread. Each MachineThreads::Thread will now point to the same MachineThreads::ThreadData for any given thread. * heap/MachineStackMarker.cpp: (pthreadSignalHandlerSuspendResume): (JSC::threadData): (JSC::MachineThreads::Thread::Thread): (JSC::MachineThreads::Thread::createForCurrentThread): (JSC::MachineThreads::Thread::operator==): (JSC::MachineThreads::ThreadData::ThreadData): (JSC::MachineThreads::ThreadData::~ThreadData): (JSC::MachineThreads::ThreadData::suspend): (JSC::MachineThreads::ThreadData::resume): (JSC::MachineThreads::ThreadData::getRegisters): (JSC::MachineThreads::ThreadData::Registers::stackPointer): (JSC::MachineThreads::ThreadData::Registers::framePointer): (JSC::MachineThreads::ThreadData::Registers::instructionPointer): (JSC::MachineThreads::ThreadData::Registers::llintPC): (JSC::MachineThreads::ThreadData::freeRegisters): (JSC::MachineThreads::ThreadData::captureStack): (JSC::MachineThreads::tryCopyOtherThreadStacks): (JSC::MachineThreads::Thread::~Thread): Deleted. (JSC::MachineThreads::Thread::suspend): Deleted. (JSC::MachineThreads::Thread::resume): Deleted. (JSC::MachineThreads::Thread::getRegisters): Deleted. (JSC::MachineThreads::Thread::Registers::stackPointer): Deleted. (JSC::MachineThreads::Thread::Registers::framePointer): Deleted. (JSC::MachineThreads::Thread::Registers::instructionPointer): Deleted. (JSC::MachineThreads::Thread::Registers::llintPC): Deleted. (JSC::MachineThreads::Thread::freeRegisters): Deleted. (JSC::MachineThreads::Thread::captureStack): Deleted. * heap/MachineStackMarker.h: (JSC::MachineThreads::Thread::operator!=): (JSC::MachineThreads::Thread::suspend): (JSC::MachineThreads::Thread::resume): (JSC::MachineThreads::Thread::getRegisters): (JSC::MachineThreads::Thread::freeRegisters): (JSC::MachineThreads::Thread::captureStack): (JSC::MachineThreads::Thread::platformThread): (JSC::MachineThreads::Thread::stackBase): (JSC::MachineThreads::Thread::stackEnd): * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::isValidFramePointer): * runtime/VMTraps.cpp: (JSC::findActiveVMAndStackBounds): 2017-04-03 Mark Lam Fix incorrect capacity delta calculation reported in SparseArrayValueMap::add(). https://bugs.webkit.org/show_bug.cgi?id=170412 Reviewed by Filip Pizlo. Here's an example of code that will trigger underflow in the "deprecatedExtraMemory" reported by SparseArrayValueMap::add() that is added to Heap::m_deprecatedExtraMemorySize: arr = new Array; Object.defineProperty(arr, 18, ({writable: true, configurable: true})); for (var i = 0; i < 3; ++i) { Array.prototype.push.apply(arr, ["", () => {}, {}]); Array.prototype.sort.apply(arr, [() => {}, []]); } However, Heap::m_deprecatedExtraMemorySize is only 1 of 3 values that are added up to form the result of Heap::extraMemorySize(). Heap::m_extraMemorySize and Heap::m_arrayBuffers.size() are the other 2. While Heap::m_arrayBuffers.size() is bounded by actual allocated memory, both Heap::m_deprecatedExtraMemorySize and Heap::m_extraMemorySize are added to without any bounds checks, and they are only reset to 0 at the start of a full GC. As a result, if we have a long sequence of eden GCs with a lot of additions to Heap::m_extraMemorySize and/or Heap::m_deprecatedExtraMemorySize, then these values could theoretically overflow. Coupling this with the underflow from SparseArrayValueMap::add(), the result for Heap::extraMemorySize() can easily overflow. Note: Heap::extraMemorySize() is used to compute the value currentHeapSize. If multiple conditions line up just right, the above overflows can result in this debug assertion failure during an eden GC: ASSERT(currentHeapSize >= m_sizeAfterLastCollect); Otherwise, the effects of the overflows will only result in the computed currentHeapSize not being representative of actual memory usage, and therefore, a full GC may be triggered earlier or later than is ideal. This patch ensures that SparseArrayValueMap::add() cannot underflow Heap::m_deprecatedExtraMemorySize. It also adds overflows checks in the calculations of Heap::m_deprecatedExtraMemorySize, Heap::m_extraMemorySize, and Heap::extraMemorySize() so that their values are saturated appropriately to ensure that GC collections are triggered based on representative memory usage. * heap/Heap.cpp: (JSC::Heap::deprecatedReportExtraMemorySlowCase): (JSC::Heap::extraMemorySize): (JSC::Heap::updateAllocationLimits): (JSC::Heap::reportExtraMemoryVisited): * runtime/SparseArrayValueMap.cpp: (JSC::SparseArrayValueMap::add): 2017-04-02 Carlos Garcia Campos Share implementation of JSRunLoopTimer::timerDidFire https://bugs.webkit.org/show_bug.cgi?id=170392 Reviewed by Michael Catanzaro. The code is cross-platform but it's duplicated in CF and GLib implementations, it could be shared instead. * runtime/JSRunLoopTimer.cpp: (JSC::JSRunLoopTimer::timerDidFire): Move common implementation here. (JSC::JSRunLoopTimer::setRunLoop): Use timerDidFireCallback. (JSC::JSRunLoopTimer::timerDidFireCallback): Call JSRunLoopTimer::timerDidFire(). * runtime/JSRunLoopTimer.h: 2017-04-01 Oleksandr Skachkov Object with numerical keys with gaps gets filled by NaN values https://bugs.webkit.org/show_bug.cgi?id=164412 Reviewed by Mark Lam. This patch fixes issue when object have two properties with name as number. The issue appears when during invoking convertDoubleToArrayStorage, array is filled by pNaN and method converting it to real NaN. This happeneds because a pNaN in a Double array is a hole, and Double arrays cannot have NaN values. To fix issue we need to check value and clear it if it pNaN. * runtime/JSObject.cpp: (JSC::JSObject::convertDoubleToArrayStorage): 2017-03-31 Mark Lam Array.prototype.splice() should not be using JSArray::tryCreateForInitializationPrivate(). https://bugs.webkit.org/show_bug.cgi?id=170303 Reviewed by Filip Pizlo. This is because it needs to call getProperty() later to get the values for initializing the array. getProperty() can execute arbitrary code and potentially trigger the GC. This is not allowed for clients of JSArray::tryCreateForInitializationPrivate(). * runtime/ArrayPrototype.cpp: (JSC::arrayProtoFuncSplice): (JSC::copySplicedArrayElements): Deleted. 2017-03-30 Mark Lam IntlObject should not be using JSArray::initializeIndex(). https://bugs.webkit.org/show_bug.cgi?id=170302 Reviewed by Saam Barati. JSArray::initializeIndex() is only meant to be used with arrays created using JSArray::tryCreateForInitializationPrivate() under very constrained conditions. * runtime/IntlObject.cpp: (JSC::canonicalizeLocaleList): (JSC::intlObjectFuncGetCanonicalLocales): 2017-03-28 Mark Lam The Mutator should not be able to steal the conn if the Collector hasn't reached the NotRunning phase yet. https://bugs.webkit.org/show_bug.cgi?id=170213 Reviewed by Filip Pizlo. The current condition for stealing the conn isn't tight enough. Restricting the stealing to when m_currentPhase == NotRunning ensures that the Collector is really done running. No test because this issue only manifests with a race condition that is difficult to reproduce on demand. * heap/Heap.cpp: (JSC::Heap::requestCollection): 2017-03-24 Mark Lam Array memcpy'ing fast paths should check if we're having a bad time if they cannot handle it. https://bugs.webkit.org/show_bug.cgi?id=170064 Reviewed by Geoffrey Garen. * runtime/ArrayPrototype.cpp: (JSC::arrayProtoPrivateFuncConcatMemcpy): * runtime/JSArray.cpp: (JSC::JSArray::fastSlice): 2017-03-23 Yusuke Suzuki [JSC] Use jsNontrivialString agressively for ToString(Int52) https://bugs.webkit.org/show_bug.cgi?id=170002 Reviewed by Sam Weinig. We use the same logic used for Int32 to use jsNontvirialString. After single character check, produced string is always longer than 1. Thus, we can use jsNontrivialString. * runtime/NumberPrototype.cpp: (JSC::int52ToString): 2017-03-23 Mark Lam Array.prototype.splice behaves incorrectly when the VM is "having a bad time". https://bugs.webkit.org/show_bug.cgi?id=170025 Reviewed by Saam Barati. * runtime/ArrayPrototype.cpp: (JSC::copySplicedArrayElements): (JSC::arrayProtoFuncSplice): 2017-03-23 Yusuke Suzuki [JSC][DFG] Make addShouldSpeculateAnyInt more conservative to avoid regression caused by Double <-> Int52 conversions https://bugs.webkit.org/show_bug.cgi?id=169998 Reviewed by Saam Barati. Double <-> Int52 and JSValue <-> Int52 conversions are not so cheap. Thus, Int52Rep is super carefully emitted. We make addShouldSpeculateAnyInt more conservative to avoid regressions caused by the above conversions. We select ArithAdd(Int52, Int52) only when this calculation is beneficial compared to added Int52Rep conversions. This patch tighten the conditions of addShouldSpeculateAnyInt. 1. Honor DoubleConstant. When executing imaging-darkroom, we have a thing like that, 132:< 2:loc36> DoubleConstant(Double|UseAsOther, AnyIntAsDouble, Double: 4607182418800017408, 1.000000, bc#114) 1320:< 1:loc38> Int52Rep(Check:Int32:@82, Int52|PureInt, Int32, Exits, bc#114) 1321:< 1:loc39> Int52Constant(Int52|PureInt, Boolint32Nonboolint32Int52, Double: 4607182418800017408, 1.000000, bc#114) 133: ArithSub(Int52Rep:@1320, Int52Rep:@1321, Int52|MustGen, Int52, CheckOverflow, Exits, bc#114) The LHS of ArithSub says predicting Boolint32, and the rhs says AnyIntAsDouble. Thus we select ArithSub(Int52, Int52) instead of ArithSub(Double, Double). However, it soon causes OSR exits. In imaging-darkroom, LHS's Int32 prediction will be broken. While speculating Int32 in the above situation is reasonable approach since the given LHS says predicting Int32, this causes severe performance regression. Previously, we always select ArithSub(Double, Double). So accidentally, we do not encounter this misprediction issue. One thing can be found that we have DoubleConstant in the RHS. It means that we have `1.0` instead of `1` in the code. We can see the code like `lhs - 1.0` instead of `lhs - 1` in imaging-darkroom. It offers good information that lhs and the resulting value would be double. Handling the above ArithSub in double seems more appropriate rather than handling it in Int52. So, in this patch, we honor DoubleConstant. If we find DoubleConstant on one operand, we give up selecting Arith[Sub,Add](Int52, Int52). This change removes OSR exits occurr in imaging-darkroom right now. 2. Two Int52Rep(Double) conversions are not desirable. We allow AnyInt ArithAdd only when the one operand of the binary operation should be speculated AnyInt. It is a bit conservative decision. This is because Double to Int52 conversion is not so cheap. Frequent back-and-forth conversions between Double and Int52 rather hurt the performance. If the one operand of the operation is already Int52, the cost for constructing ArithAdd becomes cheap since only one Double to Int52 conversion could be required. This recovers some regression in assorted tests while keeping kraken crypto improvements. 3. Avoid frequent Int52 to JSValue conversions. Int52 to JSValue conversion is not so cheap. Thus, we would like to avoid such situations. So, in this patch, we allow Arith(Int52, Int52) with AnyIntAsDouble operand only when the node is used as number. By doing so, we avoid the case like, converting Int52, performing ArithAdd, and soon converting back to JSValue. The above 3 changes recover the regression measured in microbenchmarks/int52-back-and-forth.js and assorted benchmarks. And still it keeps kraken crypto improvements. baseline patched imaging-darkroom 201.112+-3.192 ^ 189.532+-2.883 ^ definitely 1.0611x faster stanford-crypto-pbkdf2 103.953+-2.325 100.926+-2.396 might be 1.0300x faster stanford-crypto-sha256-iterative 35.103+-1.071 ? 36.049+-1.143 ? might be 1.0270x slower * dfg/DFGGraph.h: (JSC::DFG::Graph::addShouldSpeculateAnyInt): 2017-03-23 Mark Lam Clients of JSArray::tryCreateForInitializationPrivate() should do their own null checks. https://bugs.webkit.org/show_bug.cgi?id=169783 Reviewed by Saam Barati. Fixed clients of tryCreateForInitializationPrivate() to do a null check and throw an OutOfMemoryError if allocation fails, or RELEASE_ASSERT that the allocation succeeds. * dfg/DFGOperations.cpp: * ftl/FTLOperations.cpp: (JSC::FTL::operationMaterializeObjectInOSR): * runtime/ArrayPrototype.cpp: (JSC::arrayProtoFuncSplice): * runtime/CommonSlowPaths.cpp: (JSC::SLOW_PATH_DECL): * runtime/JSArray.cpp: (JSC::JSArray::tryCreateForInitializationPrivate): (JSC::JSArray::fastSlice): * runtime/JSArray.h: (JSC::constructArray): (JSC::constructArrayNegativeIndexed): * runtime/RegExpMatchesArray.cpp: (JSC::createEmptyRegExpMatchesArray): * runtime/RegExpMatchesArray.h: (JSC::createRegExpMatchesArray): 2017-03-22 Yusuke Suzuki [JSC][DFG] Propagate AnyIntAsDouble information carefully to utilize it in fixup https://bugs.webkit.org/show_bug.cgi?id=169914 Reviewed by Saam Barati. In DFG prediction propagation phase, we pollute the prediction of GetByVal for Array::Double as SpecDoubleReal even if the heap prediction says the proper prediction is SpecAnyIntAsDouble. Thus, the following nodes just see the result of GetByVal(Array::Double) as double value, and select suboptimal edge filters in fixup phase. For example, if the result of GetByVal is SpecAnyIntAsDouble, we can see the node like ArithAdd(SpecAnyIntAsDouble, Int52) and we should have a chance to make it ArithAdd(Check:Int52, Int52) instead of ArithAdd(Double, Double). This patch propagates SpecAnyIntAsDouble in GetByVal(Array::Double) properly. And ValueAdd, ArithAdd and ArithSub select AnyInt edge filters for SpecAnyIntAsDouble values. It finally produces a Int52 specialized DFG node. And subsequent nodes using the produced one also become Int52 specialized. One considerable problem is that the heap prediction misses the non any int doubles. In that case, if Int52 edge filter is used, BadType exit will occur. It updates the prediction of the value profile of GetByVal. So, in the next time, GetByVal(Array::Double) produces more conservative predictions and avoids exit-and-recompile loop correctly. This change is very sensitive to the correct AI and appropriate predictions. Thus, this patch finds and fixes some related issues. One is incorrect prediction of ToThis and another is incorrect AI logic for Int52Rep. This change dramatically improves kraken benchmarks' crypto-pbkdf2 and crypto-sha256-iterative by 42.0% and 30.7%, respectively. baseline patched Kraken: ai-astar 158.851+-4.132 ? 159.433+-5.176 ? audio-beat-detection 53.193+-1.621 ? 53.391+-2.072 ? audio-dft 103.589+-2.277 ? 104.902+-1.924 ? might be 1.0127x slower audio-fft 40.491+-1.102 39.854+-0.755 might be 1.0160x faster audio-oscillator 68.504+-1.721 ? 68.957+-1.725 ? imaging-darkroom 118.367+-2.171 ? 119.581+-2.310 ? might be 1.0103x slower imaging-desaturate 71.443+-1.461 ? 72.398+-1.918 ? might be 1.0134x slower imaging-gaussian-blur 110.648+-4.035 109.184+-3.373 might be 1.0134x faster json-parse-financial 60.363+-1.628 ? 61.936+-1.585 ? might be 1.0261x slower json-stringify-tinderbox 37.903+-0.869 ? 39.559+-1.607 ? might be 1.0437x slower stanford-crypto-aes 56.313+-1.512 ? 56.675+-1.715 ? stanford-crypto-ccm 51.564+-1.900 ? 53.456+-2.548 ? might be 1.0367x slower stanford-crypto-pbkdf2 129.546+-2.738 ^ 91.214+-2.027 ^ definitely 1.4202x faster stanford-crypto-sha256-iterative 43.515+-0.730 ^ 33.292+-0.653 ^ definitely 1.3071x faster 78.878+-0.528 ^ 75.988+-0.621 ^ definitely 1.0380x faster * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter::executeEffects): * dfg/DFGGraph.h: (JSC::DFG::Graph::addShouldSpeculateAnyInt): * dfg/DFGPredictionPropagationPhase.cpp: * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileArithNegate): 2017-03-22 Yusuke Suzuki [JSC] Use jsNontrivialString for Number toString operations https://bugs.webkit.org/show_bug.cgi?id=169965 Reviewed by Mark Lam. After single character check, produced string is always longer than 1. Thus, we can use jsNontrivialString. * runtime/NumberPrototype.cpp: (JSC::int32ToStringInternal): 2017-03-21 Mark Lam The DFG Integer Check Combining phase should force an OSR exit for CheckInBounds on a negative constant min bound. https://bugs.webkit.org/show_bug.cgi?id=169933 Reviewed by Filip Pizlo and Geoffrey Garen. Also fixed the bit-rotted RangeKey::dump() function. * dfg/DFGIntegerCheckCombiningPhase.cpp: (JSC::DFG::IntegerCheckCombiningPhase::handleBlock): 2017-03-21 Yusuke Suzuki [JSC] Optimize Number.prototype.toString on Int32 / Int52 / Double https://bugs.webkit.org/show_bug.cgi?id=167454 Reviewed by Saam Barati. This patch improves Number.toString(radix) performance by introducing NumberToStringWithRadix DFG node. It directly calls the operation and it always returns String. baseline patched stanford-crypto-sha256-iterative 45.130+-0.928 44.032+-1.184 might be 1.0250x faster 2017-02-24 Saam Barati Unreviewed. Remove inaccurate copy-paste comment from r212939. * dfg/DFGOperations.cpp: 2017-02-23 Saam Barati Intrinsicify parseInt https://bugs.webkit.org/show_bug.cgi?id=168627 Reviewed by Filip Pizlo. This patch makes parseInt an intrinsic in the DFG and FTL. We do our best to eliminate this node. If we speculate that the first operand to the operation is an int32, and that there isn't a second operand, we convert to the identity of the first operand. That's because parseInt(someInt) === someInt. If the first operand is proven to be an integer, and the second operand is the integer 0 or the integer 10, we can eliminate the node by making it an identity over its first operand. That's because parseInt(someInt, 0) === someInt and parseInt(someInt, 10) === someInt. If we are not able to constant fold the node away, we try to remove checks. The most common use case of parseInt is that its first operand is a proven string. The DFG might be able to remove type checks in this case. We also set up CSE rules for parseInt(someString, someIntRadix) because it's a "pure" operation (modulo resolving a rope). * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter::executeEffects): * dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::handleIntrinsicCall): * dfg/DFGClobberize.h: (JSC::DFG::clobberize): * dfg/DFGDoesGC.cpp: (JSC::DFG::doesGC): * dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): (JSC::DFG::FixupPhase::fixupToStringOrCallStringConstructor): * dfg/DFGNodeType.h: * dfg/DFGOperations.cpp: * dfg/DFGOperations.h: * dfg/DFGPredictionPropagationPhase.cpp: * dfg/DFGSafeToExecute.h: (JSC::DFG::safeToExecute): * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileToStringOrCallStringConstructor): (JSC::DFG::SpeculativeJIT::compileToStringOrCallStringConstructorOnNumber): (JSC::DFG::SpeculativeJIT::compileNumberToStringWithRadix): (JSC::DFG::SpeculativeJIT::compileToStringOrCallStringConstructorOnCell): Deleted. * dfg/DFGSpeculativeJIT.h: (JSC::DFG::SpeculativeJIT::callOperation): * dfg/DFGSpeculativeJIT32_64.cpp: (JSC::DFG::SpeculativeJIT::compile): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::compile): * dfg/DFGStrengthReductionPhase.cpp: (JSC::DFG::StrengthReductionPhase::handleNode): * ftl/FTLCapabilities.cpp: (JSC::FTL::canCompile): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileNode): (JSC::FTL::DFG::LowerDFGToB3::compileToStringOrCallStringConstructor): (JSC::FTL::DFG::LowerDFGToB3::compileNumberToStringWithRadix): * jit/CCallHelpers.h: (JSC::CCallHelpers::setupArgumentsWithExecState): * jit/JITOperations.h: * runtime/Intrinsic.h: * runtime/NumberPrototype.cpp: (JSC::int52ToStringWithRadix): (JSC::int32ToStringInternal): (JSC::numberToStringInternal): (JSC::int32ToString): (JSC::int52ToString): (JSC::numberToString): (JSC::numberProtoFuncToString): (JSC::integerValueToString): Deleted. * runtime/NumberPrototype.h: * runtime/StringPrototype.cpp: (JSC::StringPrototype::finishCreation): This looks to be a 4% Octane/Box2D progression. * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter::executeEffects): * dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::handleIntrinsicCall): * dfg/DFGClobberize.h: (JSC::DFG::clobberize): * dfg/DFGConstantFoldingPhase.cpp: (JSC::DFG::ConstantFoldingPhase::foldConstants): * dfg/DFGDoesGC.cpp: (JSC::DFG::doesGC): * dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): * dfg/DFGNode.h: (JSC::DFG::Node::hasHeapPrediction): * dfg/DFGNodeType.h: * dfg/DFGOperations.cpp: (JSC::DFG::parseIntResult): * dfg/DFGOperations.h: * dfg/DFGPredictionPropagationPhase.cpp: * dfg/DFGSafeToExecute.h: (JSC::DFG::safeToExecute): * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileParseInt): * dfg/DFGSpeculativeJIT.h: (JSC::DFG::SpeculativeJIT::callOperation): (JSC::DFG::SpeculativeJIT::appendCallSetResult): * dfg/DFGSpeculativeJIT32_64.cpp: (JSC::DFG::SpeculativeJIT::compile): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::compile): * ftl/FTLCapabilities.cpp: (JSC::FTL::canCompile): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileNode): (JSC::FTL::DFG::LowerDFGToB3::compileParseInt): * jit/JITOperations.h: * parser/Lexer.cpp: * runtime/ErrorInstance.cpp: * runtime/Intrinsic.h: * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): * runtime/JSGlobalObjectFunctions.cpp: (JSC::toStringView): Deleted. (JSC::isStrWhiteSpace): Deleted. (JSC::parseDigit): Deleted. (JSC::parseIntOverflow): Deleted. (JSC::parseInt): Deleted. * runtime/JSGlobalObjectFunctions.h: * runtime/ParseInt.h: Added. (JSC::parseDigit): (JSC::parseIntOverflow): (JSC::isStrWhiteSpace): (JSC::parseInt): (JSC::toStringView): * runtime/StringPrototype.cpp: 2017-03-19 Chris Dumez `const location = "foo"` throws in a worker https://bugs.webkit.org/show_bug.cgi?id=169839 Reviewed by Mark Lam. Our HasRestrictedGlobalProperty check in JSC was slightly wrong, causing us to sometimes throw a Syntax exception when we shouldn't when declaring a const/let variable and sometimes not throw an exception when we should have. This aligns our behavior with ES6, Firefox and Chrome. * runtime/ProgramExecutable.cpp: (JSC::hasRestrictedGlobalProperty): (JSC::ProgramExecutable::initializeGlobalProperties): Rewrite hasRestrictedGlobalProperty logic as per the EcmaScript spec: - http://www.ecma-international.org/ecma-262/6.0/index.html#sec-hasproperty In particular, they were 2 issues: - We should throw a SyntaxError if hasProperty() returned true but getOwnProperty() would fail to return a descriptor. This would happen for properties that are not OWN properties, but defined somewhere in the prototype chain. The spec does not say to use hasProperty(), only getOwnProperty() and says we should return false if getOwnProperty() does not return a descriptor. This is what we do now. - We would fail to throw when declaring a let/const variable that shadows an own property whose value is undefined. This is because the previous code was explicitly checking for this case. I believe this was a misinterpretation of ES6 which says: """ Let desc be O.[[GetOwnProperty]](P). If desc is undefined, return false. """ We should check that desc is undefined, not desc.value. This is now fixed. 2017-03-19 Yusuke Suzuki import(arg) crashes when ToString(arg) throws https://bugs.webkit.org/show_bug.cgi?id=169778 Reviewed by Saam Barati. JSPromiseDeferred should not be rejected with Exception*. * runtime/JSGlobalObjectFunctions.cpp: (JSC::globalFuncImportModule): 2017-03-16 Mark Lam Fix exception scope verification failures in GenericArgumentsInlines.h. https://bugs.webkit.org/show_bug.cgi?id=165012 Reviewed by Saam Barati. * runtime/GenericArgumentsInlines.h: (JSC::GenericArguments::defineOwnProperty): 2017-03-16 Mark Lam Array concat operation should check for length overflows. https://bugs.webkit.org/show_bug.cgi?id=169796 Reviewed by Keith Miller. * runtime/ArrayPrototype.cpp: (JSC::concatAppendOne): (JSC::arrayProtoPrivateFuncConcatMemcpy): 2017-03-16 Mark Lam The new array with spread operation needs to check for length overflows. https://bugs.webkit.org/show_bug.cgi?id=169780 Reviewed by Filip Pizlo. * dfg/DFGOperations.cpp: * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileNewArrayWithSpread): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileNewArrayWithSpread): * ftl/FTLOperations.cpp: (JSC::FTL::operationMaterializeObjectInOSR): * llint/LLIntSlowPaths.cpp: * runtime/CommonSlowPaths.cpp: (JSC::SLOW_PATH_DECL): * runtime/JSGlobalObject.cpp: 2017-03-16 Yusuke Suzuki Unreviewed, copy m_numberOfArgumentsToSkip https://bugs.webkit.org/show_bug.cgi?id=164582 * bytecode/CodeBlock.cpp: (JSC::CodeBlock::CodeBlock): 2017-03-16 Yusuke Suzuki Unreviewed, fix numParameter() - 1 OSRExit materialization https://bugs.webkit.org/show_bug.cgi?id=164582 When materializing rest parameters, we rely on that numParameter() - 1 equals to the numberOfArgumentsToSkip. But this assumption is broken in r214029. * bytecode/CodeBlock.cpp: (JSC::CodeBlock::finishCreation): * bytecode/CodeBlock.h: (JSC::CodeBlock::numberOfArgumentsToSkip): * ftl/FTLOperations.cpp: (JSC::FTL::operationMaterializeObjectInOSR): 2017-03-15 Yusuke Suzuki [JSC] Default parameter part should be retrieved by op_get_argument opcode instead of changing arity https://bugs.webkit.org/show_bug.cgi?id=164582 Reviewed by Saam Barati. Previously we implement the default parameters as follows. 1. We count the default parameters as the usual parameters. 2. We just get the argument register. 3. Check it with op_is_undefined. 4. And fill the binding with either the argument register or default value. The above is simple. However, it has the side effect that it always increase the arity of the function. While `function.length` does not increase, internally, the number of parameters of CodeBlock increases. This effectively prevent our DFG / FTL to perform inlining: currently we only allows DFG to inline the function with the arity less than or equal the number of passing arguments. It is OK. But when using default parameters, we frequently do not pass the argument for the parameter with the default value. Thus, in our current implementation, we frequently need to fixup the arity. And we frequently fail to inline the function. This patch fixes the above problem by not increasing the arity of the function. When we encounter the parameter with the default value, we use `op_argument` to get the argument instead of using the argument registers. This improves six-speed defaults.es6 performance by 4.45x. defaults.es6 968.4126+-101.2350 ^ 217.6602+-14.8831 ^ definitely 4.4492x faster * bytecode/UnlinkedFunctionExecutable.cpp: (JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable): * bytecode/UnlinkedFunctionExecutable.h: * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::BytecodeGenerator): (JSC::BytecodeGenerator::initializeDefaultParameterValuesAndSetupFunctionScopeStack): (JSC::BytecodeGenerator::initializeNextParameter): (JSC::BytecodeGenerator::initializeParameters): * bytecompiler/BytecodeGenerator.h: * bytecompiler/NodesCodegen.cpp: (JSC::FunctionNode::emitBytecode): * dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::inliningCost): * parser/ASTBuilder.h: (JSC::ASTBuilder::createFunctionMetadata): * parser/Nodes.cpp: (JSC::FunctionMetadataNode::FunctionMetadataNode): * parser/Nodes.h: (JSC::FunctionParameters::size): (JSC::FunctionParameters::at): (JSC::FunctionParameters::append): (JSC::FunctionParameters::isSimpleParameterList): * parser/Parser.cpp: (JSC::Parser::isArrowFunctionParameters): (JSC::Parser::parseGeneratorFunctionSourceElements): (JSC::Parser::parseAsyncFunctionSourceElements): (JSC::Parser::parseFormalParameters): (JSC::Parser::parseFunctionBody): (JSC::Parser::parseFunctionParameters): (JSC::Parser::parseFunctionInfo): * parser/Parser.h: * parser/SyntaxChecker.h: (JSC::SyntaxChecker::createFunctionMetadata): * runtime/FunctionExecutable.h: * runtime/JSFunction.cpp: (JSC::JSFunction::createBuiltinFunction): (JSC::JSFunction::reifyLength): 2017-03-15 Yusuke Suzuki [DFG] ToString operation should have fixup for primitives to say this node does not have side effects https://bugs.webkit.org/show_bug.cgi?id=169544 Reviewed by Saam Barati. Our DFG ToString only considers well about String operands. While ToString(non cell operand) does not have any side effect, it is not modeled well in DFG. This patch introduces a fixup for ToString with NonCellUse edge. If this edge is set, ToString does not clobber things (like ToLowerCase, producing String). And ToString(NonCellUse) allows us to perform CSE! Our microbenchmark shows 32.9% improvement due to dropped GetButterfly and CSE for ToString(). baseline patched template-string-array 12.6284+-0.2766 ^ 9.4998+-0.2295 ^ definitely 1.3293x faster And SixSpeed template_string.es6 shows 16.68x performance improvement due to LICM onto this non-side-effectful ToString(). baseline patched template_string.es6 3229.7343+-40.5705 ^ 193.6077+-36.3349 ^ definitely 16.6818x faster * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter::executeEffects): * dfg/DFGClobberize.h: (JSC::DFG::clobberize): * dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupToStringOrCallStringConstructor): * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileToStringOrCallStringConstructorOnCell): (JSC::DFG::SpeculativeJIT::speculateNotCell): * dfg/DFGSpeculativeJIT.h: * dfg/DFGSpeculativeJIT32_64.cpp: (JSC::DFG::SpeculativeJIT::compile): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::compile): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileToStringOrCallStringConstructor): (JSC::FTL::DFG::LowerDFGToB3::lowNotCell): (JSC::FTL::DFG::LowerDFGToB3::speculateNotCell): 2017-03-15 Daniel Ehrenberg Switch back to ISO 4217 for Intl CurrencyDigits data https://bugs.webkit.org/show_bug.cgi?id=169182 Previously, a patch switched Intl.NumberFormat to use CLDR data through ICU to get the default number of decimal digits for a currency. However, that change actually violated the ECMA 402 specification, which references ISO 4217 as the data source. This patch reverts to an in-line implementation of that data. Reviewed by Saam Barati. * runtime/IntlNumberFormat.cpp: (JSC::computeCurrencySortKey): (JSC::extractCurrencySortKey): (JSC::computeCurrencyDigits): 2017-03-15 Mark Lam Fix missing exception checks in Interpreter.cpp. https://bugs.webkit.org/show_bug.cgi?id=164964 Reviewed by Saam Barati. * interpreter/Interpreter.cpp: (JSC::eval): (JSC::sizeOfVarargs): (JSC::sizeFrameForVarargs): (JSC::Interpreter::executeProgram): (JSC::Interpreter::executeCall): (JSC::Interpreter::executeConstruct): (JSC::Interpreter::prepareForRepeatCall): (JSC::Interpreter::execute): 2017-03-14 Tomas Popela Wrong condition in offlineasm/risc.rb https://bugs.webkit.org/show_bug.cgi?id=169597 Reviewed by Mark Lam. It's missing the 'and' operator between the conditions. * offlineasm/risc.rb: 2017-03-14 Mark Lam BytecodeGenerator should use the same function to determine if it needs to store the DerivedConstructor in an ArrowFunction lexical environment. https://bugs.webkit.org/show_bug.cgi?id=169647 Reviewed by Michael Saboff. * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::usesDerivedConstructorInArrowFunctionLexicalEnvironment): (JSC::BytecodeGenerator::initializeArrowFunctionContextScopeIfNeeded): (JSC::BytecodeGenerator::emitPutDerivedConstructorToArrowFunctionContextScope): * bytecompiler/BytecodeGenerator.h: 2017-03-13 Filip Pizlo FTL should not flush strict arguments unless it really needs to https://bugs.webkit.org/show_bug.cgi?id=169519 Reviewed by Mark Lam. This is a refinement that we should have done ages ago. This kills some pointless PutStacks in DFG SSA IR. It can sometimes unlock other optimizations. Relanding after I fixed the special cases for CreateArguments-style nodes. * dfg/DFGPreciseLocalClobberize.h: (JSC::DFG::PreciseLocalClobberizeAdaptor::readTop): 2017-03-13 Caio Lima [JSC] It should be possible create a label named let when parsing Statement in non strict mode https://bugs.webkit.org/show_bug.cgi?id=168684 Reviewed by Saam Barati. This patch is fixing a Parser bug to allow define a label named ```let``` in sloppy mode when parsing a Statement. * parser/Parser.cpp: (JSC::Parser::parseStatement): 2017-03-11 Filip Pizlo Structure::willStoreValueSlow needs to keep the property table alive until the end https://bugs.webkit.org/show_bug.cgi?id=169520 Reviewed by Michael Saboff. We use pointers logically interior to `propertyTable` after doing a GC. We need to prevent the compiler from optimizing away pointers to `propertyTable`. * heap/HeapCell.cpp: (JSC::HeapCell::use): * heap/HeapCell.h: (JSC::HeapCell::use): Introduce API for keeping a pointer alive until some point in execution. * runtime/Structure.cpp: (JSC::Structure::willStoreValueSlow): Use HeapCell::use() to keep the pointer alive. 2017-03-10 Mark Lam JSC: BindingNode::bindValue doesn't increase the scope's reference count. https://bugs.webkit.org/show_bug.cgi?id=168546 Reviewed by Saam Barati. We should protect the scope RegisterID with a RefPtr while it is still needed. * bytecompiler/NodesCodegen.cpp: (JSC::ForInNode::emitLoopHeader): (JSC::ForOfNode::emitBytecode): (JSC::BindingNode::bindValue): 2017-03-09 Filip Pizlo WebKit: JSC: JSObject::ensureLength doesn't check if ensureLengthSlow failed https://bugs.webkit.org/show_bug.cgi?id=169215 Reviewed by Mark Lam. This doesn't have a test because it would be a very complicated test. * runtime/JSObject.h: (JSC::JSObject::ensureLength): If ensureLengthSlow returns false, we need to return false. 2017-03-06 Yusuke Suzuki Null pointer crash when loading module with unresolved import also as a script file https://bugs.webkit.org/show_bug.cgi?id=168971 Reviewed by Saam Barati. If linking throws an error, this error should be re-thrown when requesting the same module. * builtins/ModuleLoaderPrototype.js: (globalPrivate.newRegistryEntry): * runtime/JSModuleRecord.cpp: (JSC::JSModuleRecord::link): 2017-03-06 Daniel Ehrenberg Currency digits calculation in Intl.NumberFormat should call out to ICU https://bugs.webkit.org/show_bug.cgi?id=169182 Reviewed by Yusuke Suzuki. * runtime/IntlNumberFormat.cpp: (JSC::computeCurrencyDigits): (JSC::computeCurrencySortKey): Deleted. (JSC::extractCurrencySortKey): Deleted. 2017-03-02 Tomas Popela Incorrect RELEASE_ASSERT in JSGlobalObject::addStaticGlobals() https://bugs.webkit.org/show_bug.cgi?id=169034 Reviewed by Mark Lam. It should not assign to offset, but compare to offset. * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::addStaticGlobals): 2017-02-28 Saam Barati Arm64 disassembler prints "ars" instead of "asr" https://bugs.webkit.org/show_bug.cgi?id=168923 Rubber stamped by Michael Saboff. * disassembler/ARM64/A64DOpcode.cpp: (JSC::ARM64Disassembler::A64DOpcodeBitfield::format): 2017-02-28 Oleksandr Skachkov Use of arguments in arrow function is slow https://bugs.webkit.org/show_bug.cgi?id=168829 Reviewed by Saam Barati. Current patch improves performance access to arguments within arrow functuion by preventing create arguments variable within arrow function, also allow to cache arguments variable. Before arguments variable always have Dynamic resolve type, after patch it can be ClosureVar, that increase performance of access to arguments variable in 9 times inside of the arrow function. * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::BytecodeGenerator): * runtime/JSScope.cpp: (JSC::abstractAccess): 2017-03-08 Yusuke Suzuki [GTK] JSC test stress/arity-check-ftl-throw.js.ftl-no-cjit-validate-sampling-profiler crashing on GTK bot https://bugs.webkit.org/show_bug.cgi?id=160124 Reviewed by Mark Lam. When performing CallVarargs, we will copy values to the stack. Before actually copying values, we need to adjust the stackPointerRegister to ensure copied values are in the allocated stack area. If we do not that, OS can break the values that is stored beyond the stack pointer. For example, signal stack can be constructed on these area, and breaks values. This patch fixes the crash in stress/spread-forward-call-varargs-stack-overflow.js in Linux port. Since Linux ports use signal to suspend and resume threads, signal handler is frequently called when enabling sampling profiler. Thus this crash occurs. * dfg/DFGSpeculativeJIT32_64.cpp: (JSC::DFG::SpeculativeJIT::emitCall): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::emitCall): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstructVarargsSpread): (JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstructVarargs): * jit/SetupVarargsFrame.cpp: (JSC::emitSetupVarargsFrameFastCase): * jit/SetupVarargsFrame.h: 2017-02-23 Filip Pizlo SpeculativeJIT::compilePutByValForIntTypedArray should only do the constant-folding optimization when the constant passes the type check https://bugs.webkit.org/show_bug.cgi?id=168787 Reviewed by Michael Saboff and Mark Lam. * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compilePutByValForIntTypedArray): 2017-02-23 Mark Lam Ensure that the end of the last invalidation point does not extend beyond the end of the buffer. https://bugs.webkit.org/show_bug.cgi?id=168786 Reviewed by Filip Pizlo. In practice, we will always have multiple instructions after invalidation points, and have enough room in the JIT buffer for the invalidation point to work with. However, as a precaution, we can guarantee that there's enough room by always emitting a label just before we link the buffer. The label will emit nop padding if needed. * assembler/LinkBuffer.cpp: (JSC::LinkBuffer::linkCode): 2017-02-23 Keith Miller Unreviewed, fix the cloop build. Needed a #if. * jit/ExecutableAllocator.cpp: 2017-02-22 Carlos Garcia Campos Better handle Thread and RunLoop initialization https://bugs.webkit.org/show_bug.cgi?id=167828 Reviewed by Yusuke Suzuki. * runtime/InitializeThreading.cpp: (JSC::initializeThreading): Do not initialize double_conversion, that is already initialized by WTF, and GC threads that will be initialized by WTF main thread when needed. 2017-02-22 Keith Miller Remove the demand executable allocator https://bugs.webkit.org/show_bug.cgi?id=168754 Reviewed by Saam Barati. We currently only use the demand executable allocator for non-iOS 32-bit platforms. Benchmark results on a MBP indicate there is no appreciable performance difference between a the fixed and demand allocators. In a future patch I will go back through this code and remove more of the abstractions. * JavaScriptCore.xcodeproj/project.pbxproj: * jit/ExecutableAllocator.cpp: (JSC::FixedVMPoolExecutableAllocator::FixedVMPoolExecutableAllocator): (JSC::FixedVMPoolExecutableAllocator::initializeSeparatedWXHeaps): (JSC::FixedVMPoolExecutableAllocator::jitWriteThunkGenerator): (JSC::FixedVMPoolExecutableAllocator::genericWriteToJITRegion): (JSC::ExecutableAllocator::initializeAllocator): (JSC::ExecutableAllocator::ExecutableAllocator): (JSC::FixedVMPoolExecutableAllocator::~FixedVMPoolExecutableAllocator): (JSC::ExecutableAllocator::isValid): (JSC::ExecutableAllocator::underMemoryPressure): (JSC::ExecutableAllocator::memoryPressureMultiplier): (JSC::ExecutableAllocator::allocate): (JSC::ExecutableAllocator::isValidExecutableMemory): (JSC::ExecutableAllocator::getLock): (JSC::ExecutableAllocator::committedByteCount): (JSC::ExecutableAllocator::dumpProfile): (JSC::DemandExecutableAllocator::DemandExecutableAllocator): Deleted. (JSC::DemandExecutableAllocator::~DemandExecutableAllocator): Deleted. (JSC::DemandExecutableAllocator::bytesAllocatedByAllAllocators): Deleted. (JSC::DemandExecutableAllocator::bytesCommittedByAllocactors): Deleted. (JSC::DemandExecutableAllocator::dumpProfileFromAllAllocators): Deleted. (JSC::DemandExecutableAllocator::allocateNewSpace): Deleted. (JSC::DemandExecutableAllocator::notifyNeedPage): Deleted. (JSC::DemandExecutableAllocator::notifyPageIsFree): Deleted. (JSC::DemandExecutableAllocator::allocators): Deleted. (JSC::DemandExecutableAllocator::allocatorsMutex): Deleted. * jit/ExecutableAllocator.h: * jit/ExecutableAllocatorFixedVMPool.cpp: Removed. * jit/JITStubRoutine.h: (JSC::JITStubRoutine::canPerformRangeFilter): (JSC::JITStubRoutine::filteringStartAddress): (JSC::JITStubRoutine::filteringExtentSize): 2017-02-22 Yusuke Suzuki JSModuleNamespace object should have IC https://bugs.webkit.org/show_bug.cgi?id=160590 Reviewed by Saam Barati. This patch optimizes accesses to module namespace objects. 1. Cache the resolutions for module namespace objects. When constructing the module namespace object, we already resolves all the exports. The module namespace object caches this result and leverage it in the later access in getOwnPropertySlot. This avoids resolving bindings through resolveExport. 2. Introduce ModuleNamespaceLoad IC. This patch adds new IC for module namespace objects. The mechanism is simple, getOwnPropertySlot tells us about module namespace object resolution. The IC first checks whether the given object is an expected module namespace object. If this check succeeds, we load the value from the module environment. 3. Introduce DFG/FTL optimization. After exploiting module namespace object accesses in (2), DFG can recognize this in ByteCodeParser. DFG will convert it to CheckCell with the namespace object and GetClosureVar from the cached environment. At that time, we have a chance to fold it to the constant. This optimization improves the performance of accessing to module namespace objects. Before $ time ../../WebKitBuild/module-ic-tot/Release/bin/jsc -m module-assert-access-namespace.js ../../WebKitBuild/module-ic-tot/Release/bin/jsc -m 0.43s user 0.03s system 101% cpu 0.451 total $ time ../../WebKitBuild/module-ic-tot/Release/bin/jsc -m module-assert-access-binding.js ../../WebKitBuild/module-ic-tot/Release/bin/jsc -m 0.08s user 0.02s system 103% cpu 0.104 total After $ time ../../WebKitBuild/module-ic/Release/bin/jsc -m module-assert-access-namespace.js ../../WebKitBuild/module-ic/Release/bin/jsc -m 0.11s user 0.01s system 106% cpu 0.109 total $ time ../../WebKitBuild/module-ic/Release/bin/jsc -m module-assert-access-binding.js ../../WebKitBuild/module-ic/Release/bin/jsc -m module-assert-access-binding.j 0.08s user 0.02s system 102% cpu 0.105 total * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * bytecode/AccessCase.cpp: (JSC::AccessCase::create): (JSC::AccessCase::guardedByStructureCheck): (JSC::AccessCase::canReplace): (JSC::AccessCase::visitWeak): (JSC::AccessCase::generateWithGuard): (JSC::AccessCase::generateImpl): * bytecode/AccessCase.h: * bytecode/GetByIdStatus.cpp: (JSC::GetByIdStatus::GetByIdStatus): (JSC::GetByIdStatus::computeForStubInfoWithoutExitSiteFeedback): (JSC::GetByIdStatus::makesCalls): (JSC::GetByIdStatus::dump): * bytecode/GetByIdStatus.h: (JSC::GetByIdStatus::isModuleNamespace): (JSC::GetByIdStatus::takesSlowPath): (JSC::GetByIdStatus::moduleNamespaceObject): (JSC::GetByIdStatus::moduleEnvironment): (JSC::GetByIdStatus::scopeOffset): * bytecode/ModuleNamespaceAccessCase.cpp: Added. (JSC::ModuleNamespaceAccessCase::ModuleNamespaceAccessCase): (JSC::ModuleNamespaceAccessCase::create): (JSC::ModuleNamespaceAccessCase::~ModuleNamespaceAccessCase): (JSC::ModuleNamespaceAccessCase::clone): (JSC::ModuleNamespaceAccessCase::emit): * bytecode/ModuleNamespaceAccessCase.h: Added. (JSC::ModuleNamespaceAccessCase::moduleNamespaceObject): (JSC::ModuleNamespaceAccessCase::moduleEnvironment): (JSC::ModuleNamespaceAccessCase::scopeOffset): * bytecode/PolymorphicAccess.cpp: (WTF::printInternal): * dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::handleModuleNamespaceLoad): (JSC::DFG::ByteCodeParser::handleGetById): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::loadValue): * jit/Repatch.cpp: (JSC::tryCacheGetByID): * runtime/AbstractModuleRecord.cpp: (JSC::AbstractModuleRecord::getModuleNamespace): * runtime/JSModuleNamespaceObject.cpp: (JSC::JSModuleNamespaceObject::finishCreation): (JSC::JSModuleNamespaceObject::visitChildren): (JSC::getValue): (JSC::JSModuleNamespaceObject::getOwnPropertySlot): (JSC::JSModuleNamespaceObject::getOwnPropertyNames): * runtime/JSModuleNamespaceObject.h: (JSC::isJSModuleNamespaceObject): (JSC::JSModuleNamespaceObject::create): Deleted. (JSC::JSModuleNamespaceObject::createStructure): Deleted. (JSC::JSModuleNamespaceObject::moduleRecord): Deleted. * runtime/JSModuleRecord.h: (JSC::JSModuleRecord::moduleEnvironment): Deleted. * runtime/PropertySlot.h: (JSC::PropertySlot::PropertySlot): (JSC::PropertySlot::domJIT): (JSC::PropertySlot::moduleNamespaceSlot): (JSC::PropertySlot::setValueModuleNamespace): (JSC::PropertySlot::setCacheableCustom): 2017-02-21 Mark Lam Add more missing exception checks detected by running marathon.js. https://bugs.webkit.org/show_bug.cgi?id=168697 Reviewed by Saam Barati. * runtime/StringPrototype.cpp: (JSC::replaceUsingRegExpSearch): (JSC::replaceUsingStringSearch): 2017-02-21 Filip Pizlo Unreviewed, fix cloop. I managed to have my local patch for relanding be the one without the cloop fix. I keep forgetting about cloop! * heap/Heap.cpp: (JSC::Heap::stopThePeriphery): * runtime/JSLock.cpp: 2017-02-21 Mark Lam Add missing exception checks detected by running marathon.js. https://bugs.webkit.org/show_bug.cgi?id=168687 Reviewed by Saam Barati. When running the marathon.js test from https://bugs.webkit.org/show_bug.cgi?id=168580, we get some crashes due to missing exception checks. This patch adds those missing exception checks. * runtime/JSCJSValueInlines.h: (JSC::JSValue::toPropertyKey): * runtime/JSObject.cpp: (JSC::JSObject::getPrimitiveNumber): 2017-02-20 Filip Pizlo The collector thread should only start when the mutator doesn't have heap access https://bugs.webkit.org/show_bug.cgi?id=167737 Reviewed by Keith Miller. This turns the collector thread's workflow into a state machine, so that the mutator thread can run it directly. This reduces the amount of synchronization we do with the collector thread, and means that most apps will never start the collector thread. The collector thread will still start when we need to finish collecting and we don't have heap access. In this new world, "stopping the world" means relinquishing control of collection to the mutator. This means tracking who is conducting collection. I use the GCConductor enum to say who is conducting. It's either GCConductor::Mutator or GCConductor::Collector. I use the term "conn" to refer to the concept of conducting (having the conn, relinquishing the conn, taking the conn). So, stopping the world means giving the mutator the conn. Releasing heap access means giving the collector the conn. This meant bringing back the conservative scan of the calling thread. It turns out that this scan was too slow to be called on each GC increment because apparently setjmp() now does system calls. So, I wrote our own callee save register saving for the GC. Then I had doubts about whether or not it was correct, so I also made it so that the GC only rarely asks for the register state. I think we still want to use my register saving code instead of setjmp because setjmp seems to save things we don't need, and that could make us overly conservative. It turns out that this new scheduling discipline makes the old space-time scheduler perform better than the new stochastic space-time scheduler on systems with fewer than 4 cores. This is because the mutator having the conn enables us to time the mutator<->collector context switches by polling. The OS is never involved. So, we can use super precise timing. This allows the old space-time schduler to shine like it hadn't before. The splay results imply that this is all a good thing. On 2-core systems, this reduces pause times by 40% and it increases throughput about 5%. On 1-core systems, this reduces pause times by half and reduces throughput by 8%. On 4-or-more-core systems, this doesn't seem to have much effect. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::visitChildren): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::dump): (JSC::DFG::numberOfWorklists): (JSC::DFG::ensureWorklistForIndex): (JSC::DFG::existingWorklistForIndexOrNull): (JSC::DFG::existingWorklistForIndex): * dfg/DFGWorklist.h: (JSC::DFG::numberOfWorklists): Deleted. (JSC::DFG::ensureWorklistForIndex): Deleted. (JSC::DFG::existingWorklistForIndexOrNull): Deleted. (JSC::DFG::existingWorklistForIndex): Deleted. * heap/CollectingScope.h: Added. (JSC::CollectingScope::CollectingScope): (JSC::CollectingScope::~CollectingScope): * heap/CollectorPhase.cpp: Added. (JSC::worldShouldBeSuspended): (WTF::printInternal): * heap/CollectorPhase.h: Added. * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::lastGCLength): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): (JSC::FullGCActivityCallback::lastGCLength): * heap/GCConductor.cpp: Added. (JSC::gcConductorShortName): (WTF::printInternal): * heap/GCConductor.h: Added. * heap/GCFinalizationCallback.cpp: Added. (JSC::GCFinalizationCallback::GCFinalizationCallback): (JSC::GCFinalizationCallback::~GCFinalizationCallback): * heap/GCFinalizationCallback.h: Added. (JSC::GCFinalizationCallbackFuncAdaptor::GCFinalizationCallbackFuncAdaptor): (JSC::createGCFinalizationCallback): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::gatherStackRoots): (JSC::Heap::updateObjectCounts): (JSC::Heap::sweepSynchronously): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInCollectorThread): (JSC::Heap::collectInCollectorThread): (JSC::Heap::checkConn): (JSC::Heap::runNotRunningPhase): (JSC::Heap::runBeginPhase): (JSC::Heap::runFixpointPhase): (JSC::Heap::runConcurrentPhase): (JSC::Heap::runReloopPhase): (JSC::Heap::runEndPhase): (JSC::Heap::changePhase): (JSC::Heap::finishChangingPhase): (JSC::Heap::stopThePeriphery): (JSC::Heap::resumeThePeriphery): (JSC::Heap::stopTheMutator): (JSC::Heap::resumeTheMutator): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::collectInMutatorThread): (JSC::Heap::waitForCollector): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::relinquishConn): (JSC::Heap::finishRelinquishingConn): (JSC::Heap::handleNeedFinalize): (JSC::Heap::notifyThreadStopping): (JSC::Heap::finalize): (JSC::Heap::addFinalizationCallback): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::updateAllocationLimits): (JSC::Heap::didFinishCollection): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::notifyIsSafeToCollect): (JSC::Heap::preventCollection): (JSC::Heap::performIncrement): (JSC::Heap::markToFixpoint): Deleted. (JSC::Heap::shouldCollectInThread): Deleted. (JSC::Heap::collectInThread): Deleted. (JSC::Heap::stopTheWorld): Deleted. (JSC::Heap::resumeTheWorld): Deleted. * heap/Heap.h: (JSC::Heap::machineThreads): (JSC::Heap::lastFullGCLength): (JSC::Heap::lastEdenGCLength): (JSC::Heap::increaseLastFullGCLength): * heap/HeapInlines.h: (JSC::Heap::mutatorIsStopped): Deleted. * heap/HeapStatistics.cpp: Removed. * heap/HeapStatistics.h: Removed. * heap/HelpingGCScope.h: Removed. * heap/IncrementalSweeper.cpp: (JSC::IncrementalSweeper::stopSweeping): (JSC::IncrementalSweeper::willFinishSweeping): Deleted. * heap/IncrementalSweeper.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherFromCurrentThread): (JSC::MachineThreads::gatherConservativeRoots): (JSC::callWithCurrentThreadState): * heap/MachineStackMarker.h: * heap/MarkedAllocator.cpp: (JSC::MarkedAllocator::allocateSlowCaseImpl): * heap/MarkedBlock.cpp: (JSC::MarkedBlock::Handle::sweep): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::sweep): * heap/MutatorState.cpp: (WTF::printInternal): * heap/MutatorState.h: * heap/RegisterState.h: Added. * heap/RunningScope.h: Added. (JSC::RunningScope::RunningScope): (JSC::RunningScope::~RunningScope): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::drain): (JSC::SlotVisitor::drainFromShared): (JSC::SlotVisitor::drainInParallelPassively): (JSC::SlotVisitor::donateAll): (JSC::SlotVisitor::donate): * heap/SlotVisitor.h: (JSC::SlotVisitor::codeName): * heap/StochasticSpaceTimeMutatorScheduler.cpp: (JSC::StochasticSpaceTimeMutatorScheduler::beginCollection): (JSC::StochasticSpaceTimeMutatorScheduler::synchronousDrainingDidStall): (JSC::StochasticSpaceTimeMutatorScheduler::timeToStop): * heap/SweepingScope.h: Added. (JSC::SweepingScope::SweepingScope): (JSC::SweepingScope::~SweepingScope): * jit/JITWorklist.cpp: (JSC::JITWorklist::Thread::Thread): * jsc.cpp: (GlobalObject::finishCreation): (functionFlashHeapAccess): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/Options.cpp: (JSC::overrideDefaults): * runtime/Options.h: * runtime/TestRunnerUtils.cpp: (JSC::finalizeStatsAtEndOfTesting): 2017-02-21 Yusuke Suzuki ASSERTION FAILED: "!scope.exception()" with Object.isSealed/isFrozen and uninitialized module bindings https://bugs.webkit.org/show_bug.cgi?id=168605 Reviewed by Saam Barati. We should check exception state after calling getOwnPropertyDescriptor() since it can throw errors. * runtime/ObjectConstructor.cpp: (JSC::objectConstructorIsSealed): (JSC::objectConstructorIsFrozen): 2017-02-20 Mark Lam [Re-landing] CachedCall should let GC know to keep its arguments alive. https://bugs.webkit.org/show_bug.cgi?id=168567 Reviewed by Saam Barati. We fix this by having CachedCall use a MarkedArgumentBuffer to store its arguments instead of a Vector. Also declared CachedCall, MarkedArgumentBuffer, and ProtoCallFrame as WTF_FORBID_HEAP_ALLOCATION because they rely on being stack allocated for correctness. Update: the original patch has a bug in MarkedArgumentBuffer::expandCapacity() where it was copying and calling addMarkSet() on values in m_buffer beyond m_size (up to m_capacity). As a result, depending on the pre-existing values in m_inlineBuffer, this may result in a computed Heap pointer that is wrong, and subsequently, manifest as a crash. This is likely to be the cause of the PLT regression. I don't have a new test for this fix because the issue relies on sufficiently bad values randomly showing up in m_inlineBuffer when we do an ensureCapacity() which calls expandCapacity(). * interpreter/CachedCall.h: (JSC::CachedCall::CachedCall): (JSC::CachedCall::call): (JSC::CachedCall::clearArguments): (JSC::CachedCall::appendArgument): (JSC::CachedCall::setArgument): Deleted. * interpreter/CallFrame.h: (JSC::ExecState::emptyList): * interpreter/Interpreter.cpp: (JSC::Interpreter::prepareForRepeatCall): * interpreter/Interpreter.h: * interpreter/ProtoCallFrame.h: * runtime/ArgList.cpp: (JSC::MarkedArgumentBuffer::slowEnsureCapacity): (JSC::MarkedArgumentBuffer::expandCapacity): (JSC::MarkedArgumentBuffer::slowAppend): * runtime/ArgList.h: (JSC::MarkedArgumentBuffer::append): (JSC::MarkedArgumentBuffer::ensureCapacity): * runtime/StringPrototype.cpp: (JSC::replaceUsingRegExpSearch): * runtime/VM.cpp: (JSC::VM::VM): * runtime/VM.h: 2017-02-20 Commit Queue Unreviewed, rolling out r212618. https://bugs.webkit.org/show_bug.cgi?id=168609 "Appears to cause PLT regression" (Requested by mlam on #webkit). Reverted changeset: "CachedCall should let GC know to keep its arguments alive." https://bugs.webkit.org/show_bug.cgi?id=168567 http://trac.webkit.org/changeset/212618 2017-02-19 Mark Lam BytecodeGenerator should not iterate its m_controlFlowScopeStack using a pointer bump. https://bugs.webkit.org/show_bug.cgi?id=168585 Reviewed by Yusuke Suzuki. This is because m_controlFlowScopeStack is a SegmentedVector, and entries for consecutive indices in the vector are not guaranteed to be consecutive in memory layout. Instead, we should be using indexing instead. This issue was detected by the marathon.js test from https://bugs.webkit.org/show_bug.cgi?id=168580. * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::emitJumpViaFinallyIfNeeded): (JSC::BytecodeGenerator::emitReturnViaFinallyIfNeeded): 2017-02-20 Manuel Rego Casasnovas [css-grid] Remove compilation flag ENABLE_CSS_GRID_LAYOUT https://bugs.webkit.org/show_bug.cgi?id=167693 Reviewed by Sergio Villar Senin. * Configurations/FeatureDefines.xcconfig: 2017-02-19 Commit Queue Unreviewed, rolling out r212472. https://bugs.webkit.org/show_bug.cgi?id=168584 Broke CLoop builds when r212466 was rolled out in r212616 (Requested by rniwa on #webkit). Reverted changeset: "Unreviewed, fix cloop build." http://trac.webkit.org/changeset/212472 2017-02-19 Mark Lam functionTestWasmModuleFunctions() should use a MarkedArgumentBuffer for storing args instead of a Vector. https://bugs.webkit.org/show_bug.cgi?id=168574 Reviewed by Filip Pizlo. * jsc.cpp: (callWasmFunction): (functionTestWasmModuleFunctions): * runtime/ArgList.h: 2017-02-19 Mark Lam CachedCall should let GC know to keep its arguments alive. https://bugs.webkit.org/show_bug.cgi?id=168567 Reviewed by Saam Barati. We fix this by having CachedCall use a MarkedArgumentBuffer to store its arguments instead of a Vector. Also declared CachedCall, MarkedArgumentBuffer, and ProtoCallFrame as WTF_FORBID_HEAP_ALLOCATION because they rely on being stack allocated for correctness. * interpreter/CachedCall.h: (JSC::CachedCall::CachedCall): (JSC::CachedCall::call): (JSC::CachedCall::clearArguments): (JSC::CachedCall::appendArgument): (JSC::CachedCall::setArgument): Deleted. * interpreter/CallFrame.h: (JSC::ExecState::emptyList): * interpreter/Interpreter.cpp: (JSC::Interpreter::prepareForRepeatCall): * interpreter/Interpreter.h: * interpreter/ProtoCallFrame.h: * runtime/ArgList.cpp: (JSC::MarkedArgumentBuffer::expandCapacity): * runtime/ArgList.h: (JSC::MarkedArgumentBuffer::ensureCapacity): * runtime/StringPrototype.cpp: (JSC::replaceUsingRegExpSearch): * runtime/VM.cpp: (JSC::VM::VM): * runtime/VM.h: 2017-02-19 Commit Queue Unreviewed, rolling out r212466. https://bugs.webkit.org/show_bug.cgi?id=168577 causes crashes on AArch64 on linux, maybe it's causing crashes on iOS too (Requested by pizlo on #webkit). Reverted changeset: "The collector thread should only start when the mutator doesn't have heap access" https://bugs.webkit.org/show_bug.cgi?id=167737 http://trac.webkit.org/changeset/212466 2017-02-17 Michael Saboff Improve ARM64 disassembler handling of pseudo ops, unsupported opcodes and zero reg https://bugs.webkit.org/show_bug.cgi?id=168527 Reviewed by Filip Pizlo. Added support for data processing 1 source instructions like rbit, rev, clz and cls. Added support for the FP conditional select instruction, fcsel. Consolidated the two classes for handling dmb instructions into one class. Fixed the instruction selection mask in the integer conditional select class, A64DOpcodeConditionalSelect. Fixed the processing of extract instruction (extr) including the rotate right (ror) pseudo instruction. Changed the printing of x31 and w31 to xzr and wzr as operands according to the spec. Added support for common pseudo instructions. This includes: - mvn x1, X2 in place of orn x1, xzr, x2 - lsl x3, x4, #count in place of ubfiz x3, x4, #count, #count - smull x5, w6, w7 in place of smaddl x5, w6, w7, XZR - More understandable mov x8, #-304 in place of movn x8, #0x12f - Eliminated xzr from register index loads and stores, outputing ldr x10, [x11] instead of ldr x10, [x11, xzr] Changed the move wide instructions to use hex literals for movz and movk. This makes it much easier to decifer sequences of wide moves for large literals. Before After movz x17, #26136 movz x17, #0x6618 movk x17, #672, lsl #16 movk x17, #0x2a0, lsl #16 movk x17, #1, lsl #32 movk x17, #0x1, lsl #32 Verified that all instructions currently generated by the JSC stress tests are disassembled. * disassembler/ARM64/A64DOpcode.cpp: (JSC::ARM64Disassembler::A64DOpcodeBitfield::format): (JSC::ARM64Disassembler::A64DOpcodeDataProcessing1Source::format): (JSC::ARM64Disassembler::A64DOpcodeDataProcessing2Source::format): (JSC::ARM64Disassembler::A64DOpcodeDataProcessing3Source::format): (JSC::ARM64Disassembler::A64DOpcodeExtract::format): (JSC::ARM64Disassembler::A64DOpcodeFloatingPointConditionalSelect::format): (JSC::ARM64Disassembler::A64DOpcodeFloatingPointIntegerConversions::format): (JSC::ARM64Disassembler::A64DOpcodeDmb::format): (JSC::ARM64Disassembler::A64DOpcodeLoadStoreImmediate::format): (JSC::ARM64Disassembler::A64DOpcodeLoadStoreRegisterOffset::format): (JSC::ARM64Disassembler::A64DOpcodeLoadStoreRegisterPair::format): (JSC::ARM64Disassembler::A64DOpcodeLoadStoreUnsignedImmediate::format): (JSC::ARM64Disassembler::A64DOpcodeLogicalShiftedRegister::format): (JSC::ARM64Disassembler::A64DOpcodeMoveWide::format): (JSC::ARM64Disassembler::A64DOpcodeDmbIsh::format): Deleted. (JSC::ARM64Disassembler::A64DOpcodeDmbIshSt::format): Deleted. * disassembler/ARM64/A64DOpcode.h: (JSC::ARM64Disassembler::A64DOpcode::appendSignedImmediate64): (JSC::ARM64Disassembler::A64DOpcode::appendUnsignedHexImmediate): (JSC::ARM64Disassembler::A64DOpcodeDataProcessing1Source::opName): (JSC::ARM64Disassembler::A64DOpcodeDataProcessing1Source::sBit): (JSC::ARM64Disassembler::A64DOpcodeDataProcessing1Source::opCode): (JSC::ARM64Disassembler::A64DOpcodeDataProcessing1Source::opCode2): (JSC::ARM64Disassembler::A64DOpcodeDataProcessing1Source::opNameIndex): (JSC::ARM64Disassembler::A64DOpcodeDataProcessing3Source::opName): (JSC::ARM64Disassembler::A64DOpcodeFloatingPointConditionalSelect::opName): (JSC::ARM64Disassembler::A64DOpcodeFloatingPointConditionalSelect::condition): (JSC::ARM64Disassembler::A64DOpcodeDmb::option): (JSC::ARM64Disassembler::A64DOpcodeDmb::crM): (JSC::ARM64Disassembler::A64DOpcodeLogicalShiftedRegister::isMov): (JSC::ARM64Disassembler::A64DOpcodeDmbIsh::opName): Deleted. (JSC::ARM64Disassembler::A64DOpcodeDmbIshSt::opName): Deleted. 2017-02-17 Zan Dobersek [GLib] GCActivityCallback::scheduleTimer() keeps pushing dispatch into the future https://bugs.webkit.org/show_bug.cgi?id=168363 Reviewed by Carlos Garcia Campos. Mimic the USE(CF) implementation of GCActivityCallback and HeapTimer by scheduling the timer a decade into the future instead of completely cancelling it. That way new dispatch times for GCActivityCallback can be computed by simply deducting the difference in the new and previous delay from the GSource's current dispatch time. Previously we handled an extra 'paused' state (where m_delay was -1) and allowed for a delay of an infinite value to be valid, complicating the next dispatch time computation. HeapTimer gains the static s_decade variable. The dispatch function in heapTimerSourceFunctions only dispatches the callback, which now delays the GSource by a decade. HeapTimer::scheduleTimer() simply schedules the source to dispatch in the specified amount of time, and cancelTimer() 'cancels' the source by setting the dispatch time to a decade. GCActivityCallback constructor initializes the delay to the s_decade value and immediately sets the ready time for GSource a decade into the future, avoiding the default -1 value as the ready time that would cause problems in scheduleTimer(). scheduleTimer() doesn't special-case the zero-delay value anymore, instead it just computes the difference between the old and the new delay and rolls back the GSource's ready time for that amount. cancelTimer() sets m_delay to the decade value and delays the GSource for that same amount. * heap/GCActivityCallback.cpp: (JSC::GCActivityCallback::GCActivityCallback): (JSC::GCActivityCallback::scheduleTimer): (JSC::GCActivityCallback::cancelTimer): * heap/GCActivityCallback.h: * heap/HeapTimer.cpp: (JSC::HeapTimer::HeapTimer): (JSC::HeapTimer::scheduleTimer): (JSC::HeapTimer::cancelTimer): * heap/HeapTimer.h: 2017-02-16 Yusuke Suzuki [JSC] Drop PassRefPtr from ArrayBuffer https://bugs.webkit.org/show_bug.cgi?id=168455 Reviewed by Geoffrey Garen. This patch finally drops all the PassRefPtr in JSC. We changed PassRefPtr to RefPtr&&. Since ArrayBuffer may be nullptr if the array is neutered, we hold it as RefPtr<> instead of Ref<>. And we also drops 2 files, TypedArrayBase.h and IntegralTypedArrayBase.h. They are not used (and they are not referenced from the project file). * inspector/JavaScriptCallFrame.h: * jsc.cpp: (functionDollarAgentReceiveBroadcast): * runtime/ArrayBufferView.cpp: (JSC::ArrayBufferView::ArrayBufferView): * runtime/ArrayBufferView.h: (JSC::ArrayBufferView::possiblySharedBuffer): (JSC::ArrayBufferView::unsharedBuffer): (JSC::ArrayBufferView::verifySubRangeLength): (JSC::ArrayBufferView::clampOffsetAndNumElements): * runtime/ClassInfo.h: * runtime/DataView.cpp: (JSC::DataView::DataView): (JSC::DataView::create): * runtime/DataView.h: * runtime/GenericTypedArrayView.h: * runtime/GenericTypedArrayViewInlines.h: (JSC::GenericTypedArrayView::GenericTypedArrayView): (JSC::GenericTypedArrayView::create): (JSC::GenericTypedArrayView::subarray): * runtime/IntegralTypedArrayBase.h: Removed. * runtime/JSArrayBuffer.cpp: (JSC::JSArrayBuffer::JSArrayBuffer): (JSC::JSArrayBuffer::create): * runtime/JSArrayBuffer.h: * runtime/JSArrayBufferPrototype.cpp: (JSC::arrayBufferProtoFuncSlice): * runtime/JSArrayBufferView.cpp: (JSC::JSArrayBufferView::ConstructionContext::ConstructionContext): * runtime/JSArrayBufferView.h: * runtime/JSArrayBufferViewInlines.h: (JSC::JSArrayBufferView::possiblySharedImpl): (JSC::JSArrayBufferView::unsharedImpl): * runtime/JSCell.cpp: (JSC::JSCell::slowDownAndWasteMemory): (JSC::JSCell::getTypedArrayImpl): * runtime/JSCell.h: * runtime/JSDataView.cpp: (JSC::JSDataView::create): (JSC::JSDataView::possiblySharedTypedImpl): (JSC::JSDataView::unsharedTypedImpl): (JSC::JSDataView::getTypedArrayImpl): * runtime/JSDataView.h: * runtime/JSGenericTypedArrayView.h: * runtime/JSGenericTypedArrayViewConstructorInlines.h: (JSC::constructGenericTypedArrayViewWithArguments): * runtime/JSGenericTypedArrayViewInlines.h: (JSC::JSGenericTypedArrayView::create): (JSC::JSGenericTypedArrayView::possiblySharedTypedImpl): (JSC::JSGenericTypedArrayView::unsharedTypedImpl): (JSC::JSGenericTypedArrayView::getTypedArrayImpl): * runtime/JSGenericTypedArrayViewPrototypeFunctions.h: (JSC::genericTypedArrayViewPrivateFuncSubarrayCreate): * runtime/JSTypedArrays.cpp: (JSC::createUint8TypedArray): * runtime/TypedArrayBase.h: Removed. 2017-02-16 Keith Miller ASSERTION FAILED: vm.heap.mutatorState() == MutatorState::Running || vm.apiLock().ownerThread() != std::this_thread::get_id() https://bugs.webkit.org/show_bug.cgi?id=168354 Reviewed by Geoffrey Garen. Instead of adding a custom vmEntryGlobalObject for the debugger we can just have it use vmEntryScope instead. * debugger/Debugger.cpp: (JSC::Debugger::detach): * interpreter/CallFrame.cpp: (JSC::CallFrame::vmEntryGlobalObjectForDebuggerDetach): Deleted. * interpreter/CallFrame.h: 2017-02-16 Filip Pizlo Unreviewed, fix cloop build. * heap/Heap.cpp: (JSC::Heap::stopThePeriphery): * runtime/JSLock.cpp: 2017-02-10 Filip Pizlo The collector thread should only start when the mutator doesn't have heap access https://bugs.webkit.org/show_bug.cgi?id=167737 Reviewed by Keith Miller. This turns the collector thread's workflow into a state machine, so that the mutator thread can run it directly. This reduces the amount of synchronization we do with the collector thread, and means that most apps will never start the collector thread. The collector thread will still start when we need to finish collecting and we don't have heap access. In this new world, "stopping the world" means relinquishing control of collection to the mutator. This means tracking who is conducting collection. I use the GCConductor enum to say who is conducting. It's either GCConductor::Mutator or GCConductor::Collector. I use the term "conn" to refer to the concept of conducting (having the conn, relinquishing the conn, taking the conn). So, stopping the world means giving the mutator the conn. Releasing heap access means giving the collector the conn. This meant bringing back the conservative scan of the calling thread. It turns out that this scan was too slow to be called on each GC increment because apparently setjmp() now does system calls. So, I wrote our own callee save register saving for the GC. Then I had doubts about whether or not it was correct, so I also made it so that the GC only rarely asks for the register state. I think we still want to use my register saving code instead of setjmp because setjmp seems to save things we don't need, and that could make us overly conservative. It turns out that this new scheduling discipline makes the old space-time scheduler perform better than the new stochastic space-time scheduler on systems with fewer than 4 cores. This is because the mutator having the conn enables us to time the mutator<->collector context switches by polling. The OS is never involved. So, we can use super precise timing. This allows the old space-time schduler to shine like it hadn't before. The splay results imply that this is all a good thing. On 2-core systems, this reduces pause times by 40% and it increases throughput about 5%. On 1-core systems, this reduces pause times by half and reduces throughput by 8%. On 4-or-more-core systems, this doesn't seem to have much effect. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::dump): (JSC::DFG::numberOfWorklists): (JSC::DFG::ensureWorklistForIndex): (JSC::DFG::existingWorklistForIndexOrNull): (JSC::DFG::existingWorklistForIndex): * dfg/DFGWorklist.h: (JSC::DFG::numberOfWorklists): Deleted. (JSC::DFG::ensureWorklistForIndex): Deleted. (JSC::DFG::existingWorklistForIndexOrNull): Deleted. (JSC::DFG::existingWorklistForIndex): Deleted. * heap/CollectingScope.h: Added. (JSC::CollectingScope::CollectingScope): (JSC::CollectingScope::~CollectingScope): * heap/CollectorPhase.cpp: Added. (JSC::worldShouldBeSuspended): (WTF::printInternal): * heap/CollectorPhase.h: Added. * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::lastGCLength): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): (JSC::FullGCActivityCallback::lastGCLength): * heap/GCConductor.cpp: Added. (JSC::gcConductorShortName): (WTF::printInternal): * heap/GCConductor.h: Added. * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::gatherStackRoots): (JSC::Heap::updateObjectCounts): (JSC::Heap::shouldCollectInCollectorThread): (JSC::Heap::collectInCollectorThread): (JSC::Heap::checkConn): (JSC::Heap::runCurrentPhase): (JSC::Heap::runNotRunningPhase): (JSC::Heap::runBeginPhase): (JSC::Heap::runFixpointPhase): (JSC::Heap::runConcurrentPhase): (JSC::Heap::runReloopPhase): (JSC::Heap::runEndPhase): (JSC::Heap::changePhase): (JSC::Heap::finishChangingPhase): (JSC::Heap::stopThePeriphery): (JSC::Heap::resumeThePeriphery): (JSC::Heap::stopTheMutator): (JSC::Heap::resumeTheMutator): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::collectInMutatorThread): (JSC::Heap::collectInMutatorThreadImpl): (JSC::Heap::waitForCollector): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::relinquishConn): (JSC::Heap::finishRelinquishingConn): (JSC::Heap::handleNeedFinalize): (JSC::Heap::notifyThreadStopping): (JSC::Heap::finalize): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::updateAllocationLimits): (JSC::Heap::didFinishCollection): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::preventCollection): (JSC::Heap::performIncrement): (JSC::Heap::markToFixpoint): Deleted. (JSC::Heap::shouldCollectInThread): Deleted. (JSC::Heap::collectInThread): Deleted. (JSC::Heap::stopTheWorld): Deleted. (JSC::Heap::resumeTheWorld): Deleted. * heap/Heap.h: (JSC::Heap::machineThreads): (JSC::Heap::lastFullGCLength): (JSC::Heap::lastEdenGCLength): (JSC::Heap::increaseLastFullGCLength): * heap/HeapInlines.h: (JSC::Heap::mutatorIsStopped): Deleted. * heap/HeapStatistics.cpp: Removed. * heap/HeapStatistics.h: Removed. * heap/HelpingGCScope.h: Removed. * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherFromCurrentThread): (JSC::MachineThreads::gatherConservativeRoots): * heap/MachineStackMarker.h: * heap/MarkedBlock.cpp: (JSC::MarkedBlock::Handle::sweep): * heap/MutatorState.cpp: (WTF::printInternal): * heap/MutatorState.h: * heap/RegisterState.h: Added. * heap/SlotVisitor.cpp: (JSC::SlotVisitor::drainFromShared): (JSC::SlotVisitor::drainInParallelPassively): (JSC::SlotVisitor::donateAll): * heap/StochasticSpaceTimeMutatorScheduler.cpp: (JSC::StochasticSpaceTimeMutatorScheduler::beginCollection): (JSC::StochasticSpaceTimeMutatorScheduler::synchronousDrainingDidStall): (JSC::StochasticSpaceTimeMutatorScheduler::timeToStop): * heap/SweepingScope.h: Added. (JSC::SweepingScope::SweepingScope): (JSC::SweepingScope::~SweepingScope): * jit/JITWorklist.cpp: (JSC::JITWorklist::Thread::Thread): * jsc.cpp: (GlobalObject::finishCreation): (functionFlashHeapAccess): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/Options.cpp: (JSC::overrideDefaults): * runtime/Options.h: * runtime/TestRunnerUtils.cpp: (JSC::finalizeStatsAtEndOfTesting): 2017-02-16 Anders Carlsson Remove EFL from JavaScriptCore https://bugs.webkit.org/show_bug.cgi?id=168459 Reviewed by Geoffrey Garen. * heap/GCActivityCallback.cpp: (JSC::GCActivityCallback::GCActivityCallback): (JSC::GCActivityCallback::cancelTimer): (JSC::GCActivityCallback::didAllocate): * heap/GCActivityCallback.h: * heap/HeapTimer.cpp: (JSC::HeapTimer::add): Deleted. (JSC::HeapTimer::stop): Deleted. (JSC::HeapTimer::timerEvent): Deleted. * heap/HeapTimer.h: * inspector/EventLoop.cpp: (Inspector::EventLoop::cycle): * jsc.cpp: (main): * tools/CodeProfiling.cpp: (JSC::CodeProfiling::begin): (JSC::CodeProfiling::end): 2017-02-15 Brian Burg [Cocoa] Web Inspector: Inspector::fromProtocolString should return std::optional https://bugs.webkit.org/show_bug.cgi?id=168018 Reviewed by Joseph Pecoraro. These methods parse untrusted string inputs, so they should return an optional instead of asserting or crashing when the input is not usable. Update various pieces of generated code to handle the error case gracefully. * inspector/scripts/codegen/generate_objc_backend_dispatcher_implementation.py: (ObjCBackendDispatcherImplementationGenerator._generate_conversions_for_command): (ObjCBackendDispatcherImplementationGenerator._generate_invocation_for_command): The local variable holding the ObjC-friendly converted value should take a std::optional when converting an enum from a string into an NS_ENUM value. If the enum command parameter is not optional, then send a response with a command failure message and return. The optional enum parameter case is not handled correctly, but no existing code requires it. * inspector/scripts/codegen/generate_objc_protocol_type_conversions_header.py: (ObjCProtocolTypeConversionsHeaderGenerator._generate_enum_from_protocol_string): Fix signature and remove default case ASSERT_NOT_REACHED. * inspector/scripts/codegen/generate_objc_protocol_type_conversions_implementation.py: (ObjCProtocolTypeConversionsImplementationGenerator._generate_type_factory_method_implementation): Since this code assumes all inputs to be valid and throws an exception otherwise, we try to convert the enum and throw an exception if it's nullopt. If it's valid, write to outValue. * inspector/scripts/codegen/generate_objc_protocol_types_implementation.py: (ObjCProtocolTypesImplementationGenerator._generate_init_method_for_payload): The local variable holding the ObjC-friendly converted value should take a std::optional when converting an enum from a string into an NS_ENUM value. If the enum command parameter is not optional, then throw an exception if the value is nullopt. Otherwise, allow it to be empty. * inspector/scripts/codegen/objc_generator.py: (ObjCGenerator.protocol_to_objc_expression_for_member): Unconditionally unwrap the optional. This expression is only used inside the typechecked ObjC protocol objects. In this case we are guaranteed to have already initialized the enum with a valid value, but must store it as a string inside a wrapped InspectorObject. The getter needs to re-convert the stored string into an NS_ENUM value. * inspector/scripts/codegen/objc_generator_templates.py: Update type template for fromProtocolString(). * inspector/scripts/tests/all/expected/definitions-with-mac-platform.json-result: * inspector/scripts/tests/generic/expected/commands-with-async-attribute.json-result: * inspector/scripts/tests/generic/expected/commands-with-optional-call-return-parameters.json-result: * inspector/scripts/tests/generic/expected/definitions-with-mac-platform.json-result: * inspector/scripts/tests/generic/expected/domain-availability.json-result: * inspector/scripts/tests/generic/expected/domains-with-varying-command-sizes.json-result: * inspector/scripts/tests/generic/expected/enum-values.json-result: * inspector/scripts/tests/generic/expected/events-with-optional-parameters.json-result: * inspector/scripts/tests/generic/expected/generate-domains-with-feature-guards.json-result: * inspector/scripts/tests/generic/expected/same-type-id-different-domain.json-result: * inspector/scripts/tests/generic/expected/shadowed-optional-type-setters.json-result: * inspector/scripts/tests/generic/expected/type-declaration-aliased-primitive-type.json-result: * inspector/scripts/tests/generic/expected/type-declaration-array-type.json-result: * inspector/scripts/tests/generic/expected/type-declaration-enum-type.json-result: * inspector/scripts/tests/generic/expected/type-declaration-object-type.json-result: * inspector/scripts/tests/generic/expected/type-requiring-runtime-casts.json-result: * inspector/scripts/tests/generic/expected/worker-supported-domains.json-result: * inspector/scripts/tests/ios/expected/definitions-with-mac-platform.json-result: * inspector/scripts/tests/mac/expected/definitions-with-mac-platform.json-result: Rebaseline tests. 2017-02-16 Keith Miller ASSERTION FAILED: vm.heap.mutatorState() == MutatorState::Running || vm.apiLock().ownerThread() != std::this_thread::get_id() https://bugs.webkit.org/show_bug.cgi?id=168354 Reviewed by Filip Pizlo. Add a new vmEntryGlobalObject method for the debugger so that the debugger does not crash in debug builds when trying to detach itself from a global object. * debugger/Debugger.cpp: (JSC::Debugger::detach): * interpreter/CallFrame.cpp: (JSC::CallFrame::vmEntryGlobalObjectForDebuggerDetach): * interpreter/CallFrame.h: 2017-02-16 Keith Miller Refactor AccessCase to be more like B3Value https://bugs.webkit.org/show_bug.cgi?id=168408 Reviewed by Filip Pizlo. This patch makes AccessCase (and new subclasses) more like B3Value. In the new system each type has an associated AccessCase subclass. For instance any getter should use the GetterSetterAccessCase subclass. The new system is easier to follow since you no longer need to know exactly which members are used by which types. The subclass to AccessType mapping is: GetterSetterAccessCase: Getter CustomAccessorGetter CustomValueGetter Setter ProxyableAccessCase: Load Miss GetGetter IntrinsicGetterAccessCase: IntrinsicGetter AccessCase: Everything else It also has the additional advantage that it uses less memory for the cases where we would have needed rare data in the past but that case would only use a small bit of it. This patch also removes megamorphic loads and renames some TryGetById related enum values from Pure to Try. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * bytecode/AccessCase.cpp: Added. (JSC::AccessCase::AccessCase): (JSC::AccessCase::create): (JSC::AccessCase::~AccessCase): (JSC::AccessCase::fromStructureStubInfo): (JSC::AccessCase::clone): (JSC::AccessCase::commit): (JSC::AccessCase::guardedByStructureCheck): (JSC::AccessCase::doesCalls): (JSC::AccessCase::couldStillSucceed): (JSC::AccessCase::canReplace): (JSC::AccessCase::dump): (JSC::AccessCase::visitWeak): (JSC::AccessCase::propagateTransitions): (JSC::AccessCase::generateWithGuard): (JSC::AccessCase::generate): (JSC::AccessCase::generateImpl): * bytecode/AccessCase.h: Added. (JSC::AccessCase::as): (JSC::AccessCase::create): (JSC::AccessCase::type): (JSC::AccessCase::state): (JSC::AccessCase::offset): (JSC::AccessCase::structure): (JSC::AccessCase::newStructure): (JSC::AccessCase::conditionSet): (JSC::AccessCase::alternateBase): (JSC::AccessCase::additionalSet): (JSC::AccessCase::viaProxy): (JSC::AccessCase::isGetter): (JSC::AccessCase::isAccessor): (JSC::AccessCase::dumpImpl): (JSC::AccessCase::resetState): * bytecode/GetByIdStatus.cpp: (JSC::GetByIdStatus::computeForStubInfoWithoutExitSiteFeedback): * bytecode/GetterSetterAccessCase.cpp: Added. (JSC::GetterSetterAccessCase::GetterSetterAccessCase): (JSC::GetterSetterAccessCase::create): (JSC::GetterSetterAccessCase::~GetterSetterAccessCase): (JSC::GetterSetterAccessCase::clone): (JSC::GetterSetterAccessCase::alternateBase): (JSC::GetterSetterAccessCase::dumpImpl): (JSC::GetterSetterAccessCase::emitDOMJITGetter): * bytecode/GetterSetterAccessCase.h: Added. (JSC::GetterSetterAccessCase::callLinkInfo): (JSC::GetterSetterAccessCase::customSlotBase): (JSC::GetterSetterAccessCase::domJIT): * bytecode/IntrinsicGetterAccessCase.cpp: Added. (JSC::IntrinsicGetterAccessCase::IntrinsicGetterAccessCase): (JSC::IntrinsicGetterAccessCase::create): (JSC::IntrinsicGetterAccessCase::~IntrinsicGetterAccessCase): (JSC::IntrinsicGetterAccessCase::clone): * bytecode/IntrinsicGetterAccessCase.h: Added. (JSC::IntrinsicGetterAccessCase::intrinsicFunction): (JSC::IntrinsicGetterAccessCase::intrinsic): * bytecode/PolymorphicAccess.cpp: (JSC::PolymorphicAccess::regenerate): (WTF::printInternal): (JSC::AccessCase::AccessCase): Deleted. (JSC::AccessCase::tryGet): Deleted. (JSC::AccessCase::get): Deleted. (JSC::AccessCase::megamorphicLoad): Deleted. (JSC::AccessCase::replace): Deleted. (JSC::AccessCase::transition): Deleted. (JSC::AccessCase::setter): Deleted. (JSC::AccessCase::in): Deleted. (JSC::AccessCase::getLength): Deleted. (JSC::AccessCase::getIntrinsic): Deleted. (JSC::AccessCase::~AccessCase): Deleted. (JSC::AccessCase::fromStructureStubInfo): Deleted. (JSC::AccessCase::clone): Deleted. (JSC::AccessCase::commit): Deleted. (JSC::AccessCase::guardedByStructureCheck): Deleted. (JSC::AccessCase::alternateBase): Deleted. (JSC::AccessCase::doesCalls): Deleted. (JSC::AccessCase::couldStillSucceed): Deleted. (JSC::AccessCase::canBeReplacedByMegamorphicLoad): Deleted. (JSC::AccessCase::canReplace): Deleted. (JSC::AccessCase::dump): Deleted. (JSC::AccessCase::visitWeak): Deleted. (JSC::AccessCase::propagateTransitions): Deleted. (JSC::AccessCase::generateWithGuard): Deleted. (JSC::AccessCase::generate): Deleted. (JSC::AccessCase::generateImpl): Deleted. (JSC::AccessCase::emitDOMJITGetter): Deleted. * bytecode/PolymorphicAccess.h: (JSC::AccessCase::type): Deleted. (JSC::AccessCase::state): Deleted. (JSC::AccessCase::offset): Deleted. (JSC::AccessCase::viaProxy): Deleted. (JSC::AccessCase::structure): Deleted. (JSC::AccessCase::newStructure): Deleted. (JSC::AccessCase::conditionSet): Deleted. (JSC::AccessCase::intrinsicFunction): Deleted. (JSC::AccessCase::intrinsic): Deleted. (JSC::AccessCase::domJIT): Deleted. (JSC::AccessCase::additionalSet): Deleted. (JSC::AccessCase::customSlotBase): Deleted. (JSC::AccessCase::isGetter): Deleted. (JSC::AccessCase::callLinkInfo): Deleted. (JSC::AccessCase::RareData::RareData): Deleted. * bytecode/ProxyableAccessCase.cpp: Added. (JSC::ProxyableAccessCase::ProxyableAccessCase): (JSC::ProxyableAccessCase::create): (JSC::ProxyableAccessCase::~ProxyableAccessCase): (JSC::ProxyableAccessCase::clone): (JSC::ProxyableAccessCase::dumpImpl): * bytecode/ProxyableAccessCase.h: Added. * bytecode/PutByIdStatus.cpp: (JSC::PutByIdStatus::computeForStubInfo): * bytecode/StructureStubInfo.cpp: (JSC::StructureStubInfo::reset): * bytecode/StructureStubInfo.h: * dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::parseBlock): * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileTryGetById): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileNode): (JSC::FTL::DFG::LowerDFGToB3::compileGetById): * jit/IntrinsicEmitter.cpp: (JSC::IntrinsicGetterAccessCase::canEmitIntrinsicGetter): (JSC::IntrinsicGetterAccessCase::emitIntrinsicGetter): (JSC::AccessCase::canEmitIntrinsicGetter): Deleted. (JSC::AccessCase::emitIntrinsicGetter): Deleted. * jit/JITOperations.cpp: * jit/JITPropertyAccess.cpp: (JSC::JIT::emit_op_try_get_by_id): * jit/JITPropertyAccess32_64.cpp: (JSC::JIT::emit_op_try_get_by_id): * jit/Repatch.cpp: (JSC::tryCacheGetByID): (JSC::tryCachePutByID): (JSC::tryRepatchIn): * jit/Repatch.h: * runtime/Options.h: 2017-02-16 Filip Pizlo JSONParseTest needs to hold the lock when the VM is destroyed https://bugs.webkit.org/show_bug.cgi?id=168450 Rubber stamped by Alex Christensen. * API/tests/JSONParseTest.cpp: (testJSONParse): 2017-02-16 Yusuke Suzuki [JSC] Drop PassRefPtr in inspector/ https://bugs.webkit.org/show_bug.cgi?id=168420 Reviewed by Alex Christensen. Drop PassRefPtr uses. And use Ref and Ref as much as possible. It drops some unnecessary null checks. * debugger/Debugger.cpp: (JSC::Debugger::hasBreakpoint): (JSC::Debugger::currentDebuggerCallFrame): * debugger/Debugger.h: * inspector/AsyncStackTrace.cpp: (Inspector::AsyncStackTrace::create): (Inspector::AsyncStackTrace::AsyncStackTrace): (Inspector::AsyncStackTrace::buildInspectorObject): (Inspector::AsyncStackTrace::truncate): * inspector/AsyncStackTrace.h: * inspector/ConsoleMessage.cpp: (Inspector::ConsoleMessage::ConsoleMessage): * inspector/ConsoleMessage.h: * inspector/InjectedScriptManager.cpp: (Inspector::InjectedScriptManager::InjectedScriptManager): (Inspector::InjectedScriptManager::injectedScriptHost): * inspector/InjectedScriptManager.h: * inspector/JSGlobalObjectConsoleClient.cpp: (Inspector::JSGlobalObjectConsoleClient::messageWithTypeAndLevel): (Inspector::JSGlobalObjectConsoleClient::count): (Inspector::JSGlobalObjectConsoleClient::timeEnd): (Inspector::JSGlobalObjectConsoleClient::timeStamp): (Inspector::JSGlobalObjectConsoleClient::warnUnimplemented): * inspector/JSGlobalObjectConsoleClient.h: ConsoleClient now takes Ref&& instead of RefPtr&&. * inspector/JSGlobalObjectInspectorController.cpp: (Inspector::JSGlobalObjectInspectorController::appendAPIBacktrace): (Inspector::JSGlobalObjectInspectorController::reportAPIException): * inspector/JSGlobalObjectInspectorController.h: * inspector/JSJavaScriptCallFrame.cpp: (Inspector::JSJavaScriptCallFrame::JSJavaScriptCallFrame): (Inspector::toJS): * inspector/JSJavaScriptCallFrame.h: (Inspector::JSJavaScriptCallFrame::create): * inspector/JavaScriptCallFrame.cpp: (Inspector::JavaScriptCallFrame::JavaScriptCallFrame): (Inspector::JavaScriptCallFrame::caller): * inspector/JavaScriptCallFrame.h: (Inspector::JavaScriptCallFrame::create): * inspector/ScriptDebugServer.cpp: (Inspector::ScriptDebugServer::evaluateBreakpointAction): (Inspector::ScriptDebugServer::dispatchDidPause): (Inspector::ScriptDebugServer::exceptionOrCaughtValue): * inspector/agents/InspectorConsoleAgent.cpp: (Inspector::InspectorConsoleAgent::stopTiming): (Inspector::InspectorConsoleAgent::count): * inspector/agents/InspectorConsoleAgent.h: * inspector/agents/InspectorDebuggerAgent.cpp: (Inspector::InspectorDebuggerAgent::didScheduleAsyncCall): * runtime/ConsoleClient.cpp: (JSC::ConsoleClient::printConsoleMessageWithArguments): (JSC::ConsoleClient::internalMessageWithTypeAndLevel): (JSC::ConsoleClient::logWithLevel): (JSC::ConsoleClient::dir): (JSC::ConsoleClient::dirXML): (JSC::ConsoleClient::table): (JSC::ConsoleClient::trace): (JSC::ConsoleClient::assertion): (JSC::ConsoleClient::group): (JSC::ConsoleClient::groupCollapsed): (JSC::ConsoleClient::groupEnd): * runtime/ConsoleClient.h: * runtime/ConsoleObject.cpp: (JSC::consoleLogWithLevel): (JSC::consoleProtoFuncDir): (JSC::consoleProtoFuncDirXML): (JSC::consoleProtoFuncTable): (JSC::consoleProtoFuncTrace): (JSC::consoleProtoFuncAssert): (JSC::consoleProtoFuncCount): (JSC::consoleProtoFuncTimeStamp): (JSC::consoleProtoFuncGroup): (JSC::consoleProtoFuncGroupCollapsed): (JSC::consoleProtoFuncGroupEnd): 2017-02-15 Keith Miller Weak should not use jsCast in its accessors https://bugs.webkit.org/show_bug.cgi?id=168406 Reviewed by Filip Pizlo. This can cause assertion failures in WebCore where classes might remove themselves from a data structure in a weak reference, if that reference is still alive. * heap/WeakInlines.h: (JSC::>): (JSC::Weak::operator): (JSC::Weak::get): 2017-02-16 Yusuke Suzuki Web Inspector: allow import() inside the inspector https://bugs.webkit.org/show_bug.cgi?id=167457 Reviewed by Ryosuke Niwa. We relax import module hook to accept null SourceOrigin. Such a script can be evaluated from the inspector console. * jsc.cpp: (GlobalObject::moduleLoaderImportModule): * runtime/JSGlobalObjectFunctions.cpp: (JSC::globalFuncImportModule): 2017-02-16 Yusuke Suzuki [JSC] Update module namespace object according to the latest ECMA262 https://bugs.webkit.org/show_bug.cgi?id=168280 Reviewed by Saam Barati. Reflect updates to the module namespace object. 1. @@iterator property is dropped[1]. 2. @@toStringTag property becomes non-configurable[1]. 3. delete with Symbol should be delegated to the JSObject's one[2]. [1]: https://tc39.github.io/ecma262/#sec-module-namespace-objects [2]: https://github.com/tc39/ecma262/pull/767 * runtime/JSModuleNamespaceObject.cpp: (JSC::JSModuleNamespaceObject::finishCreation): (JSC::JSModuleNamespaceObject::deleteProperty): (JSC::moduleNamespaceObjectSymbolIterator): Deleted. 2017-02-16 Carlos Garcia Campos Unreviewed. Fix the build after r212424. Add missing file. * inspector/remote/RemoteInspector.cpp: Added. (Inspector::RemoteInspector::startDisabled): (Inspector::RemoteInspector::nextAvailableTargetIdentifier): (Inspector::RemoteInspector::registerTarget): (Inspector::RemoteInspector::unregisterTarget): (Inspector::RemoteInspector::updateTarget): (Inspector::RemoteInspector::updateClientCapabilities): (Inspector::RemoteInspector::setRemoteInspectorClient): (Inspector::RemoteInspector::setupFailed): (Inspector::RemoteInspector::setupCompleted): (Inspector::RemoteInspector::waitingForAutomaticInspection): (Inspector::RemoteInspector::clientCapabilitiesDidChange): (Inspector::RemoteInspector::stop): (Inspector::RemoteInspector::listingForTarget): (Inspector::RemoteInspector::updateHasActiveDebugSession): 2017-02-15 Yusuke Suzuki [JSC] Drop PassRefPtr in bytecompiler/ https://bugs.webkit.org/show_bug.cgi?id=168374 Reviewed by Sam Weinig. This patch drops PassRefPtr in bytecompiler directory. We carefully change this to Ref<>. And we use Ref