Chromium Code Reviews| 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 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 PretenureFlag pretenure) { | 557 PretenureFlag pretenure) { |
| 558 if (Smi::IsValid(static_cast<intptr_t>(value))) { | 558 if (Smi::IsValid(static_cast<intptr_t>(value))) { |
| 559 return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)), | 559 return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)), |
| 560 isolate()); | 560 isolate()); |
| 561 } else { | 561 } else { |
| 562 return NewNumber(static_cast<double>(value), pretenure); | 562 return NewNumber(static_cast<double>(value), pretenure); |
| 563 } | 563 } |
| 564 } | 564 } |
| 565 | 565 |
| 566 | 566 |
| 567 // Used to "safely" transition from pointer-based runtime code to Handle-based | |
| 568 // runtime code. When a GC happens during the called Handle-based code, a | |
| 569 // failure object is returned to the pointer-based code to cause it abort and | |
| 570 // re-trigger a gc of it's own. Since this double-gc will cause the Handle-based | |
| 571 // code to be called twice, it must be idempotent. | |
| 572 class IdempotentHandleToPointerCodeTrampoline { | |
|
Michael Starzinger
2013/07/05 07:49:07
nit: s/HandleToPointer/PointerToHandle/
danno
2013/07/05 09:35:54
Done.
| |
| 573 public: | |
| 574 explicit IdempotentHandleToPointerCodeTrampoline(Isolate* isolate) | |
| 575 : isolate_(isolate) {} | |
| 576 | |
| 577 template<typename R> | |
| 578 MUST_USE_RESULT MaybeObject* Call(R (*function)()) { | |
| 579 int scavenges = isolate_->heap()->gc_count(); | |
|
Michael Starzinger
2013/07/05 07:49:07
nit: Since this doesn't only count minor GCs, but
danno
2013/07/05 09:35:54
Done.
| |
| 580 (*function)(); | |
| 581 return (scavenges == isolate_->heap()->gc_count()) | |
| 582 ? isolate_->heap()->true_value() | |
| 583 : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC()); | |
| 584 } | |
| 585 | |
| 586 template<typename R> | |
| 587 MUST_USE_RESULT MaybeObject* CallWithReturnValue(R (*function)()) { | |
| 588 int scavenges = isolate_->heap()->gc_count(); | |
| 589 MaybeObject* result = (*function)(); | |
|
Michael Starzinger
2013/07/05 07:49:07
I think the called function is not allowed to retu
danno
2013/07/05 09:35:54
Done.
| |
| 590 return (scavenges == isolate_->heap()->gc_count()) | |
| 591 ? result | |
| 592 : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC()); | |
| 593 } | |
| 594 | |
| 595 template<typename R, typename P1> | |
| 596 MUST_USE_RESULT MaybeObject* Call(R (*function)(P1), P1 p1) { | |
| 597 int scavenges = isolate_->heap()->gc_count(); | |
| 598 (*function)(p1); | |
| 599 return (scavenges == isolate_->heap()->gc_count()) | |
| 600 ? isolate_->heap()->true_value() | |
| 601 : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC()); | |
| 602 } | |
| 603 | |
| 604 template<typename R, typename P1> | |
| 605 MUST_USE_RESULT MaybeObject* CallWithReturnValue( | |
| 606 R (*function)(P1), | |
| 607 P1 p1) { | |
| 608 int scavenges = isolate_->heap()->gc_count(); | |
| 609 MaybeObject* result = (*function)(p1); | |
| 610 return (scavenges == isolate_->heap()->gc_count()) | |
| 611 ? result | |
| 612 : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC()); | |
| 613 } | |
| 614 | |
| 615 template<typename R, typename P1, typename P2> | |
| 616 MUST_USE_RESULT MaybeObject* Call( | |
| 617 R (*function)(P1, P2), | |
| 618 P1 p1, | |
| 619 P2 p2) { | |
| 620 int scavenges = isolate_->heap()->gc_count(); | |
| 621 (*function)(p1, p2); | |
| 622 return (scavenges == isolate_->heap()->gc_count()) | |
| 623 ? isolate_->heap()->true_value() | |
| 624 : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC()); | |
| 625 } | |
| 626 | |
| 627 template<typename R, typename P1, typename P2> | |
| 628 MUST_USE_RESULT MaybeObject* CallWithReturnValue( | |
| 629 R (*function)(P1, P2), | |
| 630 P1 p1, | |
| 631 P2 p2) { | |
| 632 int scavenges = isolate_->heap()->gc_count(); | |
| 633 MaybeObject* result = (*function)(p1, p2); | |
| 634 return (scavenges == isolate_->heap()->gc_count()) | |
| 635 ? result | |
| 636 : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC()); | |
| 637 } | |
| 638 | |
| 639 private: | |
| 640 Isolate* isolate_; | |
| 641 }; | |
| 642 | |
| 567 | 643 |
| 568 } } // namespace v8::internal | 644 } } // namespace v8::internal |
| 569 | 645 |
| 570 #endif // V8_FACTORY_H_ | 646 #endif // V8_FACTORY_H_ |
| OLD | NEW |