Commit c96a606e authored by dcarney@chromium.org's avatar dcarney@chromium.org

Remove default isolate usage from almost all tests

R=svenpanne@chromium.org
BUG=

Review URL: https://codereview.chromium.org/24220003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16809 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 557e9b9d
......@@ -212,9 +212,13 @@ class V8_EXPORT Debug {
// If no isolate is provided the default isolate is
// used.
// TODO(dcarney): remove
static void SendCommand(const uint16_t* command, int length,
ClientData* client_data = NULL,
Isolate* isolate = NULL);
static void SendCommand(Isolate* isolate,
const uint16_t* command, int length,
ClientData* client_data = NULL);
// Dispatch interface.
static void SetHostDispatchHandler(HostDispatchHandler handler,
......
......@@ -5424,7 +5424,6 @@ Local<Context> v8::Context::New(
v8::ExtensionConfiguration* extensions,
v8::Handle<ObjectTemplate> global_template,
v8::Handle<Value> global_object) {
i::Isolate::EnsureDefaultIsolate();
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
EnsureInitializedForIsolate(isolate, "v8::Context::New()");
LOG_API(isolate, "Context::New");
......@@ -6768,7 +6767,6 @@ void V8::RemoveMemoryAllocationCallback(MemoryAllocationCallback callback) {
void V8::AddCallCompletedCallback(CallCompletedCallback callback) {
if (callback == NULL) return;
i::Isolate::EnsureDefaultIsolate();
i::Isolate* isolate = i::Isolate::Current();
if (IsDeadCheck(isolate, "v8::V8::AddLeaveScriptCallback()")) return;
i::V8::AddCallCompletedCallback(callback);
......@@ -6776,7 +6774,6 @@ void V8::AddCallCompletedCallback(CallCompletedCallback callback) {
void V8::RemoveCallCompletedCallback(CallCompletedCallback callback) {
i::Isolate::EnsureDefaultIsolate();
i::Isolate* isolate = i::Isolate::Current();
if (IsDeadCheck(isolate, "v8::V8::RemoveLeaveScriptCallback()")) return;
i::V8::RemoveCallCompletedCallback(callback);
......@@ -7083,6 +7080,16 @@ void Debug::SetMessageHandler2(v8::Debug::MessageHandler2 handler) {
}
void Debug::SendCommand(Isolate* isolate,
const uint16_t* command,
int length,
ClientData* client_data) {
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
internal_isolate->debugger()->ProcessCommand(
i::Vector<const uint16_t>(command, length), client_data);
}
void Debug::SendCommand(const uint16_t* command, int length,
ClientData* client_data,
Isolate* isolate) {
......
......@@ -345,6 +345,14 @@ Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_;
Thread::LocalStorageKey PerThreadAssertScopeBase::thread_local_key;
#endif // DEBUG
Mutex Isolate::process_wide_mutex_;
// TODO(dcarney): Remove with default isolate.
enum DefaultIsolateStatus {
kDefaultIsolateUninitialized,
kDefaultIsolateInitialized,
kDefaultIsolateCrashIfInitialized
};
static DefaultIsolateStatus default_isolate_status_
= kDefaultIsolateUninitialized;
Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL;
Atomic32 Isolate::isolate_counter_ = 0;
......@@ -382,8 +390,16 @@ Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread(
}
void Isolate::SetCrashIfDefaultIsolateInitialized() {
LockGuard<Mutex> lock_guard(&process_wide_mutex_);
CHECK(default_isolate_status_ != kDefaultIsolateInitialized);
default_isolate_status_ = kDefaultIsolateCrashIfInitialized;
}
void Isolate::EnsureDefaultIsolate() {
LockGuard<Mutex> lock_guard(&process_wide_mutex_);
CHECK(default_isolate_status_ != kDefaultIsolateCrashIfInitialized);
if (default_isolate_ == NULL) {
isolate_key_ = Thread::CreateThreadLocalKey();
thread_id_key_ = Thread::CreateThreadLocalKey();
......
......@@ -497,6 +497,7 @@ class Isolate {
bool IsDefaultIsolate() const { return this == default_isolate_; }
static void SetCrashIfDefaultIsolateInitialized();
// Ensures that process-wide resources and the default isolate have been
// allocated. It is only necessary to call this method in rare cases, for
// example if you are using V8 from within the body of a static initializer.
......
......@@ -481,7 +481,6 @@ void ContextSwitcher::Run() {
// Acknowledge the preemption by the receiving thread.
void ContextSwitcher::PreemptionReceived() {
ASSERT(Locker::IsLocked(i::Isolate::GetDefaultIsolateForLocking()));
// There is currently no accounting being done for this. But could be in the
// future, which is why we leave this in.
}
......
......@@ -31,11 +31,12 @@
CcTest* CcTest::last_ = NULL;
CcTest::InitializationState CcTest::initialization_state_ = kUnset;
CcTest::CcTest(TestFunction* callback, const char* file, const char* name,
const char* dependency, bool enabled)
: callback_(callback), name_(name), dependency_(dependency), prev_(last_) {
const char* dependency, bool enabled, bool initialize)
: callback_(callback), name_(name), dependency_(dependency),
enabled_(enabled), initialize_(initialize), prev_(last_) {
// Find the base name of this test (const_cast required on Windows).
char *basename = strrchr(const_cast<char *>(file), '/');
if (!basename) {
......@@ -51,12 +52,35 @@ CcTest::CcTest(TestFunction* callback, const char* file, const char* name,
if (extension) *extension = 0;
// Install this test in the list of tests
file_ = basename;
enabled_ = enabled;
prev_ = last_;
last_ = this;
}
void CcTest::Run() {
if (!initialize_) {
CHECK(initialization_state_ != kInitialized);
initialization_state_ = kUnintialized;
// TODO(dcarney): Remove this when default isolate is gone.
if (default_isolate_ == NULL) {
default_isolate_ = v8::Isolate::GetCurrent();
}
} else {
CHECK(initialization_state_ != kUnintialized);
initialization_state_ = kInitialized;
i::Isolate::SetCrashIfDefaultIsolateInitialized();
if (default_isolate_ == NULL) {
default_isolate_ = v8::Isolate::New();
}
default_isolate_->Enter();
}
callback_();
if (initialize_) {
default_isolate_->Exit();
}
}
v8::Persistent<v8::Context> CcTest::context_;
......@@ -95,7 +119,7 @@ static void PrintTestList(CcTest* current) {
}
v8::Isolate* CcTest::default_isolate_;
v8::Isolate* CcTest::default_isolate_ = NULL;
class CcTestArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
......@@ -120,8 +144,6 @@ int main(int argc, char* argv[]) {
CcTestArrayBufferAllocator array_buffer_allocator;
v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
CcTest::set_default_isolate(v8::Isolate::GetCurrent());
CHECK(CcTest::default_isolate() != NULL);
int tests_run = 0;
bool print_run_count = true;
for (int i = 1; i < argc; i++) {
......
......@@ -31,23 +31,30 @@
#include "v8.h"
#ifndef TEST
#define TEST(Name) \
static void Test##Name(); \
CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, true); \
#define TEST(Name) \
static void Test##Name(); \
CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, true, true); \
static void Test##Name()
#endif
#ifndef UNINITIALIZED_TEST
#define UNINITIALIZED_TEST(Name) \
static void Test##Name(); \
CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, true, false); \
static void Test##Name()
#endif
#ifndef DEPENDENT_TEST
#define DEPENDENT_TEST(Name, Dep) \
static void Test##Name(); \
CcTest register_test_##Name(Test##Name, __FILE__, #Name, #Dep, true); \
#define DEPENDENT_TEST(Name, Dep) \
static void Test##Name(); \
CcTest register_test_##Name(Test##Name, __FILE__, #Name, #Dep, true, true); \
static void Test##Name()
#endif
#ifndef DISABLED_TEST
#define DISABLED_TEST(Name) \
static void Test##Name(); \
CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, false); \
#define DISABLED_TEST(Name) \
static void Test##Name(); \
CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, false, true); \
static void Test##Name()
#endif
......@@ -79,24 +86,26 @@ class CcTest {
public:
typedef void (TestFunction)();
CcTest(TestFunction* callback, const char* file, const char* name,
const char* dependency, bool enabled);
void Run() { callback_(); }
const char* dependency, bool enabled, bool initialize);
void Run();
static CcTest* last() { return last_; }
CcTest* prev() { return prev_; }
const char* file() { return file_; }
const char* name() { return name_; }
const char* dependency() { return dependency_; }
bool enabled() { return enabled_; }
static v8::Isolate* default_isolate() { return default_isolate_; }
static v8::Isolate* default_isolate() { return isolate(); }
static v8::Handle<v8::Context> env() {
return v8::Local<v8::Context>::New(default_isolate_, context_);
return v8::Local<v8::Context>::New(isolate(), context_);
}
static v8::Isolate* isolate() { return default_isolate_; }
static v8::Isolate* isolate() {
return default_isolate_;
}
static i::Isolate* i_isolate() {
return reinterpret_cast<i::Isolate*>(default_isolate_);
return reinterpret_cast<i::Isolate*>(isolate());
}
// Helper function to initialize the VM.
......@@ -104,17 +113,17 @@ class CcTest {
private:
friend int main(int argc, char** argv);
static void set_default_isolate(v8::Isolate* default_isolate) {
default_isolate_ = default_isolate;
}
TestFunction* callback_;
const char* file_;
const char* name_;
const char* dependency_;
bool enabled_;
bool initialize_;
CcTest* prev_;
static CcTest* last_;
static v8::Isolate* default_isolate_;
enum InitializationState {kUnset, kUnintialized, kInitialized};
static InitializationState initialization_state_;
static v8::Persistent<v8::Context> context_;
};
......
......@@ -12444,28 +12444,28 @@ void ApiTestFuzzer::TearDown() {
// Lets not be needlessly self-referential.
TEST(Threading1) {
UNINITIALIZED_TEST(Threading1) {
ApiTestFuzzer::SetUp(ApiTestFuzzer::FIRST_PART);
ApiTestFuzzer::RunAllTests();
ApiTestFuzzer::TearDown();
}
TEST(Threading2) {
UNINITIALIZED_TEST(Threading2) {
ApiTestFuzzer::SetUp(ApiTestFuzzer::SECOND_PART);
ApiTestFuzzer::RunAllTests();
ApiTestFuzzer::TearDown();
}
TEST(Threading3) {
UNINITIALIZED_TEST(Threading3) {
ApiTestFuzzer::SetUp(ApiTestFuzzer::THIRD_PART);
ApiTestFuzzer::RunAllTests();
ApiTestFuzzer::TearDown();
}
TEST(Threading4) {
UNINITIALIZED_TEST(Threading4) {
ApiTestFuzzer::SetUp(ApiTestFuzzer::FOURTH_PART);
ApiTestFuzzer::RunAllTests();
ApiTestFuzzer::TearDown();
......@@ -14312,7 +14312,7 @@ class RegExpInterruptTest {
// Test that a regular expression execution can be interrupted and
// survive a garbage collection.
TEST(RegExpInterruption) {
UNINITIALIZED_TEST(RegExpInterruption) {
v8::Locker lock(CcTest::default_isolate());
v8::V8::Initialize();
v8::HandleScope scope(CcTest::default_isolate());
......@@ -14420,7 +14420,7 @@ class ApplyInterruptTest {
// Test that nothing bad happens if we get a preemption just when we were
// about to do an apply().
TEST(ApplyInterruption) {
UNINITIALIZED_TEST(ApplyInterruption) {
v8::Locker lock(CcTest::default_isolate());
v8::V8::Initialize();
v8::HandleScope scope(CcTest::default_isolate());
......@@ -14737,7 +14737,7 @@ class RegExpStringModificationTest {
// Test that a regular expression execution can be interrupted and
// the string changed without failing.
TEST(RegExpStringModification) {
UNINITIALIZED_TEST(RegExpStringModification) {
v8::Locker lock(CcTest::default_isolate());
v8::V8::Initialize();
v8::HandleScope scope(CcTest::default_isolate());
......@@ -18197,14 +18197,6 @@ TEST(GCInFailedAccessCheckCallback) {
}
TEST(DefaultIsolateGetCurrent) {
CHECK(v8::Isolate::GetCurrent() != NULL);
v8::Isolate* isolate = v8::Isolate::GetCurrent();
CHECK(reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
printf("*** %s\n", "DefaultIsolateGetCurrent success");
}
TEST(IsolateNewDispose) {
v8::Isolate* current_isolate = v8::Isolate::GetCurrent();
v8::Isolate* isolate = v8::Isolate::New();
......@@ -18221,87 +18213,7 @@ TEST(IsolateNewDispose) {
}
TEST(IsolateEnterExitDefault) {
v8::Isolate* current_isolate = v8::Isolate::GetCurrent();
CHECK(current_isolate != NULL); // Default isolate.
v8::HandleScope scope(current_isolate);
LocalContext context;
ExpectString("'hello'", "hello");
current_isolate->Enter();
ExpectString("'still working'", "still working");
current_isolate->Exit();
ExpectString("'still working 2'", "still working 2");
current_isolate->Exit();
// Default isolate is always, well, 'default current'.
CHECK_EQ(v8::Isolate::GetCurrent(), current_isolate);
// Still working since default isolate is auto-entering any thread
// that has no isolate and attempts to execute V8 APIs.
ExpectString("'still working 3'", "still working 3");
}
TEST(DisposeDefaultIsolate) {
v8::V8::SetFatalErrorHandler(StoringErrorCallback);
// Run some V8 code to trigger default isolate to become 'current'.
v8::HandleScope scope(v8::Isolate::GetCurrent());
LocalContext context;
ExpectString("'run some V8'", "run some V8");
v8::Isolate* isolate = v8::Isolate::GetCurrent();
CHECK(reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
last_location = last_message = NULL;
isolate->Dispose();
// It is not possible to dispose default isolate via Isolate API.
CHECK_NE(last_location, NULL);
CHECK_NE(last_message, NULL);
}
TEST(RunDefaultAndAnotherIsolate) {
v8::HandleScope scope(v8::Isolate::GetCurrent());
LocalContext context;
// Enter new isolate.
v8::Isolate* isolate = v8::Isolate::New();
CHECK(isolate);
isolate->Enter();
{ // Need this block because subsequent Exit() will deallocate Heap,
// so we need all scope objects to be deconstructed when it happens.
v8::HandleScope scope_new(isolate);
LocalContext context_new;
// Run something in new isolate.
CompileRun("var foo = 153;");
ExpectTrue("function f() { return foo == 153; }; f()");
}
isolate->Exit();
// This runs automatically in default isolate.
// Variables in another isolate should be not available.
ExpectTrue("function f() {"
" try {"
" foo;"
" return false;"
" } catch(e) {"
" return true;"
" }"
"};"
"var bar = 371;"
"f()");
v8::V8::SetFatalErrorHandler(StoringErrorCallback);
last_location = last_message = NULL;
isolate->Dispose();
CHECK_EQ(last_location, NULL);
CHECK_EQ(last_message, NULL);
// Check that default isolate still runs.
ExpectTrue("function f() { return bar == 371; }; f()");
}
TEST(DisposeIsolateWhenInUse) {
UNINITIALIZED_TEST(DisposeIsolateWhenInUse) {
v8::Isolate* isolate = v8::Isolate::New();
CHECK(isolate);
isolate->Enter();
......@@ -18548,6 +18460,8 @@ class InitDefaultIsolateThread : public v8::internal::Thread {
result_(false) { }
void Run() {
v8::Isolate* isolate = v8::Isolate::New();
isolate->Enter();
switch (testCase_) {
case IgnoreOOM:
v8::V8::IgnoreOutOfMemoryException();
......@@ -18578,6 +18492,8 @@ class InitDefaultIsolateThread : public v8::internal::Thread {
v8::V8::SetAddHistogramSampleFunction(NULL);
break;
}
isolate->Exit();
isolate->Dispose();
result_ = true;
}
......@@ -19818,7 +19734,7 @@ TEST(StaticGetters) {
}
TEST(IsolateEmbedderData) {
UNINITIALIZED_TEST(IsolateEmbedderData) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
CHECK_EQ(NULL, isolate->GetData());
......
......@@ -396,26 +396,6 @@ TEST(DeleteCpuProfile) {
}
TEST(GetProfilerWhenIsolateIsNotInitialized) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
CHECK(i::Isolate::Current()->IsDefaultIsolate());
CHECK(!i::Isolate::Current()->IsInitialized());
CHECK_EQ(NULL, isolate->GetCpuProfiler());
{
v8::Isolate::Scope isolateScope(isolate);
LocalContext env;
v8::HandleScope scope(isolate);
CHECK_NE(NULL, isolate->GetCpuProfiler());
isolate->GetCpuProfiler()->StartCpuProfiling(v8::String::New("Test"));
isolate->GetCpuProfiler()->StopCpuProfiling(v8::String::New("Test"));
}
CHECK(i::Isolate::Current()->IsInitialized());
CHECK_NE(NULL, isolate->GetCpuProfiler());
isolate->Dispose();
CHECK_EQ(NULL, isolate->GetCpuProfiler());
}
TEST(ProfileStartEndTime) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
......
This diff is collapsed.
......@@ -635,7 +635,7 @@ class LockUnlockLockDefaultIsolateThread : public JoinableThread {
// Locker inside an Unlocker inside a Locker for default isolate.
TEST(LockUnlockLockDefaultIsolateMultithreaded) {
UNINITIALIZED_TEST(LockUnlockLockDefaultIsolateMultithreaded) {
#if V8_TARGET_ARCH_MIPS
const int kNThreads = 50;
#else
......
......@@ -325,7 +325,7 @@ static void ObjMethod1(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
TEST(LogCallbacks) {
UNINITIALIZED_TEST(LogCallbacks) {
ScopedLoggerInitializer initialize_logger;
Logger* logger = initialize_logger.logger();
......@@ -374,7 +374,7 @@ static void Prop2Getter(v8::Local<v8::String> property,
}
TEST(LogAccessorCallbacks) {
UNINITIALIZED_TEST(LogAccessorCallbacks) {
ScopedLoggerInitializer initialize_logger;
Logger* logger = initialize_logger.logger();
......
......@@ -403,7 +403,7 @@ static void ExpectError(const char* input,
}
TEST(Errors) {
UNINITIALIZED_TEST(Errors) {
V8::Initialize(NULL);
const char* kEndBackslash = "\\ at end of pattern";
ExpectError("\\", kEndBackslash);
......
......@@ -40,7 +40,7 @@ void Signal(const v8::FunctionCallbackInfo<v8::Value>& args) {
void TerminateCurrentThread(const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK(!v8::V8::IsExecutionTerminating());
v8::V8::TerminateExecution();
v8::V8::TerminateExecution(args.GetIsolate());
}
......@@ -231,7 +231,7 @@ void LoopGetProperty(const v8::FunctionCallbackInfo<v8::Value>& args) {
// Test that we correctly handle termination exceptions if they are
// triggered by the creation of error objects in connection with ICs.
TEST(TerminateLoadICException) {
UNINITIALIZED_TEST(TerminateLoadICException) {
v8::HandleScope scope(v8::Isolate::GetCurrent());
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
global->Set(v8::String::New("terminate_or_return_object"),
......
......@@ -129,7 +129,7 @@ class ThreadB : public v8::internal::Thread {
};
TEST(JSFunctionResultCachesInTwoThreads) {
UNINITIALIZED_TEST(JSFunctionResultCachesInTwoThreads) {
v8::V8::Initialize();
ThreadA threadA;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment