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