| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/base/macros.h" | 8 #include "src/base/macros.h" |
| 9 #include "src/base/platform/mutex.h" | 9 #include "src/base/platform/mutex.h" |
| 10 #include "src/conversions-inl.h" | 10 #include "src/conversions-inl.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 Handle<Object> oldobj, Handle<Object> newobj) { | 209 Handle<Object> oldobj, Handle<Object> newobj) { |
| 210 T oldval = FromObject<T>(oldobj); | 210 T oldval = FromObject<T>(oldobj); |
| 211 T newval = FromObject<T>(newobj); | 211 T newval = FromObject<T>(newobj); |
| 212 T result = | 212 T result = |
| 213 CompareExchangeSeqCst(static_cast<T*>(buffer) + index, oldval, newval); | 213 CompareExchangeSeqCst(static_cast<T*>(buffer) + index, oldval, newval); |
| 214 return ToObject(isolate, result); | 214 return ToObject(isolate, result); |
| 215 } | 215 } |
| 216 | 216 |
| 217 | 217 |
| 218 template <typename T> | 218 template <typename T> |
| 219 inline Object* DoLoad(Isolate* isolate, void* buffer, size_t index) { | |
| 220 T result = LoadSeqCst(static_cast<T*>(buffer) + index); | |
| 221 return ToObject(isolate, result); | |
| 222 } | |
| 223 | |
| 224 | |
| 225 template <typename T> | |
| 226 inline Object* DoStore(Isolate* isolate, void* buffer, size_t index, | 219 inline Object* DoStore(Isolate* isolate, void* buffer, size_t index, |
| 227 Handle<Object> obj) { | 220 Handle<Object> obj) { |
| 228 T value = FromObject<T>(obj); | 221 T value = FromObject<T>(obj); |
| 229 StoreSeqCst(static_cast<T*>(buffer) + index, value); | 222 StoreSeqCst(static_cast<T*>(buffer) + index, value); |
| 230 return *obj; | 223 return *obj; |
| 231 } | 224 } |
| 232 | 225 |
| 233 | 226 |
| 234 template <typename T> | 227 template <typename T> |
| 235 inline Object* DoAdd(Isolate* isolate, void* buffer, size_t index, | 228 inline Object* DoAdd(Isolate* isolate, void* buffer, size_t index, |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 default: | 387 default: |
| 395 break; | 388 break; |
| 396 } | 389 } |
| 397 | 390 |
| 398 UNREACHABLE(); | 391 UNREACHABLE(); |
| 399 return isolate->heap()->undefined_value(); | 392 return isolate->heap()->undefined_value(); |
| 400 } | 393 } |
| 401 | 394 |
| 402 | 395 |
| 403 RUNTIME_FUNCTION(Runtime_AtomicsLoad) { | 396 RUNTIME_FUNCTION(Runtime_AtomicsLoad) { |
| 404 HandleScope scope(isolate); | |
| 405 DCHECK(args.length() == 2); | |
| 406 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); | |
| 407 CONVERT_SIZE_ARG_CHECKED(index, 1); | |
| 408 RUNTIME_ASSERT(sta->GetBuffer()->is_shared()); | |
| 409 RUNTIME_ASSERT(index < NumberToSize(isolate, sta->length())); | |
| 410 | |
| 411 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + | |
| 412 NumberToSize(isolate, sta->byte_offset()); | |
| 413 | |
| 414 switch (sta->type()) { | |
| 415 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ | |
| 416 case kExternal##Type##Array: \ | |
| 417 return DoLoad<ctype>(isolate, source, index); | |
| 418 | |
| 419 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) | |
| 420 #undef TYPED_ARRAY_CASE | |
| 421 | |
| 422 case kExternalUint8ClampedArray: | |
| 423 return DoLoad<uint8_t>(isolate, source, index); | |
| 424 | |
| 425 default: | |
| 426 break; | |
| 427 } | |
| 428 | |
| 429 UNREACHABLE(); | 397 UNREACHABLE(); |
| 430 return isolate->heap()->undefined_value(); | 398 return isolate->heap()->undefined_value(); |
| 431 } | 399 } |
| 432 | 400 |
| 433 | 401 |
| 434 RUNTIME_FUNCTION(Runtime_AtomicsStore) { | 402 RUNTIME_FUNCTION(Runtime_AtomicsStore) { |
| 435 HandleScope scope(isolate); | 403 HandleScope scope(isolate); |
| 436 DCHECK(args.length() == 3); | 404 DCHECK(args.length() == 3); |
| 437 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); | 405 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); |
| 438 CONVERT_SIZE_ARG_CHECKED(index, 1); | 406 CONVERT_SIZE_ARG_CHECKED(index, 1); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 | 625 |
| 658 RUNTIME_FUNCTION(Runtime_AtomicsIsLockFree) { | 626 RUNTIME_FUNCTION(Runtime_AtomicsIsLockFree) { |
| 659 HandleScope scope(isolate); | 627 HandleScope scope(isolate); |
| 660 DCHECK(args.length() == 1); | 628 DCHECK(args.length() == 1); |
| 661 CONVERT_NUMBER_ARG_HANDLE_CHECKED(size, 0); | 629 CONVERT_NUMBER_ARG_HANDLE_CHECKED(size, 0); |
| 662 uint32_t usize = NumberToUint32(*size); | 630 uint32_t usize = NumberToUint32(*size); |
| 663 return isolate->heap()->ToBoolean(AtomicIsLockFree(usize)); | 631 return isolate->heap()->ToBoolean(AtomicIsLockFree(usize)); |
| 664 } | 632 } |
| 665 } // namespace internal | 633 } // namespace internal |
| 666 } // namespace v8 | 634 } // namespace v8 |
| OLD | NEW |