Commit 963a75cc authored by vitalyr@chromium.org's avatar vitalyr@chromium.org

Fast TLS support.

This patch adds common infrastructure for fast TLS support and
implementation on win32. More implementations will be added soon.

Fast TLS is controlled by V8_FAST_TLS define which is enabled by
default in our gyp and scons builds. The scons build has
fasttls={on,off} option so that we can see the effects of slow TLS
when needed.

Review URL: http://codereview.chromium.org/6696112

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7375 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent b675cfec
......@@ -128,6 +128,9 @@ LIBRARY_FLAGS = {
'inspector:on': {
'CPPDEFINES': ['INSPECTOR'],
},
'fasttls:on': {
'CPPDEFINES': ['V8_FAST_TLS'],
},
'liveobjectlist:on': {
'CPPDEFINES': ['ENABLE_DEBUGGER_SUPPORT', 'INSPECTOR',
'LIVE_OBJECT_LIST', 'OBJECT_PRINT'],
......@@ -785,6 +788,12 @@ SIMPLE_OPTIONS = {
'default': 'off',
'help': 'enable the disassembler to inspect generated code'
},
'fasttls': {
'values': ['on', 'off'],
'default': 'on',
'help': 'enable fast thread local storage support '
'(if available on the current architecture/platform)'
},
'sourcesignatures': {
'values': ['MD5', 'timestamp'],
'default': 'MD5',
......
......@@ -402,7 +402,8 @@ class Isolate {
// Returns the isolate inside which the current thread is running.
INLINE(static Isolate* Current()) {
Isolate* isolate = UncheckedCurrent();
Isolate* isolate = reinterpret_cast<Isolate*>(
Thread::GetExistingThreadLocal(isolate_key_));
ASSERT(isolate != NULL);
return isolate;
}
......
......@@ -114,6 +114,7 @@ int signbit(double x);
#endif // __GNUC__
#include "atomicops.h"
#include "platform-tls.h"
#include "utils.h"
#include "v8globals.h"
......@@ -428,6 +429,19 @@ class Thread: public ThreadHandle {
return GetThreadLocal(key) != NULL;
}
#ifdef V8_FAST_TLS_SUPPORTED
static inline void* GetExistingThreadLocal(LocalStorageKey key) {
void* result = reinterpret_cast<void*>(
InternalGetExistingThreadLocal(static_cast<intptr_t>(key)));
ASSERT(result == GetThreadLocal(key));
return result;
}
#else
static inline void* GetExistingThreadLocal(LocalStorageKey key) {
return GetThreadLocal(key);
}
#endif
// A hint to the scheduler to let another thread run.
static void YieldCPU();
......
......@@ -5230,8 +5230,9 @@ static MaybeObject* QuoteJsonString(Isolate* isolate,
int final_length = static_cast<int>(
write_cursor - reinterpret_cast<Char*>(
new_string->address() + SeqAsciiString::kHeaderSize));
isolate->heap()->new_space()->ShrinkStringAtAllocationBoundary<StringType>(
new_string, final_length);
isolate->heap()->new_space()->
template ShrinkStringAtAllocationBoundary<StringType>(
new_string, final_length);
return new_string;
}
......
......@@ -41,8 +41,8 @@ SOURCES = {
'test-alloc.cc',
'test-api.cc',
'test-ast.cc',
'test-bignum.cc',
'test-bignum-dtoa.cc',
'test-bignum.cc',
'test-circular-queue.cc',
'test-compiler.cc',
'test-conversions.cc',
......@@ -59,15 +59,16 @@ SOURCES = {
'test-flags.cc',
'test-func-name-inference.cc',
'test-hashmap.cc',
'test-heap.cc',
'test-heap-profiler.cc',
'test-heap.cc',
'test-list.cc',
'test-liveedit.cc',
'test-lock.cc',
'test-log.cc',
'test-log-utils.cc',
'test-log.cc',
'test-mark-compact.cc',
'test-parsing.cc',
'test-platform-tls.cc',
'test-profile-generator.cc',
'test-regexp.cc',
'test-reloc-info.cc',
......
// 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(NULL, "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();
}
......@@ -41,6 +41,7 @@
'ENABLE_LOGGING_AND_PROFILING',
'ENABLE_DEBUGGER_SUPPORT',
'ENABLE_VMSTATE_TRACKING',
'V8_FAST_TLS',
],
'conditions': [
['OS!="mac"', {
......@@ -437,6 +438,8 @@
'../../src/objects.h',
'../../src/parser.cc',
'../../src/parser.h',
'../../src/platform-tls-win32.h',
'../../src/platform-tls.h',
'../../src/platform.h',
'../../src/preparse-data.cc',
'../../src/preparse-data.h',
......
......@@ -915,6 +915,7 @@
89FB0E360F8E531900B04B3C /* d8-posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "d8-posix.cc"; path = "../src/d8-posix.cc"; sourceTree = "<group>"; };
89FB0E370F8E531900B04B3C /* d8-windows.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "d8-windows.cc"; path = "../src/d8-windows.cc"; sourceTree = "<group>"; };
9C1F8E1D133906180068B362 /* small-pointer-list.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "small-pointer-list.h"; sourceTree = "<group>"; };
9C8E8061133CF772004058A5 /* platform-tls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "platform-tls.h"; sourceTree = "<group>"; };
9F11D99E105AF0A300EBE5B2 /* heap-profiler.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "heap-profiler.cc"; sourceTree = "<group>"; };
9F11D99F105AF0A300EBE5B2 /* heap-profiler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "heap-profiler.h"; sourceTree = "<group>"; };
9F2B370E114FF62D007CDAF4 /* circular-queue-inl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "circular-queue-inl.h"; sourceTree = "<group>"; };
......@@ -1238,6 +1239,7 @@
897FF1670E719B8F00D62E90 /* platform-macos.cc */,
897FF1680E719B8F00D62E90 /* platform-nullos.cc */,
893A72230F7B0FF200303DD2 /* platform-posix.cc */,
9C8E8061133CF772004058A5 /* platform-tls.h */,
897FF1690E719B8F00D62E90 /* platform-win32.cc */,
897FF16A0E719B8F00D62E90 /* platform.h */,
893E249512B14B3D0083370F /* preparse-data.cc */,
......
......@@ -869,6 +869,14 @@
RelativePath="..\..\src\profile-generator-inl.h"
>
</File>
<File
RelativePath="..\..\src\platform-tls-win32.h"
>
</File>
<File
RelativePath="..\..\src\platform-tls.h"
>
</File>
<File
RelativePath="..\..\src\platform-win32.cc"
>
......
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