Reviewers: Michael Starzinger,

Message:
Review feedback addressed, landing


https://codereview.chromium.org/18550002/diff/5001/src/factory.h
File src/factory.h (right):

https://codereview.chromium.org/18550002/diff/5001/src/factory.h#newcode572
src/factory.h:572: class IdempotentHandleToPointerCodeTrampoline {
On 2013/07/05 07:49:07, Michael Starzinger wrote:
nit: s/HandleToPointer/PointerToHandle/

Done.

https://codereview.chromium.org/18550002/diff/5001/src/factory.h#newcode579
src/factory.h:579: int scavenges = isolate_->heap()->gc_count();
On 2013/07/05 07:49:07, Michael Starzinger wrote:
nit: Since this doesn't only count minor GCs, but all GCs, let's
rename this
local variable s/scavenges/collections/. Same comment applies several
times
below.

Done.

https://codereview.chromium.org/18550002/diff/5001/src/factory.h#newcode589
src/factory.h:589: MaybeObject* result = (*function)();
On 2013/07/05 07:49:07, Michael Starzinger wrote:
I think the called function is not allowed to return a MaybeObject of
it's own.
Handlified code has to either return Handle<T> or something that is
below Object
in the type hierarchy. Can we s/MaybeObject/Object/ here? Same comment
applies
several times
below.

Done.

Description:
Add trampoline to enable pointer -> handle code calls

[email protected]

Please review this at https://codereview.chromium.org/18550002/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/factory.h
  M src/heap.h


Index: src/factory.h
diff --git a/src/factory.h b/src/factory.h
index 0cb715772909cbf17b19a03b86c21c3ba3f81782..b39c4f48af7fceb16aa0be1eb5cbf98e789b3d71 100644
--- a/src/factory.h
+++ b/src/factory.h
@@ -564,6 +564,82 @@ Handle<Object> Factory::NewNumberFromSize(size_t value,
 }


+// Used to "safely" transition from pointer-based runtime code to Handle-based
+// runtime code. When a GC happens during the called Handle-based code, a
+// failure object is returned to the pointer-based code to cause it abort and +// re-trigger a gc of it's own. Since this double-gc will cause the Handle-based
+// code to be called twice, it must be idempotent.
+class IdempotentPointerToHandleCodeTrampoline {
+ public:
+  explicit IdempotentPointerToHandleCodeTrampoline(Isolate* isolate)
+      : isolate_(isolate) {}
+
+  template<typename R>
+  MUST_USE_RESULT MaybeObject* Call(R (*function)()) {
+    int collections = isolate_->heap()->gc_count();
+    (*function)();
+    return (collections == isolate_->heap()->gc_count())
+        ? isolate_->heap()->true_value()
+        : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
+  }
+
+  template<typename R>
+  MUST_USE_RESULT MaybeObject* CallWithReturnValue(R (*function)()) {
+    int collections = isolate_->heap()->gc_count();
+    Object* result = (*function)();
+    return (collections == isolate_->heap()->gc_count())
+        ? result
+        : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
+  }
+
+  template<typename R, typename P1>
+  MUST_USE_RESULT MaybeObject* Call(R (*function)(P1), P1 p1) {
+    int collections = isolate_->heap()->gc_count();
+    (*function)(p1);
+    return (collections == isolate_->heap()->gc_count())
+        ? isolate_->heap()->true_value()
+        : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
+  }
+
+  template<typename R, typename P1>
+  MUST_USE_RESULT MaybeObject* CallWithReturnValue(
+      R (*function)(P1),
+      P1 p1) {
+    int collections = isolate_->heap()->gc_count();
+    Object* result = (*function)(p1);
+    return (collections == isolate_->heap()->gc_count())
+        ? result
+        : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
+  }
+
+  template<typename R, typename P1, typename P2>
+  MUST_USE_RESULT MaybeObject* Call(
+      R (*function)(P1, P2),
+      P1 p1,
+      P2 p2) {
+    int collections = isolate_->heap()->gc_count();
+    (*function)(p1, p2);
+    return (collections == isolate_->heap()->gc_count())
+        ? isolate_->heap()->true_value()
+        : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
+  }
+
+  template<typename R, typename P1, typename P2>
+  MUST_USE_RESULT MaybeObject* CallWithReturnValue(
+      R (*function)(P1, P2),
+      P1 p1,
+      P2 p2) {
+    int collections = isolate_->heap()->gc_count();
+    Object* result = (*function)(p1, p2);
+    return (collections == isolate_->heap()->gc_count())
+        ? result
+        : reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
+  }
+
+ private:
+  Isolate* isolate_;
+};
+

 } }  // namespace v8::internal

Index: src/heap.h
diff --git a/src/heap.h b/src/heap.h
index d254b607b6e756d29245c5d312def4d3f00afaaf..f020c7f3db9064fc989c328d8712898db9d9d8ee 100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -1812,6 +1812,8 @@ class Heap {
   void QueueMemoryChunkForFree(MemoryChunk* chunk);
   void FreeQueuedChunks();

+  int gc_count() const { return gc_count_; }
+
// Completely clear the Instanceof cache (to stop it keeping objects alive
   // around a GC).
   inline void CompletelyClearInstanceofCache();


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to