Revision: 4866
Author: lukezarko
Date: Tue Jun 15 09:28:35 2010
Log: [Isolates] Begin removing [static] from Top.
- Moved Top::thread_local to Isolate.
- Identified globals in top.cc and moved these into TopState.
It seems like the methods on Top should migrate to Isolate and that Top
itself
should disappear; WDYT?
Review URL: http://codereview.chromium.org/2720005
http://code.google.com/p/v8/source/detail?r=4866
Modified:
/branches/experimental/isolates/src/builtins.cc
/branches/experimental/isolates/src/frames.cc
/branches/experimental/isolates/src/ic.cc
/branches/experimental/isolates/src/isolate.h
/branches/experimental/isolates/src/log.cc
/branches/experimental/isolates/src/top.cc
/branches/experimental/isolates/src/top.h
/branches/experimental/isolates/test/cctest/test-log-stack-tracer.cc
=======================================
--- /branches/experimental/isolates/src/builtins.cc Thu Jun 10 10:14:01 2010
+++ /branches/experimental/isolates/src/builtins.cc Tue Jun 15 09:28:35 2010
@@ -148,7 +148,7 @@
StackFrame* frame = it.frame();
bool reference_result = frame->is_construct();
#endif
- Address fp = Top::c_entry_fp(Top::GetCurrentThread());
+ Address fp = Top::c_entry_fp(Isolate::Current()->thread_local_top());
// Because we know fp points to an exit frame we can use the relevant
// part of ExitFrame::ComputeCallerState directly.
const int kCallerOffset = ExitFrameConstants::kCallerFPOffset;
=======================================
--- /branches/experimental/isolates/src/frames.cc Tue Jun 1 03:51:42 2010
+++ /branches/experimental/isolates/src/frames.cc Tue Jun 15 09:28:35 2010
@@ -68,7 +68,8 @@
#define INITIALIZE_SINGLETON(type, field) field##_(this),
StackFrameIterator::StackFrameIterator()
: STACK_FRAME_TYPE_LIST(INITIALIZE_SINGLETON)
- frame_(NULL), handler_(NULL), thread_(Top::GetCurrentThread()),
+ frame_(NULL), handler_(NULL),
+ thread_(Isolate::Current()->thread_local_top()),
fp_(NULL), sp_(NULL),
advance_(&StackFrameIterator::AdvanceWithHandler) {
Reset();
}
@@ -81,7 +82,7 @@
StackFrameIterator::StackFrameIterator(bool use_top, Address fp, Address
sp)
: STACK_FRAME_TYPE_LIST(INITIALIZE_SINGLETON)
frame_(NULL), handler_(NULL),
- thread_(use_top ? Top::GetCurrentThread() : NULL),
+ thread_(use_top ? Isolate::Current()->thread_local_top() : NULL),
fp_(use_top ? NULL : fp), sp_(sp),
advance_(use_top ? &StackFrameIterator::AdvanceWithHandler :
&StackFrameIterator::AdvanceWithoutHandler) {
@@ -204,8 +205,8 @@
low_bound_(low_bound), high_bound_(high_bound),
is_valid_top_(
IsWithinBounds(low_bound, high_bound,
- Top::c_entry_fp(Top::GetCurrentThread())) &&
- Top::handler(Top::GetCurrentThread()) != NULL),
+
Top::c_entry_fp(Isolate::Current()->thread_local_top()))
+ && Top::handler(Isolate::Current()->thread_local_top()) != NULL),
is_valid_fp_(IsWithinBounds(low_bound, high_bound, fp)),
is_working_iterator_(is_valid_top_ || is_valid_fp_),
iteration_done_(!is_working_iterator_),
=======================================
--- /branches/experimental/isolates/src/ic.cc Thu Jun 10 08:41:41 2010
+++ /branches/experimental/isolates/src/ic.cc Tue Jun 15 09:28:35 2010
@@ -81,7 +81,7 @@
// To improve the performance of the (much used) IC code, we unfold
// a few levels of the stack frame iteration code. This yields a
// ~35% speedup when running DeltaBlue with the '--nouse-ic' flag.
- const Address entry = Top::c_entry_fp(Top::GetCurrentThread());
+ const Address entry =
Top::c_entry_fp(Isolate::Current()->thread_local_top());
Address* pc_address =
reinterpret_cast<Address*>(entry +
ExitFrameConstants::kCallerPCOffset);
Address fp = Memory::Address_at(entry +
ExitFrameConstants::kCallerFPOffset);
=======================================
--- /branches/experimental/isolates/src/isolate.h Thu Jun 10 11:15:06 2010
+++ /branches/experimental/isolates/src/isolate.h Tue Jun 15 09:28:35 2010
@@ -39,8 +39,85 @@
class Bootstrapper;
class Deserializer;
class HandleScopeImplementer;
+class SaveContext;
class StubCache;
+class ThreadLocalTop BASE_EMBEDDED {
+ public:
+ // Initialize the thread data.
+ void Initialize();
+
+ // Get the top C++ try catch handler or NULL if none are registered.
+ //
+ // This method is not guarenteed to return an address that can be
+ // used for comparison with addresses into the JS stack. If such an
+ // address is needed, use try_catch_handler_address.
+ v8::TryCatch* TryCatchHandler();
+
+ // Get the address of the top C++ try catch handler or NULL if
+ // none are registered.
+ //
+ // This method always returns an address that can be compared to
+ // pointers into the JavaScript stack. When running on actual
+ // hardware, try_catch_handler_address and TryCatchHandler return
+ // the same pointer. When running on a simulator with a separate JS
+ // stack, try_catch_handler_address returns a JS stack address that
+ // corresponds to the place on the JS stack where the C++ handler
+ // would have been if the stack were not separate.
+ inline Address try_catch_handler_address() {
+ return try_catch_handler_address_;
+ }
+
+ // Set the address of the top C++ try catch handler.
+ inline void set_try_catch_handler_address(Address address) {
+ try_catch_handler_address_ = address;
+ }
+
+ void Free() {
+ ASSERT(!has_pending_message_);
+ ASSERT(!external_caught_exception_);
+ ASSERT(try_catch_handler_address_ == NULL);
+ }
+
+ // The context where the current execution method is created and for
variable
+ // lookups.
+ Context* context_;
+ int thread_id_;
+ Object* pending_exception_;
+ bool has_pending_message_;
+ const char* pending_message_;
+ Object* pending_message_obj_;
+ Script* pending_message_script_;
+ int pending_message_start_pos_;
+ int pending_message_end_pos_;
+ // Use a separate value for scheduled exceptions to preserve the
+ // invariants that hold about pending_exception. We may want to
+ // unify them later.
+ Object* scheduled_exception_;
+ bool external_caught_exception_;
+ SaveContext* save_context_;
+ v8::TryCatch* catcher_;
+
+ // Stack.
+ Address c_entry_fp_; // the frame pointer of the top c entry frame
+ Address handler_; // try-blocks are chained through the stack
+#ifdef ENABLE_LOGGING_AND_PROFILING
+ Address js_entry_sp_; // the stack pointer of the bottom js entry frame
+#endif
+ bool stack_is_cooked_;
+ inline bool stack_is_cooked() { return stack_is_cooked_; }
+ inline void set_stack_is_cooked(bool value) { stack_is_cooked_ = value; }
+
+ // Generated code scratch locations.
+ int32_t formal_count_;
+
+ // Call back function to report unsafe JS accesses.
+ v8::FailedAccessCheckCallback failed_access_check_callback_;
+
+ private:
+ Address try_catch_handler_address_;
+};
+
#define
ISOLATE_INIT_ARRAY_LIST(V) \
/* SerializerDeserializer state.
*/ \
V(Object*, serialize_partial_snapshot_cache,
kPartialSnapshotCacheCapacity)
@@ -85,6 +162,7 @@
StackGuard* stack_guard() { return &stack_guard_; }
Heap* heap() { return &heap_; }
StubCache* stub_cache() { return stub_cache_; }
+ ThreadLocalTop* thread_local_top() { return &thread_local_top_; }
TranscendentalCache* transcendental_cache() const {
return transcendental_cache_;
@@ -131,6 +209,7 @@
Heap heap_;
StackGuard stack_guard_;
StubCache* stub_cache_;
+ ThreadLocalTop thread_local_top_;
TranscendentalCache* transcendental_cache_;
v8::ImplementationUtilities::HandleScopeData handle_scope_data_;
HandleScopeImplementer* handle_scope_implementer_;
=======================================
--- /branches/experimental/isolates/src/log.cc Wed Jun 9 16:02:44 2010
+++ /branches/experimental/isolates/src/log.cc Tue Jun 15 09:28:35 2010
@@ -148,7 +148,8 @@
if (sample->state == GC) return;
- const Address js_entry_sp = Top::js_entry_sp(Top::GetCurrentThread());
+ const Address js_entry_sp = Top::js_entry_sp(
+ Isolate::Current()->thread_local_top());
if (js_entry_sp == 0) {
// Not executing JS now.
return;
=======================================
--- /branches/experimental/isolates/src/top.cc Thu Jun 10 08:41:41 2010
+++ /branches/experimental/isolates/src/top.cc Tue Jun 15 09:28:35 2010
@@ -39,19 +39,41 @@
namespace v8 {
namespace internal {
-ThreadLocalTop Top::thread_local_;
-
-NoAllocationStringAllocator* preallocated_message_space = NULL;
-
-Address top_addresses[] = {
-#define C(name) reinterpret_cast<Address>(Top::name()),
- TOP_ADDRESS_LIST(C)
- TOP_ADDRESS_LIST_PROF(C)
+class PreallocatedMemoryThread;
+
+class TopState {
+ public:
+ TopState()
+ : preallocated_message_space_(NULL),
+ initialized_(false),
+ stack_trace_nesting_level_(0),
+ incomplete_message_(NULL),
+ preallocated_memory_thread_(NULL) {
+#define C(name) top_addresses_[Top::k_##name]
= \
+ reinterpret_cast<Address>(Top::name());
+ TOP_ADDRESS_LIST(C)
+ TOP_ADDRESS_LIST_PROF(C)
#undef C
- NULL
+ top_addresses_[Top::k_top_address_count] = NULL;
+ }
+
+ inline void PreallocatedMemoryThreadStart();
+ inline void PreallocatedMemoryThreadStop();
+
+ NoAllocationStringAllocator* preallocated_message_space_;
+ bool initialized_;
+ int stack_trace_nesting_level_;
+ StringStream* incomplete_message_;
+ // The preallocated memory thread singleton.
+ PreallocatedMemoryThread* preallocated_memory_thread_;
+ Address top_addresses_[Top::k_top_address_count + 1];
};
+// TODO(isolates): We will be moving this to Isolate ASAP.
+static TopState top_state;
+
+
v8::TryCatch* ThreadLocalTop::TryCatchHandler() {
return TRY_CATCH_FROM_ADDRESS(try_catch_handler_address());
}
@@ -76,7 +98,7 @@
Address Top::get_address_from_id(Top::AddressId id) {
- return top_addresses[id];
+ return top_state.top_addresses_[id];
}
@@ -88,7 +110,7 @@
void Top::IterateThread(ThreadVisitor* v) {
- v->VisitThread(&thread_local_);
+ v->VisitThread(thread_local());
}
@@ -121,13 +143,13 @@
void Top::Iterate(ObjectVisitor* v) {
- ThreadLocalTop* current_t = &thread_local_;
+ ThreadLocalTop* current_t = thread_local();
Iterate(v, current_t);
}
void Top::InitializeThreadLocal() {
- thread_local_.Initialize();
+ thread_local()->Initialize();
clear_pending_exception();
clear_pending_message();
clear_scheduled_exception();
@@ -139,37 +161,7 @@
// into for use by a stacks only core dump (aka minidump).
class PreallocatedMemoryThread: public Thread {
public:
- PreallocatedMemoryThread() : keep_running_(true) {
- wait_for_ever_semaphore_ = OS::CreateSemaphore(0);
- data_ready_semaphore_ = OS::CreateSemaphore(0);
- }
-
- // When the thread starts running it will allocate a fixed number of
bytes
- // on the stack and publish the location of this memory for others to
use.
- void Run() {
- EmbeddedVector<char, 15 * 1024> local_buffer;
-
- // Initialize the buffer with a known good value.
- OS::StrNCpy(local_buffer, "Trace data was not generated.\n",
- local_buffer.length());
-
- // Publish the local buffer and signal its availability.
- data_ = local_buffer.start();
- length_ = local_buffer.length();
- data_ready_semaphore_->Signal();
-
- while (keep_running_) {
- // This thread will wait here until the end of time.
- wait_for_ever_semaphore_->Wait();
- }
-
- // Make sure we access the buffer after the wait to remove all
possibility
- // of it being optimized away.
- OS::StrNCpy(local_buffer, "PreallocatedMemoryThread shutting down.\n",
- local_buffer.length());
- }
-
- static char* data() {
+ char* data() {
if (data_ready_semaphore_ != NULL) {
// Initial access is guarded until the data has been published.
data_ready_semaphore_->Wait();
@@ -179,7 +171,7 @@
return data_;
}
- static unsigned length() {
+ unsigned length() {
if (data_ready_semaphore_ != NULL) {
// Initial access is guarded until the data has been published.
data_ready_semaphore_->Wait();
@@ -188,23 +180,14 @@
}
return length_;
}
-
- static void StartThread() {
- if (the_thread_ != NULL) return;
-
- the_thread_ = new PreallocatedMemoryThread();
- the_thread_->Start();
- }
// Stop the PreallocatedMemoryThread and release its resources.
- static void StopThread() {
- if (the_thread_ == NULL) return;
-
- the_thread_->keep_running_ = false;
+ void StopThread() {
+ keep_running_ = false;
wait_for_ever_semaphore_->Signal();
// Wait for the thread to terminate.
- the_thread_->Join();
+ Join();
if (data_ready_semaphore_ != NULL) {
delete data_ready_semaphore_;
@@ -213,66 +196,109 @@
delete wait_for_ever_semaphore_;
wait_for_ever_semaphore_ = NULL;
-
- // Done with the thread entirely.
- delete the_thread_;
- the_thread_ = NULL;
- }
+ }
+
+ protected:
+ // When the thread starts running it will allocate a fixed number of
bytes
+ // on the stack and publish the location of this memory for others to
use.
+ void Run() {
+ EmbeddedVector<char, 15 * 1024> local_buffer;
+
+ // Initialize the buffer with a known good value.
+ OS::StrNCpy(local_buffer, "Trace data was not generated.\n",
+ local_buffer.length());
+
+ // Publish the local buffer and signal its availability.
+ data_ = local_buffer.start();
+ length_ = local_buffer.length();
+ data_ready_semaphore_->Signal();
+
+ while (keep_running_) {
+ // This thread will wait here until the end of time.
+ wait_for_ever_semaphore_->Wait();
+ }
+
+ // Make sure we access the buffer after the wait to remove all
possibility
+ // of it being optimized away.
+ OS::StrNCpy(local_buffer, "PreallocatedMemoryThread shutting down.\n",
+ local_buffer.length());
+ }
+
private:
+ PreallocatedMemoryThread()
+ : keep_running_(true),
+ wait_for_ever_semaphore_(OS::CreateSemaphore(0)),
+ data_ready_semaphore_(OS::CreateSemaphore(0)),
+ data_(NULL),
+ length_(0) {
+ }
+
// Used to make sure that the thread keeps looping even for spurious
wakeups.
bool keep_running_;
- // The preallocated memory thread singleton.
- static PreallocatedMemoryThread* the_thread_;
// This semaphore is used by the PreallocatedMemoryThread to wait for
ever.
- static Semaphore* wait_for_ever_semaphore_;
+ Semaphore* wait_for_ever_semaphore_;
// Semaphore to signal that the data has been initialized.
- static Semaphore* data_ready_semaphore_;
+ Semaphore* data_ready_semaphore_;
// Location and size of the preallocated memory block.
- static char* data_;
- static unsigned length_;
+ char* data_;
+ unsigned length_;
+
+ friend class TopState;
DISALLOW_COPY_AND_ASSIGN(PreallocatedMemoryThread);
};
-PreallocatedMemoryThread* PreallocatedMemoryThread::the_thread_ = NULL;
-Semaphore* PreallocatedMemoryThread::wait_for_ever_semaphore_ = NULL;
-Semaphore* PreallocatedMemoryThread::data_ready_semaphore_ = NULL;
-char* PreallocatedMemoryThread::data_ = NULL;
-unsigned PreallocatedMemoryThread::length_ = 0;
-
-static bool initialized = false;
+
+void TopState::PreallocatedMemoryThreadStart() {
+ if (preallocated_memory_thread_ != NULL) return;
+ preallocated_memory_thread_ = new PreallocatedMemoryThread();
+ preallocated_memory_thread_->Start();
+}
+
+
+void TopState::PreallocatedMemoryThreadStop() {
+ if (preallocated_memory_thread_ == NULL) return;
+ preallocated_memory_thread_->StopThread();
+ // Done with the thread entirely.
+ delete preallocated_memory_thread_;
+ preallocated_memory_thread_ = NULL;
+}
+
void Top::Initialize() {
- CHECK(!initialized);
+ CHECK(!top_state.initialized_);
InitializeThreadLocal();
// Only preallocate on the first initialization.
- if (FLAG_preallocate_message_memory && (preallocated_message_space ==
NULL)) {
+ if (FLAG_preallocate_message_memory &&
+ (top_state.preallocated_message_space_ == NULL)) {
// Start the thread which will set aside some memory.
- PreallocatedMemoryThread::StartThread();
- preallocated_message_space =
- new NoAllocationStringAllocator(PreallocatedMemoryThread::data(),
-
PreallocatedMemoryThread::length());
- PreallocatedStorage::Init(PreallocatedMemoryThread::length() / 4);
- }
- initialized = true;
+ top_state.PreallocatedMemoryThreadStart();
+ top_state.preallocated_message_space_ =
+ new NoAllocationStringAllocator(
+ top_state.preallocated_memory_thread_->data(),
+ top_state.preallocated_memory_thread_->length());
+ PreallocatedStorage::Init(
+ top_state.preallocated_memory_thread_->length() / 4);
+ }
+ top_state.initialized_ = true;
}
void Top::TearDown() {
- if (initialized) {
+ if (top_state.initialized_) {
// Remove the external reference to the preallocated stack memory.
- if (preallocated_message_space != NULL) {
- delete preallocated_message_space;
- preallocated_message_space = NULL;
+ if (top_state.preallocated_message_space_ != NULL) {
+ delete top_state.preallocated_message_space_;
+ top_state.preallocated_message_space_ = NULL;
}
- PreallocatedMemoryThread::StopThread();
- initialized = false;
+ top_state.PreallocatedMemoryThreadStop();
+ top_state.initialized_ = false;
}
}
@@ -285,21 +311,21 @@
// returned will be the address of the C++ try catch handler itself.
Address address = reinterpret_cast<Address>(
SimulatorStack::RegisterCTryCatch(reinterpret_cast<uintptr_t>(that)));
- thread_local_.set_try_catch_handler_address(address);
+ thread_local()->set_try_catch_handler_address(address);
}
void Top::UnregisterTryCatchHandler(v8::TryCatch* that) {
- ASSERT(thread_local_.TryCatchHandler() == that);
- thread_local_.set_try_catch_handler_address(
+ ASSERT(thread_local()->TryCatchHandler() == that);
+ thread_local()->set_try_catch_handler_address(
reinterpret_cast<Address>(that->next_));
- thread_local_.catcher_ = NULL;
+ thread_local()->catcher_ = NULL;
SimulatorStack::UnregisterCTryCatch();
}
void Top::MarkCompactPrologue(bool is_compacting) {
- MarkCompactPrologue(is_compacting, &thread_local_);
+ MarkCompactPrologue(is_compacting, thread_local());
}
@@ -321,7 +347,7 @@
void Top::MarkCompactEpilogue(bool is_compacting) {
- MarkCompactEpilogue(is_compacting, &thread_local_);
+ MarkCompactEpilogue(is_compacting, thread_local());
}
@@ -330,31 +356,27 @@
StackFrame::UncookFramesForThread(thread);
}
}
-
-
-static int stack_trace_nesting_level = 0;
-static StringStream* incomplete_message = NULL;
Handle<String> Top::StackTraceString() {
- if (stack_trace_nesting_level == 0) {
- stack_trace_nesting_level++;
+ if (top_state.stack_trace_nesting_level_ == 0) {
+ top_state.stack_trace_nesting_level_++;
HeapStringAllocator allocator;
StringStream::ClearMentionedObjectCache();
StringStream accumulator(&allocator);
- incomplete_message = &accumulator;
+ top_state.incomplete_message_ = &accumulator;
PrintStack(&accumulator);
Handle<String> stack_trace = accumulator.ToString();
- incomplete_message = NULL;
- stack_trace_nesting_level = 0;
+ top_state.incomplete_message_ = NULL;
+ top_state.stack_trace_nesting_level_ = 0;
return stack_trace;
- } else if (stack_trace_nesting_level == 1) {
- stack_trace_nesting_level++;
+ } else if (top_state.stack_trace_nesting_level_ == 1) {
+ top_state.stack_trace_nesting_level_++;
OS::PrintError(
"\n\nAttempt to print stack while printing stack (double fault)\n");
OS::PrintError(
"If you are lucky you may find a partial stack dump on stdout.\n\n");
- incomplete_message->OutputToStdOut();
+ top_state.incomplete_message_->OutputToStdOut();
return Factory::empty_symbol();
} else {
OS::Abort();
@@ -447,14 +469,14 @@
void Top::PrintStack() {
- if (stack_trace_nesting_level == 0) {
- stack_trace_nesting_level++;
+ if (top_state.stack_trace_nesting_level_ == 0) {
+ top_state.stack_trace_nesting_level_++;
StringAllocator* allocator;
- if (preallocated_message_space == NULL) {
+ if (top_state.preallocated_message_space_ == NULL) {
allocator = new HeapStringAllocator();
} else {
- allocator = preallocated_message_space;
+ allocator = top_state.preallocated_message_space_;
}
NativeAllocationChecker allocation_checker(
@@ -464,23 +486,23 @@
StringStream::ClearMentionedObjectCache();
StringStream accumulator(allocator);
- incomplete_message = &accumulator;
+ top_state.incomplete_message_ = &accumulator;
PrintStack(&accumulator);
accumulator.OutputToStdOut();
accumulator.Log();
- incomplete_message = NULL;
- stack_trace_nesting_level = 0;
- if (preallocated_message_space == NULL) {
+ top_state.incomplete_message_ = NULL;
+ top_state.stack_trace_nesting_level_ = 0;
+ if (top_state.preallocated_message_space_ == NULL) {
// Remove the HeapStringAllocator created above.
delete allocator;
}
- } else if (stack_trace_nesting_level == 1) {
- stack_trace_nesting_level++;
+ } else if (top_state.stack_trace_nesting_level_ == 1) {
+ top_state.stack_trace_nesting_level_++;
OS::PrintError(
"\n\nAttempt to print stack while printing stack (double fault)\n");
OS::PrintError(
"If you are lucky you may find a partial stack dump on stdout.\n\n");
- incomplete_message->OutputToStdOut();
+ top_state.incomplete_message_->OutputToStdOut();
}
}
@@ -500,7 +522,7 @@
ASSERT(StringStream::IsMentionedObjectCacheClear());
// Avoid printing anything if there are no frames.
- if (c_entry_fp(GetCurrentThread()) == 0) return;
+ if (c_entry_fp(thread_local()) == 0) return;
accumulator->Add(
"\n==== Stack trace
============================================\n\n");
@@ -516,13 +538,13 @@
void Top::SetFailedAccessCheckCallback(v8::FailedAccessCheckCallback
callback) {
- ASSERT(thread_local_.failed_access_check_callback_ == NULL);
- thread_local_.failed_access_check_callback_ = callback;
+ ASSERT(thread_local()->failed_access_check_callback_ == NULL);
+ thread_local()->failed_access_check_callback_ = callback;
}
void Top::ReportFailedAccessCheck(JSObject* receiver, v8::AccessType type)
{
- if (!thread_local_.failed_access_check_callback_) return;
+ if (!thread_local()->failed_access_check_callback_) return;
ASSERT(receiver->IsAccessCheckNeeded());
ASSERT(Top::context());
@@ -539,7 +561,7 @@
HandleScope scope;
Handle<JSObject> receiver_handle(receiver);
Handle<Object> data(AccessCheckInfo::cast(data_obj)->data());
- thread_local_.failed_access_check_callback_(
+ thread_local()->failed_access_check_callback_(
v8::Utils::ToLocal(receiver_handle),
type,
v8::Utils::ToLocal(data));
@@ -717,8 +739,8 @@
// When scheduling a throw we first throw the exception to get the
// error reporting if it is uncaught before rescheduling it.
Throw(exception);
- thread_local_.scheduled_exception_ = pending_exception();
- thread_local_.external_caught_exception_ = false;
+ thread_local()->scheduled_exception_ = pending_exception();
+ thread_local()->external_caught_exception_ = false;
clear_pending_exception();
}
@@ -800,14 +822,15 @@
bool catchable_by_javascript) {
// Find the top-most try-catch handler.
StackHandler* handler =
- StackHandler::FromAddress(Top::handler(Top::GetCurrentThread()));
+ StackHandler::FromAddress(Top::handler(thread_local()));
while (handler != NULL && !handler->is_try_catch()) {
handler = handler->next();
}
// Get the address of the external handler so we can compare the address
to
// determine which one is closer to the top of the stack.
- Address external_handler_address =
thread_local_.try_catch_handler_address();
+ Address external_handler_address =
+ thread_local()->try_catch_handler_address();
// The exception has been externally caught if and only if there is
// an external handler which is on top of the top-most try-catch
@@ -818,7 +841,7 @@
if (*is_caught_externally) {
// Only report the exception if the external handler is verbose.
- return thread_local_.TryCatchHandler()->is_verbose_;
+ return thread_local()->TryCatchHandler()->is_verbose_;
} else {
// Report the exception if it isn't caught by JavaScript code.
return handler == NULL;
@@ -855,7 +878,7 @@
MessageLocation potential_computed_location;
bool try_catch_needs_message =
is_caught_externally &&
- thread_local_.TryCatchHandler()->capture_message_;
+ thread_local()->TryCatchHandler()->capture_message_;
if (report_exception || try_catch_needs_message) {
if (location == NULL) {
// If no location was specified we use a computed one instead
@@ -874,19 +897,19 @@
}
// Save the message for reporting if the the exception remains uncaught.
- thread_local_.has_pending_message_ = report_exception;
- thread_local_.pending_message_ = message;
+ thread_local()->has_pending_message_ = report_exception;
+ thread_local()->pending_message_ = message;
if (!message_obj.is_null()) {
- thread_local_.pending_message_obj_ = *message_obj;
+ thread_local()->pending_message_obj_ = *message_obj;
if (location != NULL) {
- thread_local_.pending_message_script_ = *location->script();
- thread_local_.pending_message_start_pos_ = location->start_pos();
- thread_local_.pending_message_end_pos_ = location->end_pos();
+ thread_local()->pending_message_script_ = *location->script();
+ thread_local()->pending_message_start_pos_ = location->start_pos();
+ thread_local()->pending_message_end_pos_ = location->end_pos();
}
}
if (is_caught_externally) {
- thread_local_.catcher_ = thread_local_.TryCatchHandler();
+ thread_local()->catcher_ = thread_local()->TryCatchHandler();
}
// NOTE: Notifying the debugger or generating the message
@@ -903,37 +926,37 @@
// the global context. Note: We have to mark the global context here
// since the GenerateThrowOutOfMemory stub cannot make a RuntimeCall to
// set it.
- bool external_caught = thread_local_.external_caught_exception_;
+ bool external_caught = thread_local()->external_caught_exception_;
HandleScope scope;
- if (thread_local_.pending_exception_ == Failure::OutOfMemoryException())
{
+ if (thread_local()->pending_exception_ ==
Failure::OutOfMemoryException()) {
context()->mark_out_of_memory();
- } else if (thread_local_.pending_exception_ ==
+ } else if (thread_local()->pending_exception_ ==
HEAP->termination_exception()) {
if (external_caught) {
- thread_local_.TryCatchHandler()->can_continue_ = false;
- thread_local_.TryCatchHandler()->exception_ = HEAP->null_value();
+ thread_local()->TryCatchHandler()->can_continue_ = false;
+ thread_local()->TryCatchHandler()->exception_ = HEAP->null_value();
}
} else {
Handle<Object> exception(pending_exception());
- thread_local_.external_caught_exception_ = false;
+ thread_local()->external_caught_exception_ = false;
if (external_caught) {
- thread_local_.TryCatchHandler()->can_continue_ = true;
- thread_local_.TryCatchHandler()->exception_ =
- thread_local_.pending_exception_;
- if (!thread_local_.pending_message_obj_->IsTheHole()) {
- try_catch_handler()->message_ = thread_local_.pending_message_obj_;
+ thread_local()->TryCatchHandler()->can_continue_ = true;
+ thread_local()->TryCatchHandler()->exception_ =
+ thread_local()->pending_exception_;
+ if (!thread_local()->pending_message_obj_->IsTheHole()) {
+ try_catch_handler()->message_ =
thread_local()->pending_message_obj_;
}
}
- if (thread_local_.has_pending_message_) {
- thread_local_.has_pending_message_ = false;
- if (thread_local_.pending_message_ != NULL) {
- MessageHandler::ReportMessage(thread_local_.pending_message_);
- } else if (!thread_local_.pending_message_obj_->IsTheHole()) {
- Handle<Object> message_obj(thread_local_.pending_message_obj_);
- if (thread_local_.pending_message_script_ != NULL) {
- Handle<Script> script(thread_local_.pending_message_script_);
- int start_pos = thread_local_.pending_message_start_pos_;
- int end_pos = thread_local_.pending_message_end_pos_;
+ if (thread_local()->has_pending_message_) {
+ thread_local()->has_pending_message_ = false;
+ if (thread_local()->pending_message_ != NULL) {
+ MessageHandler::ReportMessage(thread_local()->pending_message_);
+ } else if (!thread_local()->pending_message_obj_->IsTheHole()) {
+ Handle<Object> message_obj(thread_local()->pending_message_obj_);
+ if (thread_local()->pending_message_script_ != NULL) {
+ Handle<Script> script(thread_local()->pending_message_script_);
+ int start_pos = thread_local()->pending_message_start_pos_;
+ int end_pos = thread_local()->pending_message_end_pos_;
MessageLocation location(script, start_pos, end_pos);
MessageHandler::ReportMessage(&location, message_obj);
} else {
@@ -941,7 +964,7 @@
}
}
}
- thread_local_.external_caught_exception_ = external_caught;
+ thread_local()->external_caught_exception_ = external_caught;
set_pending_exception(*exception);
}
clear_pending_message();
@@ -964,17 +987,17 @@
if (is_termination_exception) {
if (is_bottom_call) {
- thread_local_.external_caught_exception_ = false;
+ thread_local()->external_caught_exception_ = false;
clear_pending_exception();
return false;
}
- } else if (thread_local_.external_caught_exception_) {
+ } else if (thread_local()->external_caught_exception_) {
// If the exception is externally caught, clear it if there are no
// JavaScript frames on the way to the C++ frame that has the
// external handler.
- ASSERT(thread_local_.try_catch_handler_address() != NULL);
+ ASSERT(thread_local()->try_catch_handler_address() != NULL);
Address external_handler_address =
- thread_local_.try_catch_handler_address();
+ thread_local()->try_catch_handler_address();
JavaScriptFrameIterator it;
if (it.done() || (it.frame()->sp() > external_handler_address)) {
clear_exception = true;
@@ -983,14 +1006,14 @@
// Clear the exception if needed.
if (clear_exception) {
- thread_local_.external_caught_exception_ = false;
+ thread_local()->external_caught_exception_ = false;
clear_pending_exception();
return false;
}
}
// Reschedule the exception.
- thread_local_.scheduled_exception_ = pending_exception();
+ thread_local()->scheduled_exception_ = pending_exception();
clear_pending_exception();
return true;
}
@@ -1014,7 +1037,7 @@
Handle<Context> Top::global_context() {
- GlobalObject* global = thread_local_.context_->global();
+ GlobalObject* global = thread_local()->context_->global();
return Handle<Context>(global->global_context());
}
@@ -1042,15 +1065,15 @@
char* Top::ArchiveThread(char* to) {
- memcpy(to, reinterpret_cast<char*>(&thread_local_),
sizeof(thread_local_));
+ memcpy(to, reinterpret_cast<char*>(thread_local()),
sizeof(ThreadLocalTop));
InitializeThreadLocal();
- return to + sizeof(thread_local_);
+ return to + sizeof(ThreadLocalTop);
}
char* Top::RestoreThread(char* from) {
- memcpy(reinterpret_cast<char*>(&thread_local_), from,
sizeof(thread_local_));
- return from + sizeof(thread_local_);
+ memcpy(reinterpret_cast<char*>(thread_local()), from,
sizeof(ThreadLocalTop));
+ return from + sizeof(ThreadLocalTop);
}
=======================================
--- /branches/experimental/isolates/src/top.h Wed Jun 9 13:52:42 2010
+++ /branches/experimental/isolates/src/top.h Tue Jun 15 09:28:35 2010
@@ -43,82 +43,6 @@
class SaveContext; // Forward declaration.
class ThreadVisitor; // Defined in v8threads.h
-class ThreadLocalTop BASE_EMBEDDED {
- public:
- // Initialize the thread data.
- void Initialize();
-
- // Get the top C++ try catch handler or NULL if none are registered.
- //
- // This method is not guarenteed to return an address that can be
- // used for comparison with addresses into the JS stack. If such an
- // address is needed, use try_catch_handler_address.
- v8::TryCatch* TryCatchHandler();
-
- // Get the address of the top C++ try catch handler or NULL if
- // none are registered.
- //
- // This method always returns an address that can be compared to
- // pointers into the JavaScript stack. When running on actual
- // hardware, try_catch_handler_address and TryCatchHandler return
- // the same pointer. When running on a simulator with a separate JS
- // stack, try_catch_handler_address returns a JS stack address that
- // corresponds to the place on the JS stack where the C++ handler
- // would have been if the stack were not separate.
- inline Address try_catch_handler_address() {
- return try_catch_handler_address_;
- }
-
- // Set the address of the top C++ try catch handler.
- inline void set_try_catch_handler_address(Address address) {
- try_catch_handler_address_ = address;
- }
-
- void Free() {
- ASSERT(!has_pending_message_);
- ASSERT(!external_caught_exception_);
- ASSERT(try_catch_handler_address_ == NULL);
- }
-
- // The context where the current execution method is created and for
variable
- // lookups.
- Context* context_;
- int thread_id_;
- Object* pending_exception_;
- bool has_pending_message_;
- const char* pending_message_;
- Object* pending_message_obj_;
- Script* pending_message_script_;
- int pending_message_start_pos_;
- int pending_message_end_pos_;
- // Use a separate value for scheduled exceptions to preserve the
- // invariants that hold about pending_exception. We may want to
- // unify them later.
- Object* scheduled_exception_;
- bool external_caught_exception_;
- SaveContext* save_context_;
- v8::TryCatch* catcher_;
-
- // Stack.
- Address c_entry_fp_; // the frame pointer of the top c entry frame
- Address handler_; // try-blocks are chained through the stack
-#ifdef ENABLE_LOGGING_AND_PROFILING
- Address js_entry_sp_; // the stack pointer of the bottom js entry frame
-#endif
- bool stack_is_cooked_;
- inline bool stack_is_cooked() { return stack_is_cooked_; }
- inline void set_stack_is_cooked(bool value) { stack_is_cooked_ = value; }
-
- // Generated code scratch locations.
- int32_t formal_count_;
-
- // Call back function to report unsafe JS accesses.
- v8::FailedAccessCheckCallback failed_access_check_callback_;
-
- private:
- Address try_catch_handler_address_;
-};
-
#define TOP_ADDRESS_LIST(C) \
C(handler_address) \
C(c_entry_fp_address) \
@@ -147,53 +71,53 @@
static Address get_address_from_id(AddressId id);
// Access to top context (where the current function object was created).
- static Context* context() { return thread_local_.context_; }
+ static Context* context() { return thread_local()->context_; }
static void set_context(Context* context) {
- thread_local_.context_ = context;
- }
- static Context** context_address() { return &thread_local_.context_; }
-
- static SaveContext* save_context() {return thread_local_.save_context_; }
+ thread_local()->context_ = context;
+ }
+ static Context** context_address() { return &thread_local()->context_; }
+
+ static SaveContext* save_context() {return
thread_local()->save_context_; }
static void set_save_context(SaveContext* save) {
- thread_local_.save_context_ = save;
+ thread_local()->save_context_ = save;
}
// Access to current thread id.
- static int thread_id() { return thread_local_.thread_id_; }
- static void set_thread_id(int id) { thread_local_.thread_id_ = id; }
+ static int thread_id() { return thread_local()->thread_id_; }
+ static void set_thread_id(int id) { thread_local()->thread_id_ = id; }
// Interface to pending exception.
static Object* pending_exception() {
ASSERT(has_pending_exception());
- return thread_local_.pending_exception_;
+ return thread_local()->pending_exception_;
}
static bool external_caught_exception() {
- return thread_local_.external_caught_exception_;
+ return thread_local()->external_caught_exception_;
}
static void set_pending_exception(Object* exception) {
- thread_local_.pending_exception_ = exception;
+ thread_local()->pending_exception_ = exception;
}
static void clear_pending_exception() {
- thread_local_.pending_exception_ = HEAP->the_hole_value();
+ thread_local()->pending_exception_ = HEAP->the_hole_value();
}
static Object** pending_exception_address() {
- return &thread_local_.pending_exception_;
+ return &thread_local()->pending_exception_;
}
static bool has_pending_exception() {
- return !thread_local_.pending_exception_->IsTheHole();
+ return !thread_local()->pending_exception_->IsTheHole();
}
static void clear_pending_message() {
- thread_local_.has_pending_message_ = false;
- thread_local_.pending_message_ = NULL;
- thread_local_.pending_message_obj_ = HEAP->the_hole_value();
- thread_local_.pending_message_script_ = NULL;
+ thread_local()->has_pending_message_ = false;
+ thread_local()->pending_message_ = NULL;
+ thread_local()->pending_message_obj_ = HEAP->the_hole_value();
+ thread_local()->pending_message_script_ = NULL;
}
static v8::TryCatch* try_catch_handler() {
- return thread_local_.TryCatchHandler();
+ return thread_local()->TryCatchHandler();
}
static Address try_catch_handler_address() {
- return thread_local_.try_catch_handler_address();
+ return thread_local()->try_catch_handler_address();
}
// This method is called by the api after operations that may throw
// exceptions. If an exception was thrown and not handled by an external
@@ -203,29 +127,29 @@
static bool* external_caught_exception_address() {
- return &thread_local_.external_caught_exception_;
+ return &thread_local()->external_caught_exception_;
}
static Object** scheduled_exception_address() {
- return &thread_local_.scheduled_exception_;
+ return &thread_local()->scheduled_exception_;
}
static Object* scheduled_exception() {
ASSERT(has_scheduled_exception());
- return thread_local_.scheduled_exception_;
+ return thread_local()->scheduled_exception_;
}
static bool has_scheduled_exception() {
- return !thread_local_.scheduled_exception_->IsTheHole();
+ return !thread_local()->scheduled_exception_->IsTheHole();
}
static void clear_scheduled_exception() {
- thread_local_.scheduled_exception_ = HEAP->the_hole_value();
+ thread_local()->scheduled_exception_ = HEAP->the_hole_value();
}
static void setup_external_caught() {
- thread_local_.external_caught_exception_ =
+ thread_local()->external_caught_exception_ =
has_pending_exception() &&
- (thread_local_.catcher_ != NULL) &&
- (try_catch_handler() == thread_local_.catcher_);
+ (thread_local()->catcher_ != NULL) &&
+ (try_catch_handler() == thread_local()->catcher_);
}
// Tells whether the current context has experienced an out of memory
@@ -239,9 +163,9 @@
static Address handler(ThreadLocalTop* thread) { return
thread->handler_; }
static inline Address* c_entry_fp_address() {
- return &thread_local_.c_entry_fp_;
- }
- static inline Address* handler_address() { return
&thread_local_.handler_; }
+ return &thread_local()->c_entry_fp_;
+ }
+ static inline Address* handler_address() { return
&thread_local()->handler_; }
#ifdef ENABLE_LOGGING_AND_PROFILING
// Bottom JS entry (see StackTracer::Trace in log.cc).
@@ -249,12 +173,12 @@
return thread->js_entry_sp_;
}
static inline Address* js_entry_sp_address() {
- return &thread_local_.js_entry_sp_;
+ return &thread_local()->js_entry_sp_;
}
#endif
// Generated code scratch locations.
- static void* formal_count_address() { return
&thread_local_.formal_count_; }
+ static void* formal_count_address() { return
&thread_local()->formal_count_; }
static void MarkCompactPrologue(bool is_compacting);
static void MarkCompactEpilogue(bool is_compacting);
@@ -346,7 +270,7 @@
static Handle<Context> GetCallingGlobalContext();
static Handle<JSBuiltinsObject> builtins() {
- return Handle<JSBuiltinsObject>(thread_local_.context_->builtins());
+ return Handle<JSBuiltinsObject>(thread_local()->context_->builtins());
}
static void RegisterTryCatchHandler(v8::TryCatch* that);
@@ -359,17 +283,18 @@
GLOBAL_CONTEXT_FIELDS(TOP_GLOBAL_CONTEXT_FIELD_ACCESSOR)
#undef TOP_GLOBAL_CONTEXT_FIELD_ACCESSOR
- static inline ThreadLocalTop* GetCurrentThread() { return
&thread_local_; }
static int ArchiveSpacePerThread() { return sizeof(ThreadLocalTop); }
static char* ArchiveThread(char* to);
static char* RestoreThread(char* from);
- static void FreeThreadResources() { thread_local_.Free(); }
+ static void FreeThreadResources() { thread_local()->Free(); }
static const char* kStackOverflowMessage;
private:
// The context that initiated this JS execution.
- static ThreadLocalTop thread_local_;
+ static ThreadLocalTop* thread_local() {
+ return Isolate::Current()->thread_local_top();
+ }
static void InitializeThreadLocal();
static void PrintStackTrace(FILE* out, ThreadLocalTop* thread);
static void MarkCompactPrologue(bool is_compacting,
=======================================
--- /branches/experimental/isolates/test/cctest/test-log-stack-tracer.cc
Tue May 25 07:08:17 2010
+++ /branches/experimental/isolates/test/cctest/test-log-stack-tracer.cc
Tue Jun 15 09:28:35 2010
@@ -130,8 +130,8 @@
static Address GetJsEntrySp() {
- CHECK_NE(NULL, Top::GetCurrentThread());
- return Top::js_entry_sp(Top::GetCurrentThread());
+ CHECK_NE(NULL, i::Isolate::Current()->thread_local_top());
+ return Top::js_entry_sp(i::Isolate::Current()->thread_local_top());
}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev