| 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 2945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3248 "v8::GetIndexedPropertiesExternalArrayDataLength()", | 3248 "v8::GetIndexedPropertiesExternalArrayDataLength()", |
| 3249 return 0); | 3249 return 0); |
| 3250 if (self->HasExternalArrayElements()) { | 3250 if (self->HasExternalArrayElements()) { |
| 3251 return i::ExternalArray::cast(self->elements())->length(); | 3251 return i::ExternalArray::cast(self->elements())->length(); |
| 3252 } else { | 3252 } else { |
| 3253 return -1; | 3253 return -1; |
| 3254 } | 3254 } |
| 3255 } | 3255 } |
| 3256 | 3256 |
| 3257 | 3257 |
| 3258 Local<v8::Value> Object::CallAsFunction(v8::Handle<v8::Object> recv, int argc, |
| 3259 v8::Handle<v8::Value> argv[]) { |
| 3260 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3261 ON_BAILOUT(isolate, "v8::Object::CallAsFunction()", |
| 3262 return Local<v8::Value>()); |
| 3263 LOG_API(isolate, "Object::CallAsFunction"); |
| 3264 ENTER_V8(isolate); |
| 3265 i::HandleScope scope(isolate); |
| 3266 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3267 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); |
| 3268 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
| 3269 i::Object*** args = reinterpret_cast<i::Object***>(argv); |
| 3270 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>(); |
| 3271 if (obj->IsJSFunction()) { |
| 3272 fun = i::Handle<i::JSFunction>::cast(obj); |
| 3273 } else { |
| 3274 EXCEPTION_PREAMBLE(isolate); |
| 3275 i::Handle<i::Object> delegate = |
| 3276 i::Execution::TryGetFunctionDelegate(obj, &has_pending_exception); |
| 3277 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
| 3278 fun = i::Handle<i::JSFunction>::cast(delegate); |
| 3279 recv_obj = obj; |
| 3280 } |
| 3281 EXCEPTION_PREAMBLE(isolate); |
| 3282 i::Handle<i::Object> returned = |
| 3283 i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception); |
| 3284 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
| 3285 return Utils::ToLocal(scope.CloseAndEscape(returned)); |
| 3286 } |
| 3287 |
| 3288 |
| 3289 Local<v8::Value> Object::CallAsConstructor(int argc, |
| 3290 v8::Handle<v8::Value> argv[]) { |
| 3291 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3292 ON_BAILOUT(isolate, "v8::Object::CallAsConstructor()", |
| 3293 return Local<v8::Object>()); |
| 3294 LOG_API(isolate, "Object::CallAsConstructor"); |
| 3295 ENTER_V8(isolate); |
| 3296 i::HandleScope scope(isolate); |
| 3297 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3298 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
| 3299 i::Object*** args = reinterpret_cast<i::Object***>(argv); |
| 3300 if (obj->IsJSFunction()) { |
| 3301 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(obj); |
| 3302 EXCEPTION_PREAMBLE(isolate); |
| 3303 i::Handle<i::Object> returned = |
| 3304 i::Execution::New(fun, argc, args, &has_pending_exception); |
| 3305 EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
| 3306 return Utils::ToLocal(scope.CloseAndEscape( |
| 3307 i::Handle<i::JSObject>::cast(returned))); |
| 3308 } |
| 3309 EXCEPTION_PREAMBLE(isolate); |
| 3310 i::Handle<i::Object> delegate = |
| 3311 i::Execution::TryGetConstructorDelegate(obj, &has_pending_exception); |
| 3312 EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
| 3313 if (!delegate->IsUndefined()) { |
| 3314 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(delegate); |
| 3315 EXCEPTION_PREAMBLE(isolate); |
| 3316 i::Handle<i::Object> returned = |
| 3317 i::Execution::Call(fun, obj, argc, args, &has_pending_exception); |
| 3318 EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Object>()); |
| 3319 ASSERT(!delegate->IsUndefined()); |
| 3320 return Utils::ToLocal(scope.CloseAndEscape(returned)); |
| 3321 } |
| 3322 return Local<v8::Object>(); |
| 3323 } |
| 3324 |
| 3325 |
| 3258 Local<v8::Object> Function::NewInstance() const { | 3326 Local<v8::Object> Function::NewInstance() const { |
| 3259 return NewInstance(0, NULL); | 3327 return NewInstance(0, NULL); |
| 3260 } | 3328 } |
| 3261 | 3329 |
| 3262 | 3330 |
| 3263 Local<v8::Object> Function::NewInstance(int argc, | 3331 Local<v8::Object> Function::NewInstance(int argc, |
| 3264 v8::Handle<v8::Value> argv[]) const { | 3332 v8::Handle<v8::Value> argv[]) const { |
| 3265 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3333 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 3266 ON_BAILOUT(isolate, "v8::Function::NewInstance()", | 3334 ON_BAILOUT(isolate, "v8::Function::NewInstance()", |
| 3267 return Local<v8::Object>()); | 3335 return Local<v8::Object>()); |
| (...skipping 2433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5701 | 5769 |
| 5702 namespace internal { | 5770 namespace internal { |
| 5703 | 5771 |
| 5704 | 5772 |
| 5705 void HandleScopeImplementer::FreeThreadResources() { | 5773 void HandleScopeImplementer::FreeThreadResources() { |
| 5706 Free(); | 5774 Free(); |
| 5707 } | 5775 } |
| 5708 | 5776 |
| 5709 | 5777 |
| 5710 char* HandleScopeImplementer::ArchiveThread(char* storage) { | 5778 char* HandleScopeImplementer::ArchiveThread(char* storage) { |
| 5711 Isolate* isolate = Isolate::Current(); | |
| 5712 v8::ImplementationUtilities::HandleScopeData* current = | 5779 v8::ImplementationUtilities::HandleScopeData* current = |
| 5713 isolate->handle_scope_data(); | 5780 isolate_->handle_scope_data(); |
| 5714 handle_scope_data_ = *current; | 5781 handle_scope_data_ = *current; |
| 5715 memcpy(storage, this, sizeof(*this)); | 5782 memcpy(storage, this, sizeof(*this)); |
| 5716 | 5783 |
| 5717 ResetAfterArchive(); | 5784 ResetAfterArchive(); |
| 5718 current->Initialize(); | 5785 current->Initialize(); |
| 5719 | 5786 |
| 5720 return storage + ArchiveSpacePerThread(); | 5787 return storage + ArchiveSpacePerThread(); |
| 5721 } | 5788 } |
| 5722 | 5789 |
| 5723 | 5790 |
| 5724 int HandleScopeImplementer::ArchiveSpacePerThread() { | 5791 int HandleScopeImplementer::ArchiveSpacePerThread() { |
| 5725 return sizeof(HandleScopeImplementer); | 5792 return sizeof(HandleScopeImplementer); |
| 5726 } | 5793 } |
| 5727 | 5794 |
| 5728 | 5795 |
| 5729 char* HandleScopeImplementer::RestoreThread(char* storage) { | 5796 char* HandleScopeImplementer::RestoreThread(char* storage) { |
| 5730 memcpy(this, storage, sizeof(*this)); | 5797 memcpy(this, storage, sizeof(*this)); |
| 5731 *Isolate::Current()->handle_scope_data() = handle_scope_data_; | 5798 *isolate_->handle_scope_data() = handle_scope_data_; |
| 5732 return storage + ArchiveSpacePerThread(); | 5799 return storage + ArchiveSpacePerThread(); |
| 5733 } | 5800 } |
| 5734 | 5801 |
| 5735 | 5802 |
| 5736 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { | 5803 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { |
| 5737 // Iterate over all handles in the blocks except for the last. | 5804 // Iterate over all handles in the blocks except for the last. |
| 5738 for (int i = blocks()->length() - 2; i >= 0; --i) { | 5805 for (int i = blocks()->length() - 2; i >= 0; --i) { |
| 5739 Object** block = blocks()->at(i); | 5806 Object** block = blocks()->at(i); |
| 5740 v->VisitPointers(block, &block[kHandleBlockSize]); | 5807 v->VisitPointers(block, &block[kHandleBlockSize]); |
| 5741 } | 5808 } |
| 5742 | 5809 |
| 5743 // Iterate over live handles in the last block (if any). | 5810 // Iterate over live handles in the last block (if any). |
| 5744 if (!blocks()->is_empty()) { | 5811 if (!blocks()->is_empty()) { |
| 5745 v->VisitPointers(blocks()->last(), handle_scope_data_.next); | 5812 v->VisitPointers(blocks()->last(), handle_scope_data_.next); |
| 5746 } | 5813 } |
| 5747 | 5814 |
| 5748 if (!saved_contexts_.is_empty()) { | 5815 if (!saved_contexts_.is_empty()) { |
| 5749 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); | 5816 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); |
| 5750 v->VisitPointers(start, start + saved_contexts_.length()); | 5817 v->VisitPointers(start, start + saved_contexts_.length()); |
| 5751 } | 5818 } |
| 5752 } | 5819 } |
| 5753 | 5820 |
| 5754 | 5821 |
| 5755 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { | 5822 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { |
| 5756 v8::ImplementationUtilities::HandleScopeData* current = | 5823 v8::ImplementationUtilities::HandleScopeData* current = |
| 5757 Isolate::Current()->handle_scope_data(); | 5824 isolate_->handle_scope_data(); |
| 5758 handle_scope_data_ = *current; | 5825 handle_scope_data_ = *current; |
| 5759 IterateThis(v); | 5826 IterateThis(v); |
| 5760 } | 5827 } |
| 5761 | 5828 |
| 5762 | 5829 |
| 5763 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 5830 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
| 5764 HandleScopeImplementer* scope_implementer = | 5831 HandleScopeImplementer* scope_implementer = |
| 5765 reinterpret_cast<HandleScopeImplementer*>(storage); | 5832 reinterpret_cast<HandleScopeImplementer*>(storage); |
| 5766 scope_implementer->IterateThis(v); | 5833 scope_implementer->IterateThis(v); |
| 5767 return storage + ArchiveSpacePerThread(); | 5834 return storage + ArchiveSpacePerThread(); |
| 5768 } | 5835 } |
| 5769 | 5836 |
| 5770 } } // namespace v8::internal | 5837 } } // namespace v8::internal |
| OLD | NEW |