| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 if (i::V8::IsRunning()) { | 258 if (i::V8::IsRunning()) { |
| 259 return true; | 259 return true; |
| 260 } | 260 } |
| 261 if (IsDeadCheck(location)) { | 261 if (IsDeadCheck(location)) { |
| 262 return false; | 262 return false; |
| 263 } | 263 } |
| 264 return ApiCheck(v8::V8::Initialize(), location, "Error initializing V8"); | 264 return ApiCheck(v8::V8::Initialize(), location, "Error initializing V8"); |
| 265 } | 265 } |
| 266 | 266 |
| 267 | 267 |
| 268 ImplementationUtilities::HandleScopeData* | |
| 269 ImplementationUtilities::CurrentHandleScope() { | |
| 270 return &i::HandleScope::current_; | |
| 271 } | |
| 272 | |
| 273 | |
| 274 #ifdef DEBUG | 268 #ifdef DEBUG |
| 275 void ImplementationUtilities::ZapHandleRange(i::Object** begin, | 269 void ImplementationUtilities::ZapHandleRange(i::Object** begin, |
| 276 i::Object** end) { | 270 i::Object** end) { |
| 277 i::HandleScope::ZapRange(begin, end); | 271 i::HandleScope::ZapRange(begin, end); |
| 278 } | 272 } |
| 279 #endif | 273 #endif |
| 280 | 274 |
| 281 | 275 |
| 282 v8::Handle<v8::Primitive> ImplementationUtilities::Undefined() { | 276 v8::Handle<v8::Primitive> ImplementationUtilities::Undefined() { |
| 283 if (!EnsureInitialized("v8::Undefined()")) return v8::Handle<v8::Primitive>(); | 277 if (!EnsureInitialized("v8::Undefined()")) return v8::Handle<v8::Primitive>(); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 LOG_API("DisposeGlobal"); | 436 LOG_API("DisposeGlobal"); |
| 443 if (!i::V8::IsRunning()) return; | 437 if (!i::V8::IsRunning()) return; |
| 444 i::GlobalHandles::Destroy(obj); | 438 i::GlobalHandles::Destroy(obj); |
| 445 } | 439 } |
| 446 | 440 |
| 447 // --- H a n d l e s --- | 441 // --- H a n d l e s --- |
| 448 | 442 |
| 449 | 443 |
| 450 HandleScope::HandleScope() : is_closed_(false) { | 444 HandleScope::HandleScope() : is_closed_(false) { |
| 451 API_ENTRY_CHECK("HandleScope::HandleScope"); | 445 API_ENTRY_CHECK("HandleScope::HandleScope"); |
| 446 // Handle scope is per-isolate so we need to initialize the current one |
| 447 // if it wasn't already. |
| 448 EnsureInitialized("HandleScope::HandleScope"); |
| 452 i::HandleScope::Enter(&previous_); | 449 i::HandleScope::Enter(&previous_); |
| 453 } | 450 } |
| 454 | 451 |
| 455 | 452 |
| 456 HandleScope::~HandleScope() { | 453 HandleScope::~HandleScope() { |
| 457 if (!is_closed_) { | 454 if (!is_closed_) { |
| 458 i::HandleScope::Leave(&previous_); | 455 i::HandleScope::Leave(&previous_); |
| 459 } | 456 } |
| 460 } | 457 } |
| 461 | 458 |
| (...skipping 2584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3046 if (!proxy.is_null()) | 3043 if (!proxy.is_null()) |
| 3047 Utils::OpenHandle(this)->SetInternalField(index, *proxy); | 3044 Utils::OpenHandle(this)->SetInternalField(index, *proxy); |
| 3048 } | 3045 } |
| 3049 | 3046 |
| 3050 | 3047 |
| 3051 // --- E n v i r o n m e n t --- | 3048 // --- E n v i r o n m e n t --- |
| 3052 | 3049 |
| 3053 bool v8::V8::Initialize() { | 3050 bool v8::V8::Initialize() { |
| 3054 if (i::V8::IsRunning()) return true; | 3051 if (i::V8::IsRunning()) return true; |
| 3055 ENTER_V8; | 3052 ENTER_V8; |
| 3056 HandleScope scope; | 3053 if(i::Snapshot::Initialize()) return true; |
| 3057 if (i::Snapshot::Initialize()) return true; | |
| 3058 return i::V8::Initialize(NULL); | 3054 return i::V8::Initialize(NULL); |
| 3059 } | 3055 } |
| 3060 | 3056 |
| 3061 | 3057 |
| 3062 bool v8::V8::Dispose() { | 3058 bool v8::V8::Dispose() { |
| 3063 i::V8::TearDown(); | 3059 i::V8::TearDown(); |
| 3064 return true; | 3060 return true; |
| 3065 } | 3061 } |
| 3066 | 3062 |
| 3067 | 3063 |
| (...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4374 } | 4370 } |
| 4375 | 4371 |
| 4376 | 4372 |
| 4377 char* HandleScopeImplementer::ArchiveThread(char* storage) { | 4373 char* HandleScopeImplementer::ArchiveThread(char* storage) { |
| 4378 return thread_local.ArchiveThreadHelper(storage); | 4374 return thread_local.ArchiveThreadHelper(storage); |
| 4379 } | 4375 } |
| 4380 | 4376 |
| 4381 | 4377 |
| 4382 char* HandleScopeImplementer::ArchiveThreadHelper(char* storage) { | 4378 char* HandleScopeImplementer::ArchiveThreadHelper(char* storage) { |
| 4383 v8::ImplementationUtilities::HandleScopeData* current = | 4379 v8::ImplementationUtilities::HandleScopeData* current = |
| 4384 v8::ImplementationUtilities::CurrentHandleScope(); | 4380 Isolate::Current()->handle_scope_data(); |
| 4385 handle_scope_data_ = *current; | 4381 handle_scope_data_ = *current; |
| 4386 memcpy(storage, this, sizeof(*this)); | 4382 memcpy(storage, this, sizeof(*this)); |
| 4387 | 4383 |
| 4388 ResetAfterArchive(); | 4384 ResetAfterArchive(); |
| 4389 current->Initialize(); | 4385 current->Initialize(); |
| 4390 | 4386 |
| 4391 return storage + ArchiveSpacePerThread(); | 4387 return storage + ArchiveSpacePerThread(); |
| 4392 } | 4388 } |
| 4393 | 4389 |
| 4394 | 4390 |
| 4395 int HandleScopeImplementer::ArchiveSpacePerThread() { | 4391 int HandleScopeImplementer::ArchiveSpacePerThread() { |
| 4396 return sizeof(thread_local); | 4392 return sizeof(thread_local); |
| 4397 } | 4393 } |
| 4398 | 4394 |
| 4399 | 4395 |
| 4400 char* HandleScopeImplementer::RestoreThread(char* storage) { | 4396 char* HandleScopeImplementer::RestoreThread(char* storage) { |
| 4401 return thread_local.RestoreThreadHelper(storage); | 4397 return thread_local.RestoreThreadHelper(storage); |
| 4402 } | 4398 } |
| 4403 | 4399 |
| 4404 | 4400 |
| 4405 char* HandleScopeImplementer::RestoreThreadHelper(char* storage) { | 4401 char* HandleScopeImplementer::RestoreThreadHelper(char* storage) { |
| 4406 memcpy(this, storage, sizeof(*this)); | 4402 memcpy(this, storage, sizeof(*this)); |
| 4407 *v8::ImplementationUtilities::CurrentHandleScope() = handle_scope_data_; | 4403 *Isolate::Current()->handle_scope_data() = handle_scope_data_; |
| 4408 return storage + ArchiveSpacePerThread(); | 4404 return storage + ArchiveSpacePerThread(); |
| 4409 } | 4405 } |
| 4410 | 4406 |
| 4411 | 4407 |
| 4412 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { | 4408 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { |
| 4413 // Iterate over all handles in the blocks except for the last. | 4409 // Iterate over all handles in the blocks except for the last. |
| 4414 for (int i = blocks()->length() - 2; i >= 0; --i) { | 4410 for (int i = blocks()->length() - 2; i >= 0; --i) { |
| 4415 Object** block = blocks()->at(i); | 4411 Object** block = blocks()->at(i); |
| 4416 v->VisitPointers(block, &block[kHandleBlockSize]); | 4412 v->VisitPointers(block, &block[kHandleBlockSize]); |
| 4417 } | 4413 } |
| 4418 | 4414 |
| 4419 // Iterate over live handles in the last block (if any). | 4415 // Iterate over live handles in the last block (if any). |
| 4420 if (!blocks()->is_empty()) { | 4416 if (!blocks()->is_empty()) { |
| 4421 v->VisitPointers(blocks()->last(), handle_scope_data_.next); | 4417 v->VisitPointers(blocks()->last(), handle_scope_data_.next); |
| 4422 } | 4418 } |
| 4423 | 4419 |
| 4424 if (!saved_contexts_.is_empty()) { | 4420 if (!saved_contexts_.is_empty()) { |
| 4425 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); | 4421 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); |
| 4426 v->VisitPointers(start, start + saved_contexts_.length()); | 4422 v->VisitPointers(start, start + saved_contexts_.length()); |
| 4427 } | 4423 } |
| 4428 } | 4424 } |
| 4429 | 4425 |
| 4430 | 4426 |
| 4431 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { | 4427 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { |
| 4432 v8::ImplementationUtilities::HandleScopeData* current = | 4428 v8::ImplementationUtilities::HandleScopeData* current = |
| 4433 v8::ImplementationUtilities::CurrentHandleScope(); | 4429 Isolate::Current()->handle_scope_data(); |
| 4434 thread_local.handle_scope_data_ = *current; | 4430 thread_local.handle_scope_data_ = *current; |
| 4435 thread_local.IterateThis(v); | 4431 thread_local.IterateThis(v); |
| 4436 } | 4432 } |
| 4437 | 4433 |
| 4438 | 4434 |
| 4439 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 4435 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
| 4440 HandleScopeImplementer* thread_local = | 4436 HandleScopeImplementer* thread_local = |
| 4441 reinterpret_cast<HandleScopeImplementer*>(storage); | 4437 reinterpret_cast<HandleScopeImplementer*>(storage); |
| 4442 thread_local->IterateThis(v); | 4438 thread_local->IterateThis(v); |
| 4443 return storage + ArchiveSpacePerThread(); | 4439 return storage + ArchiveSpacePerThread(); |
| 4444 } | 4440 } |
| 4445 | 4441 |
| 4446 } } // namespace v8::internal | 4442 } } // namespace v8::internal |
| OLD | NEW |