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> |
219 inline Object* DoStore(Isolate* isolate, void* buffer, size_t index, | 226 inline Object* DoStore(Isolate* isolate, void* buffer, size_t index, |
220 Handle<Object> obj) { | 227 Handle<Object> obj) { |
221 T value = FromObject<T>(obj); | 228 T value = FromObject<T>(obj); |
222 StoreSeqCst(static_cast<T*>(buffer) + index, value); | 229 StoreSeqCst(static_cast<T*>(buffer) + index, value); |
223 return *obj; | 230 return *obj; |
224 } | 231 } |
225 | 232 |
226 | 233 |
227 template <typename T> | 234 template <typename T> |
228 inline Object* DoAdd(Isolate* isolate, void* buffer, size_t index, | 235 inline Object* DoAdd(Isolate* isolate, void* buffer, size_t index, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 // Duplicated from objects.h | 358 // Duplicated from objects.h |
352 // V has parameters (Type, type, TYPE, C type, element_size) | 359 // V has parameters (Type, type, TYPE, C type, element_size) |
353 #define INTEGER_TYPED_ARRAYS(V) \ | 360 #define INTEGER_TYPED_ARRAYS(V) \ |
354 V(Uint8, uint8, UINT8, uint8_t, 1) \ | 361 V(Uint8, uint8, UINT8, uint8_t, 1) \ |
355 V(Int8, int8, INT8, int8_t, 1) \ | 362 V(Int8, int8, INT8, int8_t, 1) \ |
356 V(Uint16, uint16, UINT16, uint16_t, 2) \ | 363 V(Uint16, uint16, UINT16, uint16_t, 2) \ |
357 V(Int16, int16, INT16, int16_t, 2) \ | 364 V(Int16, int16, INT16, int16_t, 2) \ |
358 V(Uint32, uint32, UINT32, uint32_t, 4) \ | 365 V(Uint32, uint32, UINT32, uint32_t, 4) \ |
359 V(Int32, int32, INT32, int32_t, 4) | 366 V(Int32, int32, INT32, int32_t, 4) |
360 | 367 |
361 RUNTIME_FUNCTION(Runtime_ThrowNotIntegerSharedTypedArrayError) { | |
362 HandleScope scope(isolate); | |
363 DCHECK_EQ(1, args.length()); | |
364 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); | |
365 THROW_NEW_ERROR_RETURN_FAILURE( | |
366 isolate, | |
367 NewTypeError(MessageTemplate::kNotIntegerSharedTypedArray, value)); | |
368 } | |
369 | |
370 RUNTIME_FUNCTION(Runtime_ThrowNotInt32SharedTypedArrayError) { | |
371 HandleScope scope(isolate); | |
372 DCHECK_EQ(1, args.length()); | |
373 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); | |
374 THROW_NEW_ERROR_RETURN_FAILURE( | |
375 isolate, NewTypeError(MessageTemplate::kNotInt32SharedTypedArray, value)); | |
376 } | |
377 | |
378 RUNTIME_FUNCTION(Runtime_ThrowInvalidAtomicAccessIndexError) { | |
379 HandleScope scope(isolate); | |
380 DCHECK_EQ(0, args.length()); | |
381 THROW_NEW_ERROR_RETURN_FAILURE( | |
382 isolate, NewRangeError(MessageTemplate::kInvalidAtomicAccessIndex)); | |
383 } | |
384 | 368 |
385 RUNTIME_FUNCTION(Runtime_AtomicsCompareExchange) { | 369 RUNTIME_FUNCTION(Runtime_AtomicsCompareExchange) { |
386 HandleScope scope(isolate); | 370 HandleScope scope(isolate); |
387 DCHECK(args.length() == 4); | 371 DCHECK(args.length() == 4); |
388 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); | 372 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); |
389 CONVERT_SIZE_ARG_CHECKED(index, 1); | 373 CONVERT_SIZE_ARG_CHECKED(index, 1); |
390 CONVERT_NUMBER_ARG_HANDLE_CHECKED(oldobj, 2); | 374 CONVERT_NUMBER_ARG_HANDLE_CHECKED(oldobj, 2); |
391 CONVERT_NUMBER_ARG_HANDLE_CHECKED(newobj, 3); | 375 CONVERT_NUMBER_ARG_HANDLE_CHECKED(newobj, 3); |
392 RUNTIME_ASSERT(sta->GetBuffer()->is_shared()); | 376 RUNTIME_ASSERT(sta->GetBuffer()->is_shared()); |
393 RUNTIME_ASSERT(index < NumberToSize(isolate, sta->length())); | 377 RUNTIME_ASSERT(index < NumberToSize(isolate, sta->length())); |
(...skipping 16 matching lines...) Expand all Loading... |
410 default: | 394 default: |
411 break; | 395 break; |
412 } | 396 } |
413 | 397 |
414 UNREACHABLE(); | 398 UNREACHABLE(); |
415 return isolate->heap()->undefined_value(); | 399 return isolate->heap()->undefined_value(); |
416 } | 400 } |
417 | 401 |
418 | 402 |
419 RUNTIME_FUNCTION(Runtime_AtomicsLoad) { | 403 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 |
420 UNREACHABLE(); | 429 UNREACHABLE(); |
421 return isolate->heap()->undefined_value(); | 430 return isolate->heap()->undefined_value(); |
422 } | 431 } |
423 | 432 |
424 | 433 |
425 RUNTIME_FUNCTION(Runtime_AtomicsStore) { | 434 RUNTIME_FUNCTION(Runtime_AtomicsStore) { |
426 HandleScope scope(isolate); | 435 HandleScope scope(isolate); |
427 DCHECK(args.length() == 3); | 436 DCHECK(args.length() == 3); |
428 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); | 437 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); |
429 CONVERT_SIZE_ARG_CHECKED(index, 1); | 438 CONVERT_SIZE_ARG_CHECKED(index, 1); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 | 657 |
649 RUNTIME_FUNCTION(Runtime_AtomicsIsLockFree) { | 658 RUNTIME_FUNCTION(Runtime_AtomicsIsLockFree) { |
650 HandleScope scope(isolate); | 659 HandleScope scope(isolate); |
651 DCHECK(args.length() == 1); | 660 DCHECK(args.length() == 1); |
652 CONVERT_NUMBER_ARG_HANDLE_CHECKED(size, 0); | 661 CONVERT_NUMBER_ARG_HANDLE_CHECKED(size, 0); |
653 uint32_t usize = NumberToUint32(*size); | 662 uint32_t usize = NumberToUint32(*size); |
654 return isolate->heap()->ToBoolean(AtomicIsLockFree(usize)); | 663 return isolate->heap()->ToBoolean(AtomicIsLockFree(usize)); |
655 } | 664 } |
656 } // namespace internal | 665 } // namespace internal |
657 } // namespace v8 | 666 } // namespace v8 |
OLD | NEW |