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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 } | 348 } |
349 | 349 |
350 RUNTIME_FUNCTION(Runtime_AtomicsCompareExchange) { | 350 RUNTIME_FUNCTION(Runtime_AtomicsCompareExchange) { |
351 HandleScope scope(isolate); | 351 HandleScope scope(isolate); |
352 DCHECK(args.length() == 4); | 352 DCHECK(args.length() == 4); |
353 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); | 353 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); |
354 CONVERT_SIZE_ARG_CHECKED(index, 1); | 354 CONVERT_SIZE_ARG_CHECKED(index, 1); |
355 CONVERT_NUMBER_ARG_HANDLE_CHECKED(oldobj, 2); | 355 CONVERT_NUMBER_ARG_HANDLE_CHECKED(oldobj, 2); |
356 CONVERT_NUMBER_ARG_HANDLE_CHECKED(newobj, 3); | 356 CONVERT_NUMBER_ARG_HANDLE_CHECKED(newobj, 3); |
357 CHECK(sta->GetBuffer()->is_shared()); | 357 CHECK(sta->GetBuffer()->is_shared()); |
358 CHECK_LT(index, NumberToSize(isolate, sta->length())); | 358 CHECK_LT(index, NumberToSize(sta->length())); |
359 | 359 |
360 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + | 360 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + |
361 NumberToSize(isolate, sta->byte_offset()); | 361 NumberToSize(sta->byte_offset()); |
362 | 362 |
363 switch (sta->type()) { | 363 switch (sta->type()) { |
364 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ | 364 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ |
365 case kExternal##Type##Array: \ | 365 case kExternal##Type##Array: \ |
366 return DoCompareExchange<ctype>(isolate, source, index, oldobj, newobj); | 366 return DoCompareExchange<ctype>(isolate, source, index, oldobj, newobj); |
367 | 367 |
368 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) | 368 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) |
369 #undef TYPED_ARRAY_CASE | 369 #undef TYPED_ARRAY_CASE |
370 | 370 |
371 case kExternalUint8ClampedArray: | 371 case kExternalUint8ClampedArray: |
372 return DoCompareExchangeUint8Clamped(isolate, source, index, oldobj, | 372 return DoCompareExchangeUint8Clamped(isolate, source, index, oldobj, |
373 newobj); | 373 newobj); |
374 | 374 |
375 default: | 375 default: |
376 break; | 376 break; |
377 } | 377 } |
378 | 378 |
379 UNREACHABLE(); | 379 UNREACHABLE(); |
380 return isolate->heap()->undefined_value(); | 380 return isolate->heap()->undefined_value(); |
381 } | 381 } |
382 | 382 |
383 | 383 |
384 RUNTIME_FUNCTION(Runtime_AtomicsAdd) { | 384 RUNTIME_FUNCTION(Runtime_AtomicsAdd) { |
385 HandleScope scope(isolate); | 385 HandleScope scope(isolate); |
386 DCHECK(args.length() == 3); | 386 DCHECK(args.length() == 3); |
387 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); | 387 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); |
388 CONVERT_SIZE_ARG_CHECKED(index, 1); | 388 CONVERT_SIZE_ARG_CHECKED(index, 1); |
389 CONVERT_NUMBER_ARG_HANDLE_CHECKED(value, 2); | 389 CONVERT_NUMBER_ARG_HANDLE_CHECKED(value, 2); |
390 CHECK(sta->GetBuffer()->is_shared()); | 390 CHECK(sta->GetBuffer()->is_shared()); |
391 CHECK_LT(index, NumberToSize(isolate, sta->length())); | 391 CHECK_LT(index, NumberToSize(sta->length())); |
392 | 392 |
393 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + | 393 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + |
394 NumberToSize(isolate, sta->byte_offset()); | 394 NumberToSize(sta->byte_offset()); |
395 | 395 |
396 switch (sta->type()) { | 396 switch (sta->type()) { |
397 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ | 397 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ |
398 case kExternal##Type##Array: \ | 398 case kExternal##Type##Array: \ |
399 return DoAdd<ctype>(isolate, source, index, value); | 399 return DoAdd<ctype>(isolate, source, index, value); |
400 | 400 |
401 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) | 401 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) |
402 #undef TYPED_ARRAY_CASE | 402 #undef TYPED_ARRAY_CASE |
403 | 403 |
404 case kExternalUint8ClampedArray: | 404 case kExternalUint8ClampedArray: |
405 return DoAddUint8Clamped(isolate, source, index, value); | 405 return DoAddUint8Clamped(isolate, source, index, value); |
406 | 406 |
407 default: | 407 default: |
408 break; | 408 break; |
409 } | 409 } |
410 | 410 |
411 UNREACHABLE(); | 411 UNREACHABLE(); |
412 return isolate->heap()->undefined_value(); | 412 return isolate->heap()->undefined_value(); |
413 } | 413 } |
414 | 414 |
415 | 415 |
416 RUNTIME_FUNCTION(Runtime_AtomicsSub) { | 416 RUNTIME_FUNCTION(Runtime_AtomicsSub) { |
417 HandleScope scope(isolate); | 417 HandleScope scope(isolate); |
418 DCHECK(args.length() == 3); | 418 DCHECK(args.length() == 3); |
419 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); | 419 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); |
420 CONVERT_SIZE_ARG_CHECKED(index, 1); | 420 CONVERT_SIZE_ARG_CHECKED(index, 1); |
421 CONVERT_NUMBER_ARG_HANDLE_CHECKED(value, 2); | 421 CONVERT_NUMBER_ARG_HANDLE_CHECKED(value, 2); |
422 CHECK(sta->GetBuffer()->is_shared()); | 422 CHECK(sta->GetBuffer()->is_shared()); |
423 CHECK_LT(index, NumberToSize(isolate, sta->length())); | 423 CHECK_LT(index, NumberToSize(sta->length())); |
424 | 424 |
425 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + | 425 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + |
426 NumberToSize(isolate, sta->byte_offset()); | 426 NumberToSize(sta->byte_offset()); |
427 | 427 |
428 switch (sta->type()) { | 428 switch (sta->type()) { |
429 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ | 429 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ |
430 case kExternal##Type##Array: \ | 430 case kExternal##Type##Array: \ |
431 return DoSub<ctype>(isolate, source, index, value); | 431 return DoSub<ctype>(isolate, source, index, value); |
432 | 432 |
433 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) | 433 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) |
434 #undef TYPED_ARRAY_CASE | 434 #undef TYPED_ARRAY_CASE |
435 | 435 |
436 case kExternalUint8ClampedArray: | 436 case kExternalUint8ClampedArray: |
437 return DoSubUint8Clamped(isolate, source, index, value); | 437 return DoSubUint8Clamped(isolate, source, index, value); |
438 | 438 |
439 default: | 439 default: |
440 break; | 440 break; |
441 } | 441 } |
442 | 442 |
443 UNREACHABLE(); | 443 UNREACHABLE(); |
444 return isolate->heap()->undefined_value(); | 444 return isolate->heap()->undefined_value(); |
445 } | 445 } |
446 | 446 |
447 | 447 |
448 RUNTIME_FUNCTION(Runtime_AtomicsAnd) { | 448 RUNTIME_FUNCTION(Runtime_AtomicsAnd) { |
449 HandleScope scope(isolate); | 449 HandleScope scope(isolate); |
450 DCHECK(args.length() == 3); | 450 DCHECK(args.length() == 3); |
451 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); | 451 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); |
452 CONVERT_SIZE_ARG_CHECKED(index, 1); | 452 CONVERT_SIZE_ARG_CHECKED(index, 1); |
453 CONVERT_NUMBER_ARG_HANDLE_CHECKED(value, 2); | 453 CONVERT_NUMBER_ARG_HANDLE_CHECKED(value, 2); |
454 CHECK(sta->GetBuffer()->is_shared()); | 454 CHECK(sta->GetBuffer()->is_shared()); |
455 CHECK_LT(index, NumberToSize(isolate, sta->length())); | 455 CHECK_LT(index, NumberToSize(sta->length())); |
456 | 456 |
457 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + | 457 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + |
458 NumberToSize(isolate, sta->byte_offset()); | 458 NumberToSize(sta->byte_offset()); |
459 | 459 |
460 switch (sta->type()) { | 460 switch (sta->type()) { |
461 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ | 461 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ |
462 case kExternal##Type##Array: \ | 462 case kExternal##Type##Array: \ |
463 return DoAnd<ctype>(isolate, source, index, value); | 463 return DoAnd<ctype>(isolate, source, index, value); |
464 | 464 |
465 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) | 465 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) |
466 #undef TYPED_ARRAY_CASE | 466 #undef TYPED_ARRAY_CASE |
467 | 467 |
468 case kExternalUint8ClampedArray: | 468 case kExternalUint8ClampedArray: |
469 return DoAndUint8Clamped(isolate, source, index, value); | 469 return DoAndUint8Clamped(isolate, source, index, value); |
470 | 470 |
471 default: | 471 default: |
472 break; | 472 break; |
473 } | 473 } |
474 | 474 |
475 UNREACHABLE(); | 475 UNREACHABLE(); |
476 return isolate->heap()->undefined_value(); | 476 return isolate->heap()->undefined_value(); |
477 } | 477 } |
478 | 478 |
479 | 479 |
480 RUNTIME_FUNCTION(Runtime_AtomicsOr) { | 480 RUNTIME_FUNCTION(Runtime_AtomicsOr) { |
481 HandleScope scope(isolate); | 481 HandleScope scope(isolate); |
482 DCHECK(args.length() == 3); | 482 DCHECK(args.length() == 3); |
483 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); | 483 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); |
484 CONVERT_SIZE_ARG_CHECKED(index, 1); | 484 CONVERT_SIZE_ARG_CHECKED(index, 1); |
485 CONVERT_NUMBER_ARG_HANDLE_CHECKED(value, 2); | 485 CONVERT_NUMBER_ARG_HANDLE_CHECKED(value, 2); |
486 CHECK(sta->GetBuffer()->is_shared()); | 486 CHECK(sta->GetBuffer()->is_shared()); |
487 CHECK_LT(index, NumberToSize(isolate, sta->length())); | 487 CHECK_LT(index, NumberToSize(sta->length())); |
488 | 488 |
489 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + | 489 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + |
490 NumberToSize(isolate, sta->byte_offset()); | 490 NumberToSize(sta->byte_offset()); |
491 | 491 |
492 switch (sta->type()) { | 492 switch (sta->type()) { |
493 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ | 493 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ |
494 case kExternal##Type##Array: \ | 494 case kExternal##Type##Array: \ |
495 return DoOr<ctype>(isolate, source, index, value); | 495 return DoOr<ctype>(isolate, source, index, value); |
496 | 496 |
497 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) | 497 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) |
498 #undef TYPED_ARRAY_CASE | 498 #undef TYPED_ARRAY_CASE |
499 | 499 |
500 case kExternalUint8ClampedArray: | 500 case kExternalUint8ClampedArray: |
501 return DoOrUint8Clamped(isolate, source, index, value); | 501 return DoOrUint8Clamped(isolate, source, index, value); |
502 | 502 |
503 default: | 503 default: |
504 break; | 504 break; |
505 } | 505 } |
506 | 506 |
507 UNREACHABLE(); | 507 UNREACHABLE(); |
508 return isolate->heap()->undefined_value(); | 508 return isolate->heap()->undefined_value(); |
509 } | 509 } |
510 | 510 |
511 | 511 |
512 RUNTIME_FUNCTION(Runtime_AtomicsXor) { | 512 RUNTIME_FUNCTION(Runtime_AtomicsXor) { |
513 HandleScope scope(isolate); | 513 HandleScope scope(isolate); |
514 DCHECK(args.length() == 3); | 514 DCHECK(args.length() == 3); |
515 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); | 515 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); |
516 CONVERT_SIZE_ARG_CHECKED(index, 1); | 516 CONVERT_SIZE_ARG_CHECKED(index, 1); |
517 CONVERT_NUMBER_ARG_HANDLE_CHECKED(value, 2); | 517 CONVERT_NUMBER_ARG_HANDLE_CHECKED(value, 2); |
518 CHECK(sta->GetBuffer()->is_shared()); | 518 CHECK(sta->GetBuffer()->is_shared()); |
519 CHECK_LT(index, NumberToSize(isolate, sta->length())); | 519 CHECK_LT(index, NumberToSize(sta->length())); |
520 | 520 |
521 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + | 521 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + |
522 NumberToSize(isolate, sta->byte_offset()); | 522 NumberToSize(sta->byte_offset()); |
523 | 523 |
524 switch (sta->type()) { | 524 switch (sta->type()) { |
525 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ | 525 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ |
526 case kExternal##Type##Array: \ | 526 case kExternal##Type##Array: \ |
527 return DoXor<ctype>(isolate, source, index, value); | 527 return DoXor<ctype>(isolate, source, index, value); |
528 | 528 |
529 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) | 529 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) |
530 #undef TYPED_ARRAY_CASE | 530 #undef TYPED_ARRAY_CASE |
531 | 531 |
532 case kExternalUint8ClampedArray: | 532 case kExternalUint8ClampedArray: |
533 return DoXorUint8Clamped(isolate, source, index, value); | 533 return DoXorUint8Clamped(isolate, source, index, value); |
534 | 534 |
535 default: | 535 default: |
536 break; | 536 break; |
537 } | 537 } |
538 | 538 |
539 UNREACHABLE(); | 539 UNREACHABLE(); |
540 return isolate->heap()->undefined_value(); | 540 return isolate->heap()->undefined_value(); |
541 } | 541 } |
542 | 542 |
543 | 543 |
544 RUNTIME_FUNCTION(Runtime_AtomicsExchange) { | 544 RUNTIME_FUNCTION(Runtime_AtomicsExchange) { |
545 HandleScope scope(isolate); | 545 HandleScope scope(isolate); |
546 DCHECK(args.length() == 3); | 546 DCHECK(args.length() == 3); |
547 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); | 547 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sta, 0); |
548 CONVERT_SIZE_ARG_CHECKED(index, 1); | 548 CONVERT_SIZE_ARG_CHECKED(index, 1); |
549 CONVERT_NUMBER_ARG_HANDLE_CHECKED(value, 2); | 549 CONVERT_NUMBER_ARG_HANDLE_CHECKED(value, 2); |
550 CHECK(sta->GetBuffer()->is_shared()); | 550 CHECK(sta->GetBuffer()->is_shared()); |
551 CHECK_LT(index, NumberToSize(isolate, sta->length())); | 551 CHECK_LT(index, NumberToSize(sta->length())); |
552 | 552 |
553 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + | 553 uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) + |
554 NumberToSize(isolate, sta->byte_offset()); | 554 NumberToSize(sta->byte_offset()); |
555 | 555 |
556 switch (sta->type()) { | 556 switch (sta->type()) { |
557 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ | 557 #define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \ |
558 case kExternal##Type##Array: \ | 558 case kExternal##Type##Array: \ |
559 return DoExchange<ctype>(isolate, source, index, value); | 559 return DoExchange<ctype>(isolate, source, index, value); |
560 | 560 |
561 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) | 561 INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE) |
562 #undef TYPED_ARRAY_CASE | 562 #undef TYPED_ARRAY_CASE |
563 | 563 |
564 case kExternalUint8ClampedArray: | 564 case kExternalUint8ClampedArray: |
(...skipping 10 matching lines...) Expand all Loading... |
575 | 575 |
576 RUNTIME_FUNCTION(Runtime_AtomicsIsLockFree) { | 576 RUNTIME_FUNCTION(Runtime_AtomicsIsLockFree) { |
577 HandleScope scope(isolate); | 577 HandleScope scope(isolate); |
578 DCHECK(args.length() == 1); | 578 DCHECK(args.length() == 1); |
579 CONVERT_NUMBER_ARG_HANDLE_CHECKED(size, 0); | 579 CONVERT_NUMBER_ARG_HANDLE_CHECKED(size, 0); |
580 uint32_t usize = NumberToUint32(*size); | 580 uint32_t usize = NumberToUint32(*size); |
581 return isolate->heap()->ToBoolean(AtomicIsLockFree(usize)); | 581 return isolate->heap()->ToBoolean(AtomicIsLockFree(usize)); |
582 } | 582 } |
583 } // namespace internal | 583 } // namespace internal |
584 } // namespace v8 | 584 } // namespace v8 |
OLD | NEW |