OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 5310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5613 | 5613 |
5614 namespace internal { | 5614 namespace internal { |
5615 | 5615 |
5616 | 5616 |
5617 void HandleScopeImplementer::FreeThreadResources() { | 5617 void HandleScopeImplementer::FreeThreadResources() { |
5618 Free(); | 5618 Free(); |
5619 } | 5619 } |
5620 | 5620 |
5621 | 5621 |
5622 char* HandleScopeImplementer::ArchiveThread(char* storage) { | 5622 char* HandleScopeImplementer::ArchiveThread(char* storage) { |
5623 Isolate* isolate = Isolate::Current(); | |
5624 v8::ImplementationUtilities::HandleScopeData* current = | 5623 v8::ImplementationUtilities::HandleScopeData* current = |
5625 isolate->handle_scope_data(); | 5624 isolate_->handle_scope_data(); |
5626 handle_scope_data_ = *current; | 5625 handle_scope_data_ = *current; |
5627 memcpy(storage, this, sizeof(*this)); | 5626 memcpy(storage, this, sizeof(*this)); |
5628 | 5627 |
5629 ResetAfterArchive(); | 5628 ResetAfterArchive(); |
5630 current->Initialize(); | 5629 current->Initialize(); |
5631 | 5630 |
5632 return storage + ArchiveSpacePerThread(); | 5631 return storage + ArchiveSpacePerThread(); |
5633 } | 5632 } |
5634 | 5633 |
5635 | 5634 |
5636 int HandleScopeImplementer::ArchiveSpacePerThread() { | 5635 int HandleScopeImplementer::ArchiveSpacePerThread() { |
5637 return sizeof(HandleScopeImplementer); | 5636 return sizeof(HandleScopeImplementer); |
5638 } | 5637 } |
5639 | 5638 |
5640 | 5639 |
5641 char* HandleScopeImplementer::RestoreThread(char* storage) { | 5640 char* HandleScopeImplementer::RestoreThread(char* storage) { |
5642 memcpy(this, storage, sizeof(*this)); | 5641 memcpy(this, storage, sizeof(*this)); |
5643 *Isolate::Current()->handle_scope_data() = handle_scope_data_; | 5642 *isolate_->handle_scope_data() = handle_scope_data_; |
5644 return storage + ArchiveSpacePerThread(); | 5643 return storage + ArchiveSpacePerThread(); |
5645 } | 5644 } |
5646 | 5645 |
5647 | 5646 |
5648 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { | 5647 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { |
5649 // Iterate over all handles in the blocks except for the last. | 5648 // Iterate over all handles in the blocks except for the last. |
5650 for (int i = blocks()->length() - 2; i >= 0; --i) { | 5649 for (int i = blocks()->length() - 2; i >= 0; --i) { |
5651 Object** block = blocks()->at(i); | 5650 Object** block = blocks()->at(i); |
5652 v->VisitPointers(block, &block[kHandleBlockSize]); | 5651 v->VisitPointers(block, &block[kHandleBlockSize]); |
5653 } | 5652 } |
5654 | 5653 |
5655 // Iterate over live handles in the last block (if any). | 5654 // Iterate over live handles in the last block (if any). |
5656 if (!blocks()->is_empty()) { | 5655 if (!blocks()->is_empty()) { |
5657 v->VisitPointers(blocks()->last(), handle_scope_data_.next); | 5656 v->VisitPointers(blocks()->last(), handle_scope_data_.next); |
5658 } | 5657 } |
5659 | 5658 |
5660 if (!saved_contexts_.is_empty()) { | 5659 if (!saved_contexts_.is_empty()) { |
5661 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); | 5660 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); |
5662 v->VisitPointers(start, start + saved_contexts_.length()); | 5661 v->VisitPointers(start, start + saved_contexts_.length()); |
5663 } | 5662 } |
5664 } | 5663 } |
5665 | 5664 |
5666 | 5665 |
5667 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { | 5666 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { |
5668 v8::ImplementationUtilities::HandleScopeData* current = | 5667 v8::ImplementationUtilities::HandleScopeData* current = |
5669 Isolate::Current()->handle_scope_data(); | 5668 isolate_->handle_scope_data(); |
5670 handle_scope_data_ = *current; | 5669 handle_scope_data_ = *current; |
5671 IterateThis(v); | 5670 IterateThis(v); |
5672 } | 5671 } |
5673 | 5672 |
5674 | 5673 |
5675 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 5674 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
5676 HandleScopeImplementer* scope_implementer = | 5675 HandleScopeImplementer* scope_implementer = |
5677 reinterpret_cast<HandleScopeImplementer*>(storage); | 5676 reinterpret_cast<HandleScopeImplementer*>(storage); |
5678 scope_implementer->IterateThis(v); | 5677 scope_implementer->IterateThis(v); |
5679 return storage + ArchiveSpacePerThread(); | 5678 return storage + ArchiveSpacePerThread(); |
5680 } | 5679 } |
5681 | 5680 |
5682 } } // namespace v8::internal | 5681 } } // namespace v8::internal |
OLD | NEW |