OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 #include "snapshot.h" | 46 #include "snapshot.h" |
47 #include "v8threads.h" | 47 #include "v8threads.h" |
48 #include "version.h" | 48 #include "version.h" |
49 #include "vm-state-inl.h" | 49 #include "vm-state-inl.h" |
50 | 50 |
51 #include "../include/v8-profiler.h" | 51 #include "../include/v8-profiler.h" |
52 #include "../include/v8-testing.h" | 52 #include "../include/v8-testing.h" |
53 | 53 |
54 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) | 54 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) |
55 | 55 |
56 // TODO(isolates): avoid repeated TLS reads in function prologues. | |
57 #ifdef ENABLE_VMSTATE_TRACKING | 56 #ifdef ENABLE_VMSTATE_TRACKING |
58 #define ENTER_V8(isolate) \ | 57 #define ENTER_V8(isolate) \ |
59 ASSERT((isolate)->IsInitialized()); \ | 58 ASSERT((isolate)->IsInitialized()); \ |
60 i::VMState __state__((isolate), i::OTHER) | 59 i::VMState __state__((isolate), i::OTHER) |
61 #define LEAVE_V8(isolate) \ | 60 #define LEAVE_V8(isolate) \ |
62 i::VMState __state__((isolate), i::EXTERNAL) | 61 i::VMState __state__((isolate), i::EXTERNAL) |
63 #else | 62 #else |
64 #define ENTER_V8(isolate) ((void) 0) | 63 #define ENTER_V8(isolate) ((void) 0) |
65 #define LEAVE_V8(isolate) ((void) 0) | 64 #define LEAVE_V8(isolate) ((void) 0) |
66 #endif | 65 #endif |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 return i::V8::Initialize(NULL); | 282 return i::V8::Initialize(NULL); |
284 } | 283 } |
285 | 284 |
286 | 285 |
287 static inline bool EnsureInitializedForIsolate(i::Isolate* isolate, | 286 static inline bool EnsureInitializedForIsolate(i::Isolate* isolate, |
288 const char* location) { | 287 const char* location) { |
289 if (IsDeadCheck(isolate, location)) return false; | 288 if (IsDeadCheck(isolate, location)) return false; |
290 if (isolate != NULL) { | 289 if (isolate != NULL) { |
291 if (isolate->IsInitialized()) return true; | 290 if (isolate->IsInitialized()) return true; |
292 } | 291 } |
| 292 ASSERT(isolate == i::Isolate::Current()); |
293 return ApiCheck(InitializeHelper(), location, "Error initializing V8"); | 293 return ApiCheck(InitializeHelper(), location, "Error initializing V8"); |
294 } | 294 } |
295 | 295 |
296 // Some initializing API functions are called early and may be | 296 // Some initializing API functions are called early and may be |
297 // called on a thread different from static initializer thread. | 297 // called on a thread different from static initializer thread. |
298 // If Isolate API is used, Isolate::Enter() will initialize TLS so | 298 // If Isolate API is used, Isolate::Enter() will initialize TLS so |
299 // Isolate::Current() works. If it's a legacy case, then the thread | 299 // Isolate::Current() works. If it's a legacy case, then the thread |
300 // may not have TLS initialized yet. However, in initializing APIs it | 300 // may not have TLS initialized yet. However, in initializing APIs it |
301 // may be too early to call EnsureInitialized() - some pre-init | 301 // may be too early to call EnsureInitialized() - some pre-init |
302 // parameters still have to be configured. | 302 // parameters still have to be configured. |
(...skipping 5429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5732 | 5732 |
5733 namespace internal { | 5733 namespace internal { |
5734 | 5734 |
5735 | 5735 |
5736 void HandleScopeImplementer::FreeThreadResources() { | 5736 void HandleScopeImplementer::FreeThreadResources() { |
5737 Free(); | 5737 Free(); |
5738 } | 5738 } |
5739 | 5739 |
5740 | 5740 |
5741 char* HandleScopeImplementer::ArchiveThread(char* storage) { | 5741 char* HandleScopeImplementer::ArchiveThread(char* storage) { |
5742 Isolate* isolate = Isolate::Current(); | |
5743 v8::ImplementationUtilities::HandleScopeData* current = | 5742 v8::ImplementationUtilities::HandleScopeData* current = |
5744 isolate->handle_scope_data(); | 5743 isolate_->handle_scope_data(); |
5745 handle_scope_data_ = *current; | 5744 handle_scope_data_ = *current; |
5746 memcpy(storage, this, sizeof(*this)); | 5745 memcpy(storage, this, sizeof(*this)); |
5747 | 5746 |
5748 ResetAfterArchive(); | 5747 ResetAfterArchive(); |
5749 current->Initialize(); | 5748 current->Initialize(); |
5750 | 5749 |
5751 return storage + ArchiveSpacePerThread(); | 5750 return storage + ArchiveSpacePerThread(); |
5752 } | 5751 } |
5753 | 5752 |
5754 | 5753 |
5755 int HandleScopeImplementer::ArchiveSpacePerThread() { | 5754 int HandleScopeImplementer::ArchiveSpacePerThread() { |
5756 return sizeof(HandleScopeImplementer); | 5755 return sizeof(HandleScopeImplementer); |
5757 } | 5756 } |
5758 | 5757 |
5759 | 5758 |
5760 char* HandleScopeImplementer::RestoreThread(char* storage) { | 5759 char* HandleScopeImplementer::RestoreThread(char* storage) { |
5761 memcpy(this, storage, sizeof(*this)); | 5760 memcpy(this, storage, sizeof(*this)); |
5762 *Isolate::Current()->handle_scope_data() = handle_scope_data_; | 5761 *isolate_->handle_scope_data() = handle_scope_data_; |
5763 return storage + ArchiveSpacePerThread(); | 5762 return storage + ArchiveSpacePerThread(); |
5764 } | 5763 } |
5765 | 5764 |
5766 | 5765 |
5767 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { | 5766 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { |
5768 // Iterate over all handles in the blocks except for the last. | 5767 // Iterate over all handles in the blocks except for the last. |
5769 for (int i = blocks()->length() - 2; i >= 0; --i) { | 5768 for (int i = blocks()->length() - 2; i >= 0; --i) { |
5770 Object** block = blocks()->at(i); | 5769 Object** block = blocks()->at(i); |
5771 v->VisitPointers(block, &block[kHandleBlockSize]); | 5770 v->VisitPointers(block, &block[kHandleBlockSize]); |
5772 } | 5771 } |
5773 | 5772 |
5774 // Iterate over live handles in the last block (if any). | 5773 // Iterate over live handles in the last block (if any). |
5775 if (!blocks()->is_empty()) { | 5774 if (!blocks()->is_empty()) { |
5776 v->VisitPointers(blocks()->last(), handle_scope_data_.next); | 5775 v->VisitPointers(blocks()->last(), handle_scope_data_.next); |
5777 } | 5776 } |
5778 | 5777 |
5779 if (!saved_contexts_.is_empty()) { | 5778 if (!saved_contexts_.is_empty()) { |
5780 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); | 5779 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); |
5781 v->VisitPointers(start, start + saved_contexts_.length()); | 5780 v->VisitPointers(start, start + saved_contexts_.length()); |
5782 } | 5781 } |
5783 } | 5782 } |
5784 | 5783 |
5785 | 5784 |
5786 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { | 5785 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { |
5787 v8::ImplementationUtilities::HandleScopeData* current = | 5786 v8::ImplementationUtilities::HandleScopeData* current = |
5788 Isolate::Current()->handle_scope_data(); | 5787 isolate_->handle_scope_data(); |
5789 handle_scope_data_ = *current; | 5788 handle_scope_data_ = *current; |
5790 IterateThis(v); | 5789 IterateThis(v); |
5791 } | 5790 } |
5792 | 5791 |
5793 | 5792 |
5794 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 5793 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
5795 HandleScopeImplementer* scope_implementer = | 5794 HandleScopeImplementer* scope_implementer = |
5796 reinterpret_cast<HandleScopeImplementer*>(storage); | 5795 reinterpret_cast<HandleScopeImplementer*>(storage); |
5797 scope_implementer->IterateThis(v); | 5796 scope_implementer->IterateThis(v); |
5798 return storage + ArchiveSpacePerThread(); | 5797 return storage + ArchiveSpacePerThread(); |
5799 } | 5798 } |
5800 | 5799 |
5801 } } // namespace v8::internal | 5800 } } // namespace v8::internal |
OLD | NEW |