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