Changeset 139491 in webkit


Ignore:
Timestamp:
Jan 11, 2013, 1:33:47 PM (12 years ago)
Author:
ggaren@apple.com
Message:

Removed getDirectLocation and offsetForLocation and all their uses
https://bugs.webkit.org/show_bug.cgi?id=106692

Reviewed by Filip Pizlo.

getDirectLocation() and its associated offsetForLocation() relied on
detailed knowledge of the rules of PropertyOffset, JSObject, and
Structure, which is a hard thing to reverse-engineer reliably. Luckily,
it wasn't needed, and all clients either wanted a true value or a
PropertyOffset. So, I refactored accordingly.

  • dfg/DFGOperations.cpp: Renamed putDirectOffset to putDirect, to clarify

that we are not putting an offset.

  • runtime/JSActivation.cpp:

(JSC::JSActivation::getOwnPropertySlot): Get a value instead of a value
pointer, since we never wanted a pointer to begin with.

  • runtime/JSFunction.cpp:

(JSC::JSFunction::getOwnPropertySlot): Use a PropertyOffset instead of a pointer,
so we don't have to reverse-engineer the offset from the pointer.

  • runtime/JSObject.cpp:

(JSC::JSObject::put):
(JSC::JSObject::resetInheritorID):
(JSC::JSObject::inheritorID):
(JSC::JSObject::removeDirect):
(JSC::JSObject::fillGetterPropertySlot):
(JSC::JSObject::getOwnPropertyDescriptor): Renamed getDirectOffset and
putDirectOffset, as explaind above. We want to use the name "getDirectOffset"
for when the thing you're getting is the offset.

  • runtime/JSObject.h:

(JSC::JSObject::getDirect):
(JSC::JSObject::getDirectOffset): Changed getDirectLocation to getDirectOffset,
since clients really wants PropertyOffsets and not locations.

(JSObject::offsetForLocation): Removed this function because it was hard
to get right.

(JSC::JSObject::putDirect):
(JSC::JSObject::putDirectUndefined):
(JSC::JSObject::inlineGetOwnPropertySlot):
(JSC::JSObject::putDirectInternal):
(JSC::JSObject::putDirectWithoutTransition):

  • runtime/JSScope.cpp:

(JSC::executeResolveOperations):
(JSC::JSScope::resolvePut):

  • runtime/JSValue.cpp:

(JSC::JSValue::putToPrimitive): Updated for renames.

  • runtime/Lookup.cpp:

(JSC::setUpStaticFunctionSlot): Use a PropertyOffset instead of a pointer,
so we don't have to reverse-engineer the offset from the pointer.

  • runtime/Structure.cpp:

(JSC::Structure::flattenDictionaryStructure): Updated for renames.

Location:
trunk/Source/JavaScriptCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r139488 r139491  
     12013-01-11  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Removed getDirectLocation and offsetForLocation and all their uses
     4        https://bugs.webkit.org/show_bug.cgi?id=106692
     5
     6        Reviewed by Filip Pizlo.
     7
     8        getDirectLocation() and its associated offsetForLocation() relied on
     9        detailed knowledge of the rules of PropertyOffset, JSObject, and
     10        Structure, which is a hard thing to reverse-engineer reliably. Luckily,
     11        it wasn't needed, and all clients either wanted a true value or a
     12        PropertyOffset. So, I refactored accordingly.
     13
     14        * dfg/DFGOperations.cpp: Renamed putDirectOffset to putDirect, to clarify
     15        that we are not putting an offset.
     16
     17        * runtime/JSActivation.cpp:
     18        (JSC::JSActivation::getOwnPropertySlot): Get a value instead of a value
     19        pointer, since we never wanted a pointer to begin with.
     20
     21        * runtime/JSFunction.cpp:
     22        (JSC::JSFunction::getOwnPropertySlot): Use a PropertyOffset instead of a pointer,
     23        so we don't have to reverse-engineer the offset from the pointer.
     24
     25        * runtime/JSObject.cpp:
     26        (JSC::JSObject::put):
     27        (JSC::JSObject::resetInheritorID):
     28        (JSC::JSObject::inheritorID):
     29        (JSC::JSObject::removeDirect):
     30        (JSC::JSObject::fillGetterPropertySlot):
     31        (JSC::JSObject::getOwnPropertyDescriptor): Renamed getDirectOffset and
     32        putDirectOffset, as explaind above. We want to use the name "getDirectOffset"
     33        for when the thing you're getting is the offset.
     34
     35        * runtime/JSObject.h:
     36        (JSC::JSObject::getDirect):
     37        (JSC::JSObject::getDirectOffset): Changed getDirectLocation to getDirectOffset,
     38        since clients really wants PropertyOffsets and not locations.
     39
     40        (JSObject::offsetForLocation): Removed this function because it was hard
     41        to get right.
     42
     43        (JSC::JSObject::putDirect):
     44        (JSC::JSObject::putDirectUndefined):
     45        (JSC::JSObject::inlineGetOwnPropertySlot):
     46        (JSC::JSObject::putDirectInternal):
     47        (JSC::JSObject::putDirectWithoutTransition):
     48        * runtime/JSScope.cpp:
     49        (JSC::executeResolveOperations):
     50        (JSC::JSScope::resolvePut):
     51        * runtime/JSValue.cpp:
     52        (JSC::JSValue::putToPrimitive): Updated for renames.
     53
     54        * runtime/Lookup.cpp:
     55        (JSC::setUpStaticFunctionSlot): Use a PropertyOffset instead of a pointer,
     56        so we don't have to reverse-engineer the offset from the pointer.
     57
     58        * runtime/Structure.cpp:
     59        (JSC::Structure::flattenDictionaryStructure): Updated for renames.
     60
    1612013-01-11  Geoffrey Garen  <ggaren@apple.com>
    262
  • trunk/Source/JavaScriptCore/dfg/DFGOperations.cpp

    r139145 r139491  
    14421442    ASSERT(!globalData.heap.storageAllocator().fastPathShouldSucceed(structure->outOfLineCapacity() * sizeof(JSValue)));
    14431443    base->setStructureAndReallocateStorageIfNecessary(globalData, structure);
    1444     base->putDirectOffset(globalData, offset, JSValue::decode(value));
     1444    base->putDirect(globalData, offset, JSValue::decode(value));
    14451445}
    14461446
  • trunk/Source/JavaScriptCore/runtime/JSActivation.cpp

    r131088 r139491  
    157157        return true;
    158158
    159     if (WriteBarrierBase<Unknown>* location = thisObject->getDirectLocation(exec->globalData(), propertyName)) {
    160         slot.setValue(location->get());
     159    if (JSValue value = thisObject->getDirect(exec->globalData(), propertyName)) {
     160        slot.setValue(value);
    161161        return true;
    162162    }
  • trunk/Source/JavaScriptCore/runtime/JSFunction.cpp

    r134555 r139491  
    219219
    220220    if (propertyName == exec->propertyNames().prototype) {
    221         WriteBarrierBase<Unknown>* location = thisObject->getDirectLocation(exec->globalData(), propertyName);
    222 
    223         if (!location) {
     221        PropertyOffset offset = thisObject->getDirectOffset(exec->globalData(), propertyName);
     222        if (!isValidOffset(offset)) {
    224223            JSObject* prototype = constructEmptyObject(exec, thisObject->globalObject()->emptyObjectStructure());
    225224            prototype->putDirect(exec->globalData(), exec->propertyNames().constructor, thisObject, DontEnum);
    226225            thisObject->putDirect(exec->globalData(), exec->propertyNames().prototype, prototype, DontDelete | DontEnum);
    227             location = thisObject->getDirectLocation(exec->globalData(), exec->propertyNames().prototype);
    228         }
    229 
    230         slot.setValue(thisObject, location->get(), thisObject->offsetForLocation(location));
     226            offset = thisObject->getDirectOffset(exec->globalData(), exec->propertyNames().prototype);
     227            ASSERT(isValidOffset(offset));
     228        }
     229
     230        slot.setValue(thisObject, thisObject->getDirect(offset), offset);
    231231    }
    232232
  • trunk/Source/JavaScriptCore/runtime/JSObject.cpp

    r138201 r139491  
    380380            }
    381381
    382             JSValue gs = obj->getDirectOffset(offset);
     382            JSValue gs = obj->getDirect(offset);
    383383            if (gs.isGetterSetter()) {
    384384                ASSERT(attributes & Accessor);
     
    11941194        return;
    11951195   
    1196     putDirectOffset(globalData, offset, jsUndefined());
     1196    putDirect(globalData, offset, jsUndefined());
    11971197}
    11981198
    11991199Structure* JSObject::inheritorID(JSGlobalData& globalData)
    12001200{
    1201     if (WriteBarrierBase<Unknown>* location = getDirectLocation(globalData, globalData.m_inheritorIDKey)) {
    1202         JSValue value = location->get();
     1201    if (JSValue value = getDirect(globalData, globalData.m_inheritorIDKey)) {
    12031202        if (value.isCell()) {
    12041203            Structure* inheritorID = jsCast<Structure*>(value);
     
    16431642        if (offset == invalidOffset)
    16441643            return false;
    1645         putUndefinedAtDirectOffset(offset);
     1644        putDirectUndefined(offset);
    16461645        return true;
    16471646    }
     
    16501649    if (offset == invalidOffset)
    16511650        return false;
    1652     putUndefinedAtDirectOffset(offset);
     1651    putDirectUndefined(offset);
    16531652    return true;
    16541653}
     
    16561655NEVER_INLINE void JSObject::fillGetterPropertySlot(PropertySlot& slot, PropertyOffset offset)
    16571656{
    1658     if (JSObject* getterFunction = asGetterSetter(getDirectOffset(offset))->getter()) {
     1657    if (JSObject* getterFunction = asGetterSetter(getDirect(offset))->getter()) {
    16591658        if (!structure()->isDictionary())
    16601659            slot.setCacheableGetterSlot(this, getterFunction, offset);
     
    24292428    PropertyOffset offset = object->structure()->get(exec->globalData(), propertyName, attributes, cell);
    24302429    if (isValidOffset(offset)) {
    2431         descriptor.setDescriptor(object->getDirectOffset(offset), attributes);
     2430        descriptor.setDescriptor(object->getDirect(offset), attributes);
    24322431        return true;
    24332432    }
  • trunk/Source/JavaScriptCore/runtime/JSObject.h

    r139488 r139491  
    506506        PropertyOffset offset = structure()->get(globalData, propertyName);
    507507        checkOffset(offset, structure()->inlineCapacity());
    508         return offset != invalidOffset ? getDirectOffset(offset) : JSValue();
    509     }
    510 
    511     WriteBarrierBase<Unknown>* getDirectLocation(JSGlobalData& globalData, PropertyName propertyName)
     508        return offset != invalidOffset ? getDirect(offset) : JSValue();
     509    }
     510
     511    PropertyOffset getDirectOffset(JSGlobalData& globalData, PropertyName propertyName)
    512512    {
    513513        PropertyOffset offset = structure()->get(globalData, propertyName);
    514514        checkOffset(offset, structure()->inlineCapacity());
    515         return isValidOffset(offset) ? locationForOffset(offset) : 0;
     515        return offset;
    516516    }
    517517
     
    554554            return &inlineStorage()[offsetInInlineStorage(offset)];
    555555        return &outOfLineStorage()[offsetInOutOfLineStorage(offset)];
    556     }
    557 
    558     PropertyOffset offsetForLocation(WriteBarrierBase<Unknown>* location) const
    559     {
    560         PropertyOffset result;
    561         size_t offsetInInlineStorage = location - inlineStorageUnsafe();
    562         if (offsetInInlineStorage < static_cast<size_t>(firstOutOfLineOffset))
    563             result = offsetInInlineStorage;
    564         else
    565             result = outOfLineStorage() - location + (firstOutOfLineOffset - 1);
    566         validateOffset(result, structure()->inlineCapacity());
    567         return result;
    568556    }
    569557
     
    582570
    583571    // Fast access to known property offsets.
    584     JSValue getDirectOffset(PropertyOffset offset) const { return locationForOffset(offset)->get(); }
    585     void putDirectOffset(JSGlobalData& globalData, PropertyOffset offset, JSValue value) { locationForOffset(offset)->set(globalData, this, value); }
    586     void putUndefinedAtDirectOffset(PropertyOffset offset) { locationForOffset(offset)->setUndefined(); }
     572    JSValue getDirect(PropertyOffset offset) const { return locationForOffset(offset)->get(); }
     573    void putDirect(JSGlobalData& globalData, PropertyOffset offset, JSValue value) { locationForOffset(offset)->set(globalData, this, value); }
     574    void putDirectUndefined(PropertyOffset offset) { locationForOffset(offset)->setUndefined(); }
    587575
    588576    JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, PropertyDescriptor&, bool shouldThrow);
     
    11901178    PropertyOffset offset = structure()->get(exec->globalData(), propertyName);
    11911179    if (LIKELY(isValidOffset(offset))) {
    1192         JSValue value = getDirectOffset(offset);
     1180        JSValue value = getDirect(offset);
    11931181        if (structure()->hasGetterSetterProperties() && value.isGetterSetter())
    11941182            fillGetterPropertySlot(slot, offset);
     
    12981286                return false;
    12991287
    1300             putDirectOffset(globalData, offset, value);
     1288            putDirect(globalData, offset, value);
    13011289            // At this point, the objects structure only has a specific value set if previously there
    13021290            // had been one set, and if the new value being specified is the same (otherwise we would
     
    13211309        validateOffset(offset);
    13221310        ASSERT(structure()->isValidOffset(offset));
    1323         putDirectOffset(globalData, offset, value);
     1311        putDirect(globalData, offset, value);
    13241312        // See comment on setNewProperty call below.
    13251313        if (!specificFunction)
     
    13401328        ASSERT(structure->isValidOffset(offset));
    13411329        setButterfly(globalData, newButterfly, structure);
    1342         putDirectOffset(globalData, offset, value);
     1330        putDirect(globalData, offset, value);
    13431331        // This is a new property; transitions with specific values are not currently cachable,
    13441332        // so leave the slot in an uncachable state.
     
    13671355            // case (1) Do the put, then return leaving the slot uncachable.
    13681356            if (specificFunction == currentSpecificFunction) {
    1369                 putDirectOffset(globalData, offset, value);
     1357                putDirect(globalData, offset, value);
    13701358                return true;
    13711359            }
     
    13761364        // case (3) set the slot, do the put, return.
    13771365        slot.setExistingProperty(this, offset);
    1378         putDirectOffset(globalData, offset, value);
     1366        putDirect(globalData, offset, value);
    13791367        return true;
    13801368    }
     
    13891377    setStructureAndReallocateStorageIfNecessary(globalData, structure);
    13901378
    1391     putDirectOffset(globalData, offset, value);
     1379    putDirect(globalData, offset, value);
    13921380    // This is a new property; transitions with specific values are not currently cachable,
    13931381    // so leave the slot in an uncachable state.
     
    14491437    PropertyOffset offset = structure()->addPropertyWithoutTransition(globalData, propertyName, attributes, getCallableObject(value));
    14501438    setButterfly(globalData, newButterfly, structure());
    1451     putDirectOffset(globalData, offset, value);
     1439    putDirect(globalData, offset, value);
    14521440}
    14531441
  • trunk/Source/JavaScriptCore/runtime/JSScope.cpp

    r132546 r139491  
    167167            JSGlobalObject* globalObject = scope->globalObject();
    168168            if (globalObject->structure() == pc->m_structure.get()) {
    169                 result.setValue(globalObject->getDirectOffset(pc->m_offset));
     169                result.setValue(globalObject->getDirect(pc->m_offset));
    170170                return true;
    171171            }
     
    582582        if (operation->m_structure.get() != object->structure())
    583583            break;
    584         object->putDirectOffset(callFrame->globalData(), operation->m_offset, value);
     584        object->putDirect(callFrame->globalData(), operation->m_offset, value);
    585585        return;
    586586    }
  • trunk/Source/JavaScriptCore/runtime/JSValue.cpp

    r139145 r139491  
    145145            }
    146146
    147             JSValue gs = obj->getDirectOffset(offset);
     147            JSValue gs = obj->getDirect(offset);
    148148            if (gs.isGetterSetter()) {
    149149                JSObject* setterFunc = asGetterSetter(gs)->setter();       
  • trunk/Source/JavaScriptCore/runtime/Lookup.cpp

    r117859 r139491  
    6969    ASSERT(thisObj->globalObject());
    7070    ASSERT(entry->attributes() & Function);
    71     WriteBarrierBase<Unknown>* location = thisObj->getDirectLocation(exec->globalData(), propertyName);
     71    PropertyOffset offset = thisObj->getDirectOffset(exec->globalData(), propertyName);
    7272
    73     if (!location) {
     73    if (!isValidOffset(offset)) {
    7474        // If a property is ever deleted from an object with a static table, then we reify
    7575        // all static functions at that time - after this we shouldn't be re-adding anything.
     
    8282        JSFunction* function = JSFunction::create(exec, thisObj->globalObject(), entry->functionLength(), name, entry->function(), entry->intrinsic());
    8383        thisObj->putDirect(exec->globalData(), propertyName, function, entry->attributes());
    84         location = thisObj->getDirectLocation(exec->globalData(), propertyName);
     84        offset = thisObj->getDirectOffset(exec->globalData(), propertyName);
     85        ASSERT(isValidOffset(offset));
    8586    }
    8687
    87     slot.setValue(thisObj, location->get(), thisObj->offsetForLocation(location));
     88    slot.setValue(thisObj, thisObj->getDirect(offset), offset);
    8889    return true;
    8990}
  • trunk/Source/JavaScriptCore/runtime/Structure.cpp

    r139482 r139491  
    635635        PropertyTable::iterator end = m_propertyTable->end();
    636636        for (PropertyTable::iterator iter = m_propertyTable->begin(); iter != end; ++iter, ++i) {
    637             values[i] = object->getDirectOffset(iter->offset);
     637            values[i] = object->getDirect(iter->offset);
    638638            iter->offset = offsetForPropertyNumber(i, m_inlineCapacity);
    639639        }
     
    641641        // Copies in our values to their compacted locations.
    642642        for (unsigned i = 0; i < propertyCount; i++)
    643             object->putDirectOffset(globalData, offsetForPropertyNumber(i, m_inlineCapacity), values[i]);
     643            object->putDirect(globalData, offsetForPropertyNumber(i, m_inlineCapacity), values[i]);
    644644
    645645        m_propertyTable->clearDeletedOffsets();
Note: See TracChangeset for help on using the changeset viewer.