⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 211122 in webkit


Ignore:
Timestamp:
Jan 24, 2017, 4:53:48 PM (10 years ago)
Author:
fpizlo@apple.com
Message:

Atomics.store should return the int-converted value, not the value that it stored
https://bugs.webkit.org/show_bug.cgi?id=167395

Reviewed by Saam Barati.
JSTests:

  • stress/atomics-store-return.js: Added.

Source/JavaScriptCore:


Previously the code was based around passing a lambda that operated over the native type of the
operation (so for example int8_t if we were doing things to Int8Arrays). But to support this
behavior of store, we need it to be able to control how it converts its result to JSValue and it
needs to see its argument as an int32_t. It turns out that it's easy for all of the functions in
AtomicsObject.cpp to also adopt this protocol since the conversion to JSValue is just jsNumber()
from the native type in those cases, and the conversion from int32_t is done for free in
std::atomic.

  • runtime/AtomicsObject.cpp:

(JSC::atomicsFuncAdd):
(JSC::atomicsFuncAnd):
(JSC::atomicsFuncCompareExchange):
(JSC::atomicsFuncExchange):
(JSC::atomicsFuncLoad):
(JSC::atomicsFuncOr):
(JSC::atomicsFuncStore):
(JSC::atomicsFuncSub):
(JSC::atomicsFuncXor):

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r211113 r211122  
     12017-01-24  Filip Pizlo  <fpizlo@apple.com>
     2
     3        Atomics.store should return the int-converted value, not the value that it stored
     4        https://bugs.webkit.org/show_bug.cgi?id=167395
     5
     6        Reviewed by Saam Barati.
     7
     8        * stress/atomics-store-return.js: Added.
     9
    1102017-01-24  Filip Pizlo  <fpizlo@apple.com>
    211
  • trunk/Source/JavaScriptCore/ChangeLog

    r211113 r211122  
     12017-01-24  Filip Pizlo  <fpizlo@apple.com>
     2
     3        Atomics.store should return the int-converted value, not the value that it stored
     4        https://bugs.webkit.org/show_bug.cgi?id=167395
     5
     6        Reviewed by Saam Barati.
     7       
     8        Previously the code was based around passing a lambda that operated over the native type of the
     9        operation (so for example int8_t if we were doing things to Int8Arrays). But to support this
     10        behavior of store, we need it to be able to control how it converts its result to JSValue and it
     11        needs to see its argument as an int32_t. It turns out that it's easy for all of the functions in
     12        AtomicsObject.cpp to also adopt this protocol since the conversion to JSValue is just jsNumber()
     13        from the native type in those cases, and the conversion from int32_t is done for free in
     14        std::atomic.
     15
     16        * runtime/AtomicsObject.cpp:
     17        (JSC::atomicsFuncAdd):
     18        (JSC::atomicsFuncAnd):
     19        (JSC::atomicsFuncCompareExchange):
     20        (JSC::atomicsFuncExchange):
     21        (JSC::atomicsFuncLoad):
     22        (JSC::atomicsFuncOr):
     23        (JSC::atomicsFuncStore):
     24        (JSC::atomicsFuncSub):
     25        (JSC::atomicsFuncXor):
     26
    1272017-01-24  Filip Pizlo  <fpizlo@apple.com>
    228
  • trunk/Source/JavaScriptCore/runtime/AtomicsObject.cpp

    r211113 r211122  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    9393    JSGenericTypedArrayView<Adaptor>* typedArray = jsCast<JSGenericTypedArrayView<Adaptor>*>(typedArrayView);
    9494   
    95     typename Adaptor::Type extraArgs[numExtraArgs + 1]; // Add 1 to avoid 0 size array error in VS.
     95    int32_t extraArgs[numExtraArgs + 1]; // Add 1 to avoid 0 size array error in VS.
    9696    for (unsigned i = 0; i < numExtraArgs; ++i) {
    9797        int32_t value = exec->argument(2 + i).toInt32(exec);
    9898        RETURN_IF_EXCEPTION(scope, JSValue::encode(jsUndefined()));
    99         extraArgs[i] = Adaptor::toNativeFromInt32(value);
    100     }
    101 
    102     typename Adaptor::Type result = func(typedArray->typedVector() + accessIndex, extraArgs);
    103     return JSValue::encode(Adaptor::toJSValue(result));
     99        extraArgs[i] = value;
     100    }
     101
     102    return JSValue::encode(func(typedArray->typedVector() + accessIndex, extraArgs));
    104103}
    105104
     
    193192{
    194193    return atomicOperationWithArgs<1>(
    195         exec, [&] (auto* ptr, const auto* args) {
    196             return WTF::atomicExchangeAdd(ptr, args[0]);
     194        exec, [&] (auto* ptr, const int32_t* args) {
     195            return jsNumber(WTF::atomicExchangeAdd(ptr, args[0]));
    197196        });
    198197}
     
    201200{
    202201    return atomicOperationWithArgs<1>(
    203         exec, [&] (auto* ptr, const auto* args) {
    204             return WTF::atomicExchangeAnd(ptr, args[0]);
     202        exec, [&] (auto* ptr, const int32_t* args) {
     203            return jsNumber(WTF::atomicExchangeAnd(ptr, args[0]));
    205204        });
    206205}
     
    209208{
    210209    return atomicOperationWithArgs<2>(
    211         exec, [&] (auto* ptr, const auto* args) {
    212             return WTF::atomicCompareExchangeStrong(ptr, args[0], args[1]);
     210        exec, [&] (auto* ptr, const int32_t* args) {
     211            typedef typename std::remove_pointer<decltype(ptr)>::type T;
     212            T expected = static_cast<T>(args[0]);
     213            T newValue = static_cast<T>(args[1]);
     214            return jsNumber(WTF::atomicCompareExchangeStrong(ptr, expected, newValue));
    213215        });
    214216}
     
    217219{
    218220    return atomicOperationWithArgs<1>(
    219         exec, [&] (auto* ptr, const auto* args) {
    220             return WTF::atomicExchange(ptr, args[0]);
     221        exec, [&] (auto* ptr, const int32_t* args) {
     222            typedef typename std::remove_pointer<decltype(ptr)>::type T;
     223            return jsNumber(WTF::atomicExchange(ptr, static_cast<T>(args[0])));
    221224        });
    222225}
     
    247250{
    248251    return atomicOperationWithArgs<0>(
    249         exec, [&] (auto* ptr, const auto*) {
    250             return WTF::atomicLoad(ptr);
     252        exec, [&] (auto* ptr, const int32_t*) {
     253            return jsNumber(WTF::atomicLoad(ptr));
    251254        });
    252255}
     
    255258{
    256259    return atomicOperationWithArgs<1>(
    257         exec, [&] (auto* ptr, const auto* args) {
    258             return WTF::atomicExchangeOr(ptr, args[0]);
     260        exec, [&] (auto* ptr, const int32_t* args) {
     261            return jsNumber(WTF::atomicExchangeOr(ptr, args[0]));
    259262        });
    260263}
     
    263266{
    264267    return atomicOperationWithArgs<1>(
    265         exec, [&] (auto* ptr, const auto* args) {
    266             auto value = args[0];
    267             WTF::atomicStore(ptr, value);
    268             return value;
     268        exec, [&] (auto* ptr, const int32_t* args) {
     269            typedef typename std::remove_pointer<decltype(ptr)>::type T;
     270            int32_t valueAsInt = args[0];
     271            T valueAsT = static_cast<T>(valueAsInt);
     272            WTF::atomicStore(ptr, valueAsT);
     273           
     274            if (static_cast<int32_t>(valueAsT) == valueAsInt)
     275                return jsNumber(valueAsT);
     276            return jsNumber(valueAsInt);
    269277        });
    270278}
     
    273281{
    274282    return atomicOperationWithArgs<1>(
    275         exec, [&] (auto* ptr, const auto* args) {
    276             return WTF::atomicExchangeSub(ptr, args[0]);
     283        exec, [&] (auto* ptr, const int32_t* args) {
     284            return jsNumber(WTF::atomicExchangeSub(ptr, args[0]));
    277285        });
    278286}
     
    383391{
    384392    return atomicOperationWithArgs<1>(
    385         exec, [&] (auto* ptr, const auto* args) {
    386             return WTF::atomicExchangeXor(ptr, args[0]);
     393        exec, [&] (auto* ptr, const int32_t* args) {
     394            return jsNumber(WTF::atomicExchangeXor(ptr, args[0]));
    387395        });
    388396}
Note: See TracChangeset for help on using the changeset viewer.