| 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. |
| 56 #ifdef ENABLE_VMSTATE_TRACKING | 57 #ifdef ENABLE_VMSTATE_TRACKING |
| 57 #define ENTER_V8(isolate) \ | 58 #define ENTER_V8(isolate) \ |
| 58 ASSERT((isolate)->IsInitialized()); \ | 59 ASSERT((isolate)->IsInitialized()); \ |
| 59 i::VMState __state__((isolate), i::OTHER) | 60 i::VMState __state__((isolate), i::OTHER) |
| 60 #define LEAVE_V8(isolate) \ | 61 #define LEAVE_V8(isolate) \ |
| 61 i::VMState __state__((isolate), i::EXTERNAL) | 62 i::VMState __state__((isolate), i::EXTERNAL) |
| 62 #else | 63 #else |
| 63 #define ENTER_V8(isolate) ((void) 0) | 64 #define ENTER_V8(isolate) ((void) 0) |
| 64 #define LEAVE_V8(isolate) ((void) 0) | 65 #define LEAVE_V8(isolate) ((void) 0) |
| 65 #endif | 66 #endif |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 return i::V8::Initialize(NULL); | 283 return i::V8::Initialize(NULL); |
| 283 } | 284 } |
| 284 | 285 |
| 285 | 286 |
| 286 static inline bool EnsureInitializedForIsolate(i::Isolate* isolate, | 287 static inline bool EnsureInitializedForIsolate(i::Isolate* isolate, |
| 287 const char* location) { | 288 const char* location) { |
| 288 if (IsDeadCheck(isolate, location)) return false; | 289 if (IsDeadCheck(isolate, location)) return false; |
| 289 if (isolate != NULL) { | 290 if (isolate != NULL) { |
| 290 if (isolate->IsInitialized()) return true; | 291 if (isolate->IsInitialized()) return true; |
| 291 } | 292 } |
| 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 5377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5680 | 5680 |
| 5681 namespace internal { | 5681 namespace internal { |
| 5682 | 5682 |
| 5683 | 5683 |
| 5684 void HandleScopeImplementer::FreeThreadResources() { | 5684 void HandleScopeImplementer::FreeThreadResources() { |
| 5685 Free(); | 5685 Free(); |
| 5686 } | 5686 } |
| 5687 | 5687 |
| 5688 | 5688 |
| 5689 char* HandleScopeImplementer::ArchiveThread(char* storage) { | 5689 char* HandleScopeImplementer::ArchiveThread(char* storage) { |
| 5690 Isolate* isolate = Isolate::Current(); |
| 5690 v8::ImplementationUtilities::HandleScopeData* current = | 5691 v8::ImplementationUtilities::HandleScopeData* current = |
| 5691 isolate_->handle_scope_data(); | 5692 isolate->handle_scope_data(); |
| 5692 handle_scope_data_ = *current; | 5693 handle_scope_data_ = *current; |
| 5693 memcpy(storage, this, sizeof(*this)); | 5694 memcpy(storage, this, sizeof(*this)); |
| 5694 | 5695 |
| 5695 ResetAfterArchive(); | 5696 ResetAfterArchive(); |
| 5696 current->Initialize(); | 5697 current->Initialize(); |
| 5697 | 5698 |
| 5698 return storage + ArchiveSpacePerThread(); | 5699 return storage + ArchiveSpacePerThread(); |
| 5699 } | 5700 } |
| 5700 | 5701 |
| 5701 | 5702 |
| 5702 int HandleScopeImplementer::ArchiveSpacePerThread() { | 5703 int HandleScopeImplementer::ArchiveSpacePerThread() { |
| 5703 return sizeof(HandleScopeImplementer); | 5704 return sizeof(HandleScopeImplementer); |
| 5704 } | 5705 } |
| 5705 | 5706 |
| 5706 | 5707 |
| 5707 char* HandleScopeImplementer::RestoreThread(char* storage) { | 5708 char* HandleScopeImplementer::RestoreThread(char* storage) { |
| 5708 memcpy(this, storage, sizeof(*this)); | 5709 memcpy(this, storage, sizeof(*this)); |
| 5709 *isolate_->handle_scope_data() = handle_scope_data_; | 5710 *Isolate::Current()->handle_scope_data() = handle_scope_data_; |
| 5710 return storage + ArchiveSpacePerThread(); | 5711 return storage + ArchiveSpacePerThread(); |
| 5711 } | 5712 } |
| 5712 | 5713 |
| 5713 | 5714 |
| 5714 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { | 5715 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { |
| 5715 // Iterate over all handles in the blocks except for the last. | 5716 // Iterate over all handles in the blocks except for the last. |
| 5716 for (int i = blocks()->length() - 2; i >= 0; --i) { | 5717 for (int i = blocks()->length() - 2; i >= 0; --i) { |
| 5717 Object** block = blocks()->at(i); | 5718 Object** block = blocks()->at(i); |
| 5718 v->VisitPointers(block, &block[kHandleBlockSize]); | 5719 v->VisitPointers(block, &block[kHandleBlockSize]); |
| 5719 } | 5720 } |
| 5720 | 5721 |
| 5721 // Iterate over live handles in the last block (if any). | 5722 // Iterate over live handles in the last block (if any). |
| 5722 if (!blocks()->is_empty()) { | 5723 if (!blocks()->is_empty()) { |
| 5723 v->VisitPointers(blocks()->last(), handle_scope_data_.next); | 5724 v->VisitPointers(blocks()->last(), handle_scope_data_.next); |
| 5724 } | 5725 } |
| 5725 | 5726 |
| 5726 if (!saved_contexts_.is_empty()) { | 5727 if (!saved_contexts_.is_empty()) { |
| 5727 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); | 5728 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); |
| 5728 v->VisitPointers(start, start + saved_contexts_.length()); | 5729 v->VisitPointers(start, start + saved_contexts_.length()); |
| 5729 } | 5730 } |
| 5730 } | 5731 } |
| 5731 | 5732 |
| 5732 | 5733 |
| 5733 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { | 5734 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { |
| 5734 v8::ImplementationUtilities::HandleScopeData* current = | 5735 v8::ImplementationUtilities::HandleScopeData* current = |
| 5735 isolate_->handle_scope_data(); | 5736 Isolate::Current()->handle_scope_data(); |
| 5736 handle_scope_data_ = *current; | 5737 handle_scope_data_ = *current; |
| 5737 IterateThis(v); | 5738 IterateThis(v); |
| 5738 } | 5739 } |
| 5739 | 5740 |
| 5740 | 5741 |
| 5741 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 5742 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
| 5742 HandleScopeImplementer* scope_implementer = | 5743 HandleScopeImplementer* scope_implementer = |
| 5743 reinterpret_cast<HandleScopeImplementer*>(storage); | 5744 reinterpret_cast<HandleScopeImplementer*>(storage); |
| 5744 scope_implementer->IterateThis(v); | 5745 scope_implementer->IterateThis(v); |
| 5745 return storage + ArchiveSpacePerThread(); | 5746 return storage + ArchiveSpacePerThread(); |
| 5746 } | 5747 } |
| 5747 | 5748 |
| 5748 } } // namespace v8::internal | 5749 } } // namespace v8::internal |
| OLD | NEW |