Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/factory.h

Issue 18550002: Add trampoline to enable pointer -> handle code calls (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review feedback Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/heap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 IdempotentPointerToHandleCodeTrampoline {
573 public:
574 explicit IdempotentPointerToHandleCodeTrampoline(Isolate* isolate)
575 : isolate_(isolate) {}
576
577 template<typename R>
578 MUST_USE_RESULT MaybeObject* Call(R (*function)()) {
579 int collections = isolate_->heap()->gc_count();
580 (*function)();
581 return (collections == 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 collections = isolate_->heap()->gc_count();
589 Object* result = (*function)();
590 return (collections == 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 collections = isolate_->heap()->gc_count();
598 (*function)(p1);
599 return (collections == 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 collections = isolate_->heap()->gc_count();
609 Object* result = (*function)(p1);
610 return (collections == 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 collections = isolate_->heap()->gc_count();
621 (*function)(p1, p2);
622 return (collections == 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 collections = isolate_->heap()->gc_count();
633 Object* result = (*function)(p1, p2);
634 return (collections == 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_
OLDNEW
« no previous file with comments | « no previous file | src/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698