Ignore:
Timestamp:
Dec 13, 2019, 8:34:45 PM (5 years ago)
Author:
[email protected]
Message:

[JSC] Remove JSFixedArray, and use JSImmutableButterfly instead
https://bugs.webkit.org/show_bug.cgi?id=204402

Reviewed by Mark Lam.

JSTests:

  • stress/new-array-with-spread-cow-double.js: Added.

(shouldBe):
(shouldBeArray):
(test):

  • stress/new-array-with-spread-cow-int.js: Added.

(shouldBe):
(shouldBeArray):
(test):

  • stress/new-array-with-spread-cow.js: Added.

(shouldBe):
(shouldBeArray):
(test):

Source/JavaScriptCore:

This patch removes JSFixedArray, and use JSImmutableButterfly instead. JSFixedArray can be replaced by
JSImmutableButterfly with Contiguous shape. And further, we can create an array from JSImmutableButterfly
generated by Spread node in NewArrayBufferWithSpread.

Currently, we are always creating contiguous JSImmutableButterfly from Spread. If it takes contiguous CoW
array, we can reuse JSImmutableButterfly of the input. But if it is CoW and not contiguous shape (like,
CopyOnWriteArrayWithInt32), we create a JSImmutableButterfly and copy it to this new butterfly. We can
extend it to accept non-contiguous JSImmutableButterfly in the future.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • Sources.txt:
  • bytecompiler/BytecodeGenerator.cpp:
  • dfg/DFGAbstractInterpreterInlines.h:

(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):

  • dfg/DFGByteCodeParser.cpp:
  • dfg/DFGClobberize.h:

(JSC::DFG::clobberize):

  • dfg/DFGConstantFoldingPhase.cpp:

(JSC::DFG::ConstantFoldingPhase::foldConstants):

  • dfg/DFGOperations.cpp:
  • dfg/DFGOperations.h:
  • dfg/DFGSpeculativeJIT.cpp:

(JSC::DFG::SpeculativeJIT::compileSpread):
(JSC::DFG::SpeculativeJIT::compileNewArrayWithSpread):
(JSC::DFG::SpeculativeJIT::compileObjectKeys):

  • ftl/FTLAbstractHeapRepository.h:
  • ftl/FTLLowerDFGToB3.cpp:

(JSC::FTL::DFG::LowerDFGToB3::compileNewArrayWithSpread):
(JSC::FTL::DFG::LowerDFGToB3::compileSpread):
(JSC::FTL::DFG::LowerDFGToB3::toButterfly):

  • ftl/FTLOperations.cpp:

(JSC::FTL::operationMaterializeObjectInOSR):

  • interpreter/Interpreter.cpp:

(JSC::sizeOfVarargs):
(JSC::loadVarargs):

  • runtime/CommonSlowPaths.cpp:

(JSC::SLOW_PATH_DECL):

  • runtime/JSCast.h:
  • runtime/JSFixedArray.cpp: Removed.
  • runtime/JSFixedArray.h: Removed.
  • runtime/JSImmutableButterfly.h:

(JSC::JSImmutableButterfly::createFromArray):
(JSC::JSImmutableButterfly::offsetOfPublicLength):
(JSC::JSImmutableButterfly::offsetOfVectorLength):

  • runtime/JSType.cpp:

(WTF::printInternal):

  • runtime/JSType.h:
  • runtime/VM.cpp:

(JSC::VM::VM):

  • runtime/VM.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/dfg/DFGOperations.cpp

    r253458 r253520  
    5555#include "JSBigInt.h"
    5656#include "JSCInlines.h"
    57 #include "JSFixedArray.h"
    5857#include "JSGenericTypedArrayViewConstructorInlines.h"
    5958#include "JSGlobalObjectFunctions.h"
     
    30723071    for (unsigned i = 0; i < numItems; i++) {
    30733072        JSValue value = JSValue::decode(values[i]);
    3074         if (JSFixedArray* array = jsDynamicCast<JSFixedArray*>(vm, value))
    3075             checkedLength += array->size();
     3073        if (JSImmutableButterfly* array = jsDynamicCast<JSImmutableButterfly*>(vm, value))
     3074            checkedLength += array->publicLength();
    30763075        else
    30773076            ++checkedLength;
     
    31013100    for (unsigned i = 0; i < numItems; i++) {
    31023101        JSValue value = JSValue::decode(values[i]);
    3103         if (JSFixedArray* array = jsDynamicCast<JSFixedArray*>(vm, value)) {
     3102        if (JSImmutableButterfly* array = jsDynamicCast<JSImmutableButterfly*>(vm, value)) {
    31043103            // We are spreading.
    3105             for (unsigned i = 0; i < array->size(); i++) {
     3104            for (unsigned i = 0; i < array->publicLength(); i++) {
    31063105                result->putDirectIndex(globalObject, index, array->get(i));
    31073106                RETURN_IF_EXCEPTION(scope, nullptr);
     
    31193118}
    31203119
    3121 JSCell* operationCreateFixedArray(JSGlobalObject* globalObject, unsigned length)
    3122 {
    3123     VM& vm = globalObject->vm();
    3124     CallFrame* callFrame = DECLARE_CALL_FRAME(vm);
    3125     JITOperationPrologueCallFrameTracer tracer(vm, callFrame);
    3126     auto scope = DECLARE_THROW_SCOPE(vm);
    3127 
    3128     if (JSFixedArray* result = JSFixedArray::tryCreate(vm, vm.fixedArrayStructure.get(), length))
     3120JSCell* operationCreateImmutableButterfly(JSGlobalObject* globalObject, unsigned length)
     3121{
     3122    VM& vm = globalObject->vm();
     3123    CallFrame* callFrame = DECLARE_CALL_FRAME(vm);
     3124    JITOperationPrologueCallFrameTracer tracer(vm, callFrame);
     3125    auto scope = DECLARE_THROW_SCOPE(vm);
     3126
     3127    if (JSImmutableButterfly* result = JSImmutableButterfly::tryCreate(vm, vm.immutableButterflyStructures[arrayIndexFromIndexingType(CopyOnWriteArrayWithContiguous) - NumberOfIndexingShapes].get(), length))
    31293128        return result;
    31303129
     
    31443143        JSArray* array = jsCast<JSArray*>(iterable);
    31453144        if (array->isIteratorProtocolFastAndNonObservable())
    3146             RELEASE_AND_RETURN(throwScope, JSFixedArray::createFromArray(globalObject, vm, array));
     3145            RELEASE_AND_RETURN(throwScope, JSImmutableButterfly::createFromArray(globalObject, vm, array));
    31473146    }
    31483147
     
    31653164    }
    31663165
    3167     RELEASE_AND_RETURN(throwScope, JSFixedArray::createFromArray(globalObject, vm, array));
     3166    RELEASE_AND_RETURN(throwScope, JSImmutableButterfly::createFromArray(globalObject, vm, array));
    31683167}
    31693168
     
    31783177    ASSERT(array->isIteratorProtocolFastAndNonObservable());
    31793178
    3180     return JSFixedArray::createFromArray(globalObject, vm, array);
     3179    return JSImmutableButterfly::createFromArray(globalObject, vm, array);
    31813180}
    31823181
Note: See TracChangeset for help on using the changeset viewer.