Ignore:
Timestamp:
Mar 13, 2011, 2:16:29 PM (14 years ago)
Author:
[email protected]
Message:

Bug 56270 - The JIT 'friend's many classes in JSC; start unwinding this.

Reviewed by Sam Weinig.

The JIT need to 'friend' other classes in order to be able to calculate offsets
of various properties, or the absolute addresses of members within specific objects,
in order to JIT generate code that will access members within the class when run.

Instead of using friends in these cases, switch to providing specific accessor
methods to provide this information. In the case of offsets, these can be static
functions, and in the case of pointers to members within a specific object these can
be const methods returning pointers to const values, to prevent clients from
modifying values otherwise encapsulated within classes.

  • bytecode/SamplingTool.h:
  • interpreter/Register.h:
  • interpreter/RegisterFile.h:
  • runtime/JSArray.h:
  • runtime/JSCell.h:
  • runtime/JSTypeInfo.h:
  • runtime/JSVariableObject.h:
  • runtime/Structure.h:
  • wtf/RefCounted.h:
    • Change these classes to no longer friend the JIT, add accessors for member offsets.
  • jit/JIT.cpp:
  • jit/JITCall32_64.cpp:
  • jit/JITInlineMethods.h:
  • jit/JITOpcodes.cpp:
  • jit/JITOpcodes32_64.cpp:
  • jit/JITPropertyAccess.cpp:
  • jit/JITPropertyAccess32_64.cpp:
    • Change the JIT to use class accessors, rather than taking object ofsets directly.
  • assembler/AbstractMacroAssembler.h:
  • assembler/MacroAssemblerX86_64.h:
  • assembler/X86Assembler.h:
    • Since the accessors for objects members return const pointers to retain encapsulation, methods generating code with absolute addresses must be able to handle const pointers (the JIT doesn't write to these values, do dies treat the pointer to value as const from within the C++ code of the JIT, if not at runtime!).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/jit/JITPropertyAccess.cpp

    r78732 r80969  
    102102    addSlowCase(branchPtr(NotEqual, Address(regT0), ImmPtr(m_globalData->jsArrayVPtr)));
    103103
    104     loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_storage)), regT2);
    105     addSlowCase(branch32(AboveOrEqual, regT1, Address(regT0, OBJECT_OFFSETOF(JSArray, m_vectorLength))));
     104    loadPtr(Address(regT0, JSArray::storageOffset()), regT2);
     105    addSlowCase(branch32(AboveOrEqual, regT1, Address(regT0, JSArray::vectorLengthOffset())));
    106106
    107107    loadPtr(BaseIndex(regT2, regT1, ScalePtr, OBJECT_OFFSETOF(ArrayStorage, m_vector[0])), regT0);
     
    160160
    161161    // Test base's structure
    162     loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2);
     162    loadPtr(Address(regT0, JSCell::structureOffset()), regT2);
    163163    addSlowCase(branchPtr(NotEqual, regT2, Address(regT1, OBJECT_OFFSETOF(JSPropertyNameIterator, m_cachedStructure))));
    164164    load32(addressFor(i), regT3);
     
    199199    emitJumpSlowCaseIfNotJSCell(regT0, base);
    200200    addSlowCase(branchPtr(NotEqual, Address(regT0), ImmPtr(m_globalData->jsArrayVPtr)));
    201     addSlowCase(branch32(AboveOrEqual, regT1, Address(regT0, OBJECT_OFFSETOF(JSArray, m_vectorLength))));
    202 
    203     loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_storage)), regT2);
     201    addSlowCase(branch32(AboveOrEqual, regT1, Address(regT0, JSArray::vectorLengthOffset())));
     202
     203    loadPtr(Address(regT0, JSArray::storageOffset()), regT2);
    204204    Jump empty = branchTestPtr(Zero, BaseIndex(regT2, regT1, ScalePtr, OBJECT_OFFSETOF(ArrayStorage, m_vector[0])));
    205205
     
    337337    BEGIN_UNINTERRUPTED_SEQUENCE(sequenceMethodCheck);
    338338
    339     Jump structureCheck = branchPtrWithPatch(NotEqual, Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), info.structureToCompare, ImmPtr(reinterpret_cast<void*>(patchGetByIdDefaultStructure)));
     339    Jump structureCheck = branchPtrWithPatch(NotEqual, Address(regT0, JSCell::structureOffset()), info.structureToCompare, ImmPtr(reinterpret_cast<void*>(patchGetByIdDefaultStructure)));
    340340    DataLabelPtr protoStructureToCompare, protoObj = moveWithPatch(ImmPtr(0), regT1);
    341     Jump protoStructureCheck = branchPtrWithPatch(NotEqual, Address(regT1, OBJECT_OFFSETOF(JSCell, m_structure)), protoStructureToCompare, ImmPtr(reinterpret_cast<void*>(patchGetByIdDefaultStructure)));
     341    Jump protoStructureCheck = branchPtrWithPatch(NotEqual, Address(regT1, JSCell::structureOffset()), protoStructureToCompare, ImmPtr(reinterpret_cast<void*>(patchGetByIdDefaultStructure)));
    342342
    343343    // This will be relinked to load the function without doing a load.
     
    415415
    416416    DataLabelPtr structureToCompare;
    417     Jump structureCheck = branchPtrWithPatch(NotEqual, Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), structureToCompare, ImmPtr(reinterpret_cast<void*>(patchGetByIdDefaultStructure)));
     417    Jump structureCheck = branchPtrWithPatch(NotEqual, Address(regT0, JSCell::structureOffset()), structureToCompare, ImmPtr(reinterpret_cast<void*>(patchGetByIdDefaultStructure)));
    418418    addSlowCase(structureCheck);
    419419    ASSERT_JIT_OFFSET(differenceBetween(hotPathBegin, structureToCompare), patchOffsetGetByIdStructure);
     
    493493    // It is important that the following instruction plants a 32bit immediate, in order that it can be patched over.
    494494    DataLabelPtr structureToCompare;
    495     addSlowCase(branchPtrWithPatch(NotEqual, Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), structureToCompare, ImmPtr(reinterpret_cast<void*>(patchGetByIdDefaultStructure))));
     495    addSlowCase(branchPtrWithPatch(NotEqual, Address(regT0, JSCell::structureOffset()), structureToCompare, ImmPtr(reinterpret_cast<void*>(patchGetByIdDefaultStructure))));
    496496    ASSERT_JIT_OFFSET(differenceBetween(hotPathBegin, structureToCompare), patchOffsetPutByIdStructure);
    497497
     
    566566#if CPU(X86_64)
    567567    move(ImmPtr(prototype.asCell()->structure()), regT3);
    568     failureCases.append(branchPtr(NotEqual, AbsoluteAddress(&prototype.asCell()->m_structure), regT3));
     568    failureCases.append(branchPtr(NotEqual, AbsoluteAddress(prototype.asCell()->addressOfStructure()), regT3));
    569569#else
    570     failureCases.append(branchPtr(NotEqual, AbsoluteAddress(&prototype.asCell()->m_structure), ImmPtr(prototype.asCell()->structure())));
     570    failureCases.append(branchPtr(NotEqual, AbsoluteAddress(prototype.asCell()->addressOfStructure()), ImmPtr(prototype.asCell()->structure())));
    571571#endif
    572572}
     
    577577    // Check eax is an object of the right Structure.
    578578    failureCases.append(emitJumpIfNotJSCell(regT0));
    579     failureCases.append(branchPtr(NotEqual, Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), ImmPtr(oldStructure)));
     579    failureCases.append(branchPtr(NotEqual, Address(regT0, JSCell::structureOffset()), ImmPtr(oldStructure)));
    580580    testPrototype(oldStructure->storedPrototype(), failureCases);
    581581
     
    611611    sub32(Imm32(1), AbsoluteAddress(oldStructure->addressOfCount()));
    612612    add32(Imm32(1), AbsoluteAddress(newStructure->addressOfCount()));
    613     storePtr(ImmPtr(newStructure), Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)));
     613    storePtr(ImmPtr(newStructure), Address(regT0, JSCell::structureOffset()));
    614614
    615615    // write the value
     
    696696
    697697    // Checks out okay! - get the length from the storage
    698     loadPtr(Address(regT0, OBJECT_OFFSETOF(JSArray, m_storage)), regT3);
     698    loadPtr(Address(regT0, JSArray::storageOffset()), regT3);
    699699    load32(Address(regT3, OBJECT_OFFSETOF(ArrayStorage, m_length)), regT2);
    700700    Jump failureCases2 = branch32(Above, regT2, Imm32(JSImmediate::maxImmediateInt));
     
    736736
    737737    // Check the prototype object's Structure had not changed.
    738     Structure** prototypeStructureAddress = &(protoObject->m_structure);
     738    Structure* const * prototypeStructureAddress = protoObject->addressOfStructure();
    739739#if CPU(X86_64)
    740740    move(ImmPtr(prototypeStructure), regT3);
     
    859859
    860860    // Check the prototype object's Structure had not changed.
    861     Structure** prototypeStructureAddress = &(protoObject->m_structure);
     861    Structure* const * prototypeStructureAddress = protoObject->addressOfStructure();
    862862#if CPU(X86_64)
    863863    move(ImmPtr(prototypeStructure), regT3);
Note: See TracChangeset for help on using the changeset viewer.