508b22c436
Thread class was receiving an isolate parameter by default. This approact violates the assumption that only VM threads can have an associated isolate, and can lead to troubles, because accessing the same isolate from different threads leads to race conditions. This was found by investigating mysterious failures of the CPU profiler layout test on Linux Chromium. As almost all threads were associated with some isolate, the sampler was trying to sample them. As a side effect, we have also fixed the DebuggerAgent test. Thanks to Vitaly for help in fixing isolates handling! R=vitalyr@chromium.org BUG=none TEST=none git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8259 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
// Copyright 2011 the V8 project authors. All rights reserved.
|
|
//
|
|
// Tests of fast TLS support.
|
|
|
|
#include "v8.h"
|
|
|
|
#include "cctest.h"
|
|
#include "checks.h"
|
|
#include "platform.h"
|
|
|
|
using v8::internal::Thread;
|
|
|
|
static const int kValueCount = 128;
|
|
|
|
static Thread::LocalStorageKey keys[kValueCount];
|
|
|
|
static void* GetValue(int num) {
|
|
return reinterpret_cast<void*>(static_cast<intptr_t>(num + 1));
|
|
}
|
|
|
|
static void DoTest() {
|
|
for (int i = 0; i < kValueCount; i++) {
|
|
CHECK(!Thread::HasThreadLocal(keys[i]));
|
|
}
|
|
for (int i = 0; i < kValueCount; i++) {
|
|
Thread::SetThreadLocal(keys[i], GetValue(i));
|
|
}
|
|
for (int i = 0; i < kValueCount; i++) {
|
|
CHECK(Thread::HasThreadLocal(keys[i]));
|
|
}
|
|
for (int i = 0; i < kValueCount; i++) {
|
|
CHECK_EQ(GetValue(i), Thread::GetThreadLocal(keys[i]));
|
|
CHECK_EQ(GetValue(i), Thread::GetExistingThreadLocal(keys[i]));
|
|
}
|
|
for (int i = 0; i < kValueCount; i++) {
|
|
Thread::SetThreadLocal(keys[i], GetValue(kValueCount - i - 1));
|
|
}
|
|
for (int i = 0; i < kValueCount; i++) {
|
|
CHECK(Thread::HasThreadLocal(keys[i]));
|
|
}
|
|
for (int i = 0; i < kValueCount; i++) {
|
|
CHECK_EQ(GetValue(kValueCount - i - 1),
|
|
Thread::GetThreadLocal(keys[i]));
|
|
CHECK_EQ(GetValue(kValueCount - i - 1),
|
|
Thread::GetExistingThreadLocal(keys[i]));
|
|
}
|
|
}
|
|
|
|
class TestThread : public Thread {
|
|
public:
|
|
TestThread() : Thread("TestThread") {}
|
|
|
|
virtual void Run() {
|
|
DoTest();
|
|
}
|
|
};
|
|
|
|
TEST(FastTLS) {
|
|
for (int i = 0; i < kValueCount; i++) {
|
|
keys[i] = Thread::CreateThreadLocalKey();
|
|
}
|
|
DoTest();
|
|
TestThread thread;
|
|
thread.Start();
|
|
thread.Join();
|
|
}
|