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

Unified Diff: test/cctest/test-api.cc

Issue 8506017: Fix IdleNotification to correctly free objects. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/heap.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 2d3a5994da52422befba8205a9e48f2ced4d50e6..1f083dcac2b2315e1d0e4ad10db33961441b924f 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -13395,6 +13395,72 @@ THREADED_TEST(IdleNotification) {
}
+class Point {
+ public:
+ static int counter;
+
+ Point(int x, int y) : x_(x), y_(y) { ++counter; }
+ ~Point() { --counter; }
+
+ private:
+ int x_, y_;
+};
+
+int Point::counter = 0;
+
+static void weakPointCallback(Persistent<Value> object, void* parameter) {
+ Point* point = static_cast<Point*>(parameter);
+ delete point;
+
+ object.Dispose();
+ object.Clear();
+
+ V8::AdjustAmountOfExternalAllocatedMemory(-static_cast<int>(sizeof(Point)));
+}
+
+static Handle<Value> makeWeakPoint(const Arguments& args) {
+ CHECK(args.IsConstructCall());
+
+ Local<Object> self = args.This();
+ CHECK_EQ(1, self->InternalFieldCount());
+
+ Point *point = new Point(10, 20);
+ self->SetPointerInInternalField(0, point);
+ V8::AdjustAmountOfExternalAllocatedMemory(static_cast<int>(sizeof(Point)));
+
+ Persistent<Object> weak_self = Persistent<Object>::New(self);
+ weak_self.MakeWeak(point, weakPointCallback);
+
+ return weak_self;
+}
+
+// Test that idle notification correctly force garbage collection.
+THREADED_TEST(IdleNotificationForceGC) {
+ HandleScope scope;
+ LocalContext context;
+
+ Local<FunctionTemplate> fun_templ =
+ FunctionTemplate::New(makeWeakPoint);
+ Handle<ObjectTemplate> point_templ = fun_templ->InstanceTemplate();
+ point_templ->SetInternalFieldCount(1);
+
+ context->Global()->Set(String::New("Point"), fun_templ->GetFunction());
+
+ for (int i = 1000; i < 800000; i += 50000) {
+ context->Global()->Set(String::New("counter"), v8::Int32::New(i));
+
+ {
+ HandleScope scope;
+ CompileRun("for (i = 0; i < counter; ++i) { new Point(); }");
+ }
+
+ while (!V8::IdleNotification()) { }
+
+ CHECK_EQ(0, Point::counter);
+ }
+}
+
+
static uint32_t* stack_limit;
static v8::Handle<Value> GetStackLimitCallback(const v8::Arguments& args) {
« no previous file with comments | « src/heap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698