From 63c817cc55919c129ab6b574f99ab1231eccc909 Mon Sep 17 00:00:00 2001 From: "bmeurer@chromium.org" Date: Fri, 6 Sep 2013 11:29:13 +0000 Subject: [PATCH] Drop GetCurrentThreadId() and TerminateExecution(int) from the external API. R=dcarney@chromium.org Review URL: https://codereview.chromium.org/23538007 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16570 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8.h | 34 ----------------- src/api.cc | 23 ------------ test/cctest/test-thread-termination.cc | 67 ---------------------------------- 3 files changed, 124 deletions(-) diff --git a/include/v8.h b/include/v8.h index ba4d19b..be838c2 100644 --- a/include/v8.h +++ b/include/v8.h @@ -4592,40 +4592,6 @@ class V8_EXPORT V8 { intptr_t change_in_bytes); /** - * Retrieve the V8 thread id of the calling thread. - * - * The thread id for a thread should only be retrieved after the V8 - * lock has been acquired with a Locker object with that thread. - */ - static int GetCurrentThreadId(); - - /** - * Forcefully terminate execution of a JavaScript thread. This can - * be used to terminate long-running scripts. - * - * TerminateExecution should only be called when then V8 lock has - * been acquired with a Locker object. Therefore, in order to be - * able to terminate long-running threads, preemption must be - * enabled to allow the user of TerminateExecution to acquire the - * lock. - * - * The termination is achieved by throwing an exception that is - * uncatchable by JavaScript exception handlers. Termination - * exceptions act as if they were caught by a C++ TryCatch exception - * handler. If forceful termination is used, any C++ TryCatch - * exception handler that catches an exception should check if that - * exception is a termination exception and immediately return if - * that is the case. Returning immediately in that case will - * continue the propagation of the termination exception if needed. - * - * The thread id passed to TerminateExecution must have been - * obtained by calling GetCurrentThreadId on the thread in question. - * - * \param thread_id The thread id of the thread to terminate. - */ - static void TerminateExecution(int thread_id); - - /** * Forcefully terminate the current thread of JavaScript execution * in the given isolate. If no isolate is provided, the default * isolate is used. diff --git a/src/api.cc b/src/api.cc index ad75715..22228c4 100644 --- a/src/api.cc +++ b/src/api.cc @@ -6772,29 +6772,6 @@ void V8::RemoveCallCompletedCallback(CallCompletedCallback callback) { } -int V8::GetCurrentThreadId() { - i::Isolate* isolate = i::Isolate::Current(); - EnsureInitializedForIsolate(isolate, "V8::GetCurrentThreadId()"); - return isolate->thread_id().ToInteger(); -} - - -void V8::TerminateExecution(int thread_id) { - i::Isolate* isolate = i::Isolate::Current(); - if (!isolate->IsInitialized()) return; - API_ENTRY_CHECK(isolate, "V8::TerminateExecution()"); - // If the thread_id identifies the current thread just terminate - // execution right away. Otherwise, ask the thread manager to - // terminate the thread with the given id if any. - i::ThreadId internal_tid = i::ThreadId::FromInteger(thread_id); - if (isolate->thread_id().Equals(internal_tid)) { - isolate->stack_guard()->TerminateExecution(); - } else { - isolate->thread_manager()->TerminateExecution(internal_tid); - } -} - - void V8::TerminateExecution(Isolate* isolate) { // If no isolate is supplied, use the default isolate. if (isolate != NULL) { diff --git a/test/cctest/test-thread-termination.cc b/test/cctest/test-thread-termination.cc index 4c08539..619bce7 100644 --- a/test/cctest/test-thread-termination.cc +++ b/test/cctest/test-thread-termination.cc @@ -192,73 +192,6 @@ TEST(TerminateOnlyV8ThreadFromOtherThread) { } -class LoopingThread : public v8::internal::Thread { - public: - LoopingThread() : Thread("LoopingThread") { } - void Run() { - v8::Locker locker(CcTest::default_isolate()); - v8::HandleScope scope(CcTest::default_isolate()); - v8_thread_id_ = v8::V8::GetCurrentThreadId(); - v8::Handle global = - CreateGlobalTemplate(Signal, DoLoop); - v8::Handle context = - v8::Context::New(v8::Isolate::GetCurrent(), NULL, global); - v8::Context::Scope context_scope(context); - CHECK(!v8::V8::IsExecutionTerminating()); - // Run a loop that will be infinite if thread termination does not work. - v8::Handle source = - v8::String::New("try { loop(); fail(); } catch(e) { fail(); }"); - v8::Script::Compile(source)->Run(); - } - - int GetV8ThreadId() { return v8_thread_id_; } - - private: - int v8_thread_id_; -}; - - -// Test that multiple threads using default isolate can be terminated -// from another thread when using Lockers and preemption. -TEST(TerminateMultipleV8ThreadsDefaultIsolate) { - { - v8::Locker locker(CcTest::default_isolate()); - v8::V8::Initialize(); - v8::Locker::StartPreemption(1); - semaphore = new v8::internal::Semaphore(0); - } - const int kThreads = 2; - i::List threads(kThreads); - for (int i = 0; i < kThreads; i++) { - threads.Add(new LoopingThread()); - } - for (int i = 0; i < kThreads; i++) { - threads[i]->Start(); - } - // Wait until all threads have signaled the semaphore. - for (int i = 0; i < kThreads; i++) { - semaphore->Wait(); - } - { - v8::Locker locker(CcTest::default_isolate()); - for (int i = 0; i < kThreads; i++) { - v8::V8::TerminateExecution(threads[i]->GetV8ThreadId()); - } - } - for (int i = 0; i < kThreads; i++) { - threads[i]->Join(); - delete threads[i]; - } - { - v8::Locker locker(CcTest::default_isolate()); - v8::Locker::StopPreemption(); - } - - delete semaphore; - semaphore = NULL; -} - - int call_count = 0; -- 2.7.4