| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 PretenureFlag pretenure) { | 581 PretenureFlag pretenure) { |
| 582 if (Smi::IsValid(static_cast<intptr_t>(value))) { | 582 if (Smi::IsValid(static_cast<intptr_t>(value))) { |
| 583 return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)), | 583 return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)), |
| 584 isolate()); | 584 isolate()); |
| 585 } else { | 585 } else { |
| 586 return NewNumber(static_cast<double>(value), pretenure); | 586 return NewNumber(static_cast<double>(value), pretenure); |
| 587 } | 587 } |
| 588 } | 588 } |
| 589 | 589 |
| 590 | 590 |
| 591 // Used to "safely" transition from pointer-based runtime code to Handle-based | |
| 592 // runtime code. When a GC happens during the called Handle-based code, a | |
| 593 // failure object is returned to the pointer-based code to cause it abort and | |
| 594 // re-trigger a gc of it's own. Since this double-gc will cause the Handle-based | |
| 595 // code to be called twice, it must be idempotent. | |
| 596 class IdempotentPointerToHandleCodeTrampoline { | |
| 597 public: | |
| 598 explicit IdempotentPointerToHandleCodeTrampoline(Isolate* isolate) | |
| 599 : isolate_(isolate) {} | |
| 600 | |
| 601 template<typename R> | |
| 602 MUST_USE_RESULT MaybeObject* Call(R (*function)()) { | |
| 603 int collections = isolate_->heap()->gc_count(); | |
| 604 (*function)(); | |
| 605 return (collections == isolate_->heap()->gc_count()) | |
| 606 ? isolate_->heap()->true_value() | |
| 607 : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC()); | |
| 608 } | |
| 609 | |
| 610 template<typename R> | |
| 611 MUST_USE_RESULT MaybeObject* CallWithReturnValue(R (*function)()) { | |
| 612 int collections = isolate_->heap()->gc_count(); | |
| 613 Object* result = (*function)(); | |
| 614 return (collections == isolate_->heap()->gc_count()) | |
| 615 ? result | |
| 616 : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC()); | |
| 617 } | |
| 618 | |
| 619 template<typename R, typename P1> | |
| 620 MUST_USE_RESULT MaybeObject* Call(R (*function)(P1), P1 p1) { | |
| 621 int collections = isolate_->heap()->gc_count(); | |
| 622 (*function)(p1); | |
| 623 return (collections == isolate_->heap()->gc_count()) | |
| 624 ? isolate_->heap()->true_value() | |
| 625 : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC()); | |
| 626 } | |
| 627 | |
| 628 template<typename R, typename P1> | |
| 629 MUST_USE_RESULT MaybeObject* CallWithReturnValue( | |
| 630 R (*function)(P1), | |
| 631 P1 p1) { | |
| 632 int collections = isolate_->heap()->gc_count(); | |
| 633 Object* result = (*function)(p1); | |
| 634 return (collections == isolate_->heap()->gc_count()) | |
| 635 ? result | |
| 636 : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC()); | |
| 637 } | |
| 638 | |
| 639 template<typename R, typename P1, typename P2> | |
| 640 MUST_USE_RESULT MaybeObject* Call( | |
| 641 R (*function)(P1, P2), | |
| 642 P1 p1, | |
| 643 P2 p2) { | |
| 644 int collections = isolate_->heap()->gc_count(); | |
| 645 (*function)(p1, p2); | |
| 646 return (collections == isolate_->heap()->gc_count()) | |
| 647 ? isolate_->heap()->true_value() | |
| 648 : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC()); | |
| 649 } | |
| 650 | |
| 651 template<typename R, typename P1, typename P2> | |
| 652 MUST_USE_RESULT MaybeObject* CallWithReturnValue( | |
| 653 R (*function)(P1, P2), | |
| 654 P1 p1, | |
| 655 P2 p2) { | |
| 656 int collections = isolate_->heap()->gc_count(); | |
| 657 Object* result = (*function)(p1, p2); | |
| 658 return (collections == isolate_->heap()->gc_count()) | |
| 659 ? result | |
| 660 : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC()); | |
| 661 } | |
| 662 | |
| 663 template<typename R, typename P1, typename P2, typename P3, typename P4, | |
| 664 typename P5, typename P6, typename P7> | |
| 665 MUST_USE_RESULT MaybeObject* CallWithReturnValue( | |
| 666 R (*function)(P1, P2, P3, P4, P5, P6, P7), | |
| 667 P1 p1, | |
| 668 P2 p2, | |
| 669 P3 p3, | |
| 670 P4 p4, | |
| 671 P5 p5, | |
| 672 P6 p6, | |
| 673 P7 p7) { | |
| 674 int collections = isolate_->heap()->gc_count(); | |
| 675 Handle<Object> result = (*function)(p1, p2, p3, p4, p5, p6, p7); | |
| 676 return (collections == isolate_->heap()->gc_count()) | |
| 677 ? *result | |
| 678 : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC()); | |
| 679 } | |
| 680 | |
| 681 private: | |
| 682 Isolate* isolate_; | |
| 683 }; | |
| 684 | |
| 685 | |
| 686 } } // namespace v8::internal | 591 } } // namespace v8::internal |
| 687 | 592 |
| 688 #endif // V8_FACTORY_H_ | 593 #endif // V8_FACTORY_H_ |
| OLD | NEW |