From 561bd9861ac2efc82ac231212df76248b5c0fa77 Mon Sep 17 00:00:00 2001 From: "erik.corry@gmail.com" Date: Wed, 22 Apr 2009 14:09:50 +0000 Subject: [PATCH] Make a test that excercises the preemption code in apply(). Review URL: http://codereview.chromium.org/93015 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1772 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- test/cctest/test-api.cc | 106 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index eaba627..b7a5cb6 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -6014,6 +6014,112 @@ TEST(RegExpInterruption) { } +class ApplyInterruptTest { + public: + ApplyInterruptTest() : block_(NULL) {} + ~ApplyInterruptTest() { delete block_; } + void RunTest() { + block_ = i::OS::CreateSemaphore(0); + gc_count_ = 0; + gc_during_apply_ = 0; + apply_success_ = false; + gc_success_ = false; + GCThread gc_thread(this); + gc_thread.Start(); + v8::Locker::StartPreemption(1); + + LongRunningApply(); + { + v8::Unlocker unlock; + gc_thread.Join(); + } + v8::Locker::StopPreemption(); + CHECK(apply_success_); + CHECK(gc_success_); + } + private: + // Number of garbage collections required. + static const int kRequiredGCs = 2; + + class GCThread : public i::Thread { + public: + explicit GCThread(ApplyInterruptTest* test) + : test_(test) {} + virtual void Run() { + test_->CollectGarbage(); + } + private: + ApplyInterruptTest* test_; + }; + + void CollectGarbage() { + block_->Wait(); + while (gc_during_apply_ < kRequiredGCs) { + { + v8::Locker lock; + i::Heap::CollectAllGarbage(); + gc_count_++; + } + i::OS::Sleep(1); + } + gc_success_ = true; + } + + void LongRunningApply() { + block_->Signal(); + int rounds = 0; + while (gc_during_apply_ < kRequiredGCs) { + int gc_before = gc_count_; + { + const char* c_source = + "function do_very_little(bar) {" + " this.foo = bar;" + "}" + "for (var i = 0; i < 100000; i++) {" + " do_very_little.apply(this, ['bar']);" + "}"; + Local source = String::New(c_source); + Local