Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 | 390 |
| 391 DISALLOW_COPY_AND_ASSIGN(StringTracker); | 391 DISALLOW_COPY_AND_ASSIGN(StringTracker); |
| 392 }; | 392 }; |
| 393 | 393 |
| 394 | 394 |
| 395 class DeferredHandles { | 395 class DeferredHandles { |
| 396 public: | 396 public: |
| 397 ~DeferredHandles(); | 397 ~DeferredHandles(); |
| 398 | 398 |
| 399 private: | 399 private: |
| 400 DeferredHandles(DeferredHandles* next, Object** first_block_limit, | 400 DeferredHandles(Object** first_block_limit, Isolate* isolate) |
| 401 HandleScopeImplementer* impl) | 401 : next_(isolate->deferred_handles_head_), |
| 402 : next_(next), | |
| 403 previous_(NULL), | 402 previous_(NULL), |
| 404 first_block_limit_(first_block_limit), | 403 first_block_limit_(first_block_limit), |
| 405 impl_(impl) { | 404 isolate_(isolate) { |
| 406 if (next != NULL) next->previous_ = this; | 405 if (next_ != NULL) next_->previous_ = this; |
| 406 isolate->deferred_handles_head_ = this; | |
|
danno
2012/07/18 13:36:17
I don't think you should reach into the isolate li
sanjoy
2012/07/18 14:00:43
Done.
| |
| 407 } | 407 } |
| 408 | 408 |
| 409 void Iterate(ObjectVisitor* v); | 409 void Iterate(ObjectVisitor* v); |
| 410 | 410 |
| 411 List<Object**> blocks_; | 411 List<Object**> blocks_; |
| 412 DeferredHandles* next_; | 412 DeferredHandles* next_; |
| 413 DeferredHandles* previous_; | 413 DeferredHandles* previous_; |
| 414 Object** first_block_limit_; | 414 Object** first_block_limit_; |
| 415 HandleScopeImplementer* impl_; | 415 Isolate* isolate_; |
| 416 | 416 |
| 417 friend class HandleScopeImplementer; | 417 friend class HandleScopeImplementer; |
| 418 friend class Isolate; | |
| 418 }; | 419 }; |
| 419 | 420 |
| 420 | 421 |
| 421 // This class is here in order to be able to declare it a friend of | 422 // This class is here in order to be able to declare it a friend of |
| 422 // HandleScope. Moving these methods to be members of HandleScope would be | 423 // HandleScope. Moving these methods to be members of HandleScope would be |
| 423 // neat in some ways, but it would expose internal implementation details in | 424 // neat in some ways, but it would expose internal implementation details in |
| 424 // our public header file, which is undesirable. | 425 // our public header file, which is undesirable. |
| 425 // | 426 // |
| 426 // An isolate has a single instance of this class to hold the current thread's | 427 // An isolate has a single instance of this class to hold the current thread's |
| 427 // data. In multithreaded V8 programs this data is copied in and out of storage | 428 // data. In multithreaded V8 programs this data is copied in and out of storage |
| 428 // so that the currently executing thread always has its own copy of this | 429 // so that the currently executing thread always has its own copy of this |
| 429 // data. | 430 // data. |
| 430 class HandleScopeImplementer { | 431 class HandleScopeImplementer { |
| 431 public: | 432 public: |
| 432 explicit HandleScopeImplementer(Isolate* isolate) | 433 explicit HandleScopeImplementer(Isolate* isolate) |
| 433 : isolate_(isolate), | 434 : isolate_(isolate), |
| 434 blocks_(0), | 435 blocks_(0), |
| 435 entered_contexts_(0), | 436 entered_contexts_(0), |
| 436 saved_contexts_(0), | 437 saved_contexts_(0), |
| 437 spare_(NULL), | 438 spare_(NULL), |
| 438 call_depth_(0), | 439 call_depth_(0), |
| 439 last_handle_before_deferred_block_(NULL), | 440 last_handle_before_deferred_block_(NULL) { } |
| 440 deferred_handles_head_(NULL) { } | |
| 441 | 441 |
| 442 ~HandleScopeImplementer() { | 442 ~HandleScopeImplementer() { |
| 443 DeleteArray(spare_); | 443 DeleteArray(spare_); |
| 444 } | 444 } |
| 445 | 445 |
| 446 // Threading support for handle data. | 446 // Threading support for handle data. |
| 447 static int ArchiveSpacePerThread(); | 447 static int ArchiveSpacePerThread(); |
| 448 char* RestoreThread(char* from); | 448 char* RestoreThread(char* from); |
| 449 char* ArchiveThread(char* to); | 449 char* ArchiveThread(char* to); |
| 450 void FreeThreadResources(); | 450 void FreeThreadResources(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 468 // contexts have been entered. | 468 // contexts have been entered. |
| 469 inline Handle<Object> LastEnteredContext(); | 469 inline Handle<Object> LastEnteredContext(); |
| 470 | 470 |
| 471 inline void SaveContext(Context* context); | 471 inline void SaveContext(Context* context); |
| 472 inline Context* RestoreContext(); | 472 inline Context* RestoreContext(); |
| 473 inline bool HasSavedContexts(); | 473 inline bool HasSavedContexts(); |
| 474 | 474 |
| 475 inline List<internal::Object**>* blocks() { return &blocks_; } | 475 inline List<internal::Object**>* blocks() { return &blocks_; } |
| 476 Isolate* isolate() const { return isolate_; } | 476 Isolate* isolate() const { return isolate_; } |
| 477 | 477 |
| 478 void ReturnBlock(Object** block) { | |
| 479 ASSERT(block != NULL); | |
| 480 if (spare_ != NULL) DeleteArray(spare_); | |
| 481 spare_ = block; | |
| 482 } | |
| 483 | |
| 478 private: | 484 private: |
| 479 void ResetAfterArchive() { | 485 void ResetAfterArchive() { |
| 480 blocks_.Initialize(0); | 486 blocks_.Initialize(0); |
| 481 entered_contexts_.Initialize(0); | 487 entered_contexts_.Initialize(0); |
| 482 saved_contexts_.Initialize(0); | 488 saved_contexts_.Initialize(0); |
| 483 spare_ = NULL; | 489 spare_ = NULL; |
| 484 deferred_handles_head_ = NULL; | |
| 485 last_handle_before_deferred_block_ = NULL; | 490 last_handle_before_deferred_block_ = NULL; |
| 486 call_depth_ = 0; | 491 call_depth_ = 0; |
| 487 } | 492 } |
| 488 | 493 |
| 489 void Free() { | 494 void Free() { |
| 490 ASSERT(blocks_.length() == 0); | 495 ASSERT(blocks_.length() == 0); |
| 491 ASSERT(entered_contexts_.length() == 0); | 496 ASSERT(entered_contexts_.length() == 0); |
| 492 ASSERT(saved_contexts_.length() == 0); | 497 ASSERT(saved_contexts_.length() == 0); |
| 493 ASSERT(deferred_handles_head_ == NULL); | |
| 494 blocks_.Free(); | 498 blocks_.Free(); |
| 495 entered_contexts_.Free(); | 499 entered_contexts_.Free(); |
| 496 saved_contexts_.Free(); | 500 saved_contexts_.Free(); |
| 497 if (spare_ != NULL) { | 501 if (spare_ != NULL) { |
| 498 DeleteArray(spare_); | 502 DeleteArray(spare_); |
| 499 spare_ = NULL; | 503 spare_ = NULL; |
| 500 } | 504 } |
| 501 ASSERT(call_depth_ == 0); | 505 ASSERT(call_depth_ == 0); |
| 502 } | 506 } |
| 503 | 507 |
| 504 void BeginDeferredScope(); | 508 void BeginDeferredScope(); |
| 505 DeferredHandles* Detach(Object** prev_limit); | 509 DeferredHandles* Detach(Object** prev_limit); |
| 506 void DestroyDeferredHandles(DeferredHandles* handles); | |
| 507 | 510 |
| 508 Isolate* isolate_; | 511 Isolate* isolate_; |
| 509 List<internal::Object**> blocks_; | 512 List<internal::Object**> blocks_; |
| 510 // Used as a stack to keep track of entered contexts. | 513 // Used as a stack to keep track of entered contexts. |
| 511 List<Handle<Object> > entered_contexts_; | 514 List<Handle<Object> > entered_contexts_; |
| 512 // Used as a stack to keep track of saved contexts. | 515 // Used as a stack to keep track of saved contexts. |
| 513 List<Context*> saved_contexts_; | 516 List<Context*> saved_contexts_; |
| 514 Object** spare_; | 517 Object** spare_; |
| 515 int call_depth_; | 518 int call_depth_; |
| 516 Object** last_handle_before_deferred_block_; | 519 Object** last_handle_before_deferred_block_; |
| 517 DeferredHandles* deferred_handles_head_; | |
| 518 // This is only used for threading support. | 520 // This is only used for threading support. |
| 519 v8::ImplementationUtilities::HandleScopeData handle_scope_data_; | 521 v8::ImplementationUtilities::HandleScopeData handle_scope_data_; |
| 520 | 522 |
| 521 void IterateThis(ObjectVisitor* v); | 523 void IterateThis(ObjectVisitor* v); |
| 522 char* RestoreThreadHelper(char* from); | 524 char* RestoreThreadHelper(char* from); |
| 523 char* ArchiveThreadHelper(char* to); | 525 char* ArchiveThreadHelper(char* to); |
| 524 | 526 |
| 525 friend class DeferredHandles; | 527 friend class DeferredHandles; |
| 526 friend class DeferredHandleScope; | 528 friend class DeferredHandleScope; |
| 527 | 529 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 stress_type_ = stress_type; | 609 stress_type_ = stress_type; |
| 608 } | 610 } |
| 609 | 611 |
| 610 private: | 612 private: |
| 611 static v8::Testing::StressType stress_type_; | 613 static v8::Testing::StressType stress_type_; |
| 612 }; | 614 }; |
| 613 | 615 |
| 614 } } // namespace v8::internal | 616 } } // namespace v8::internal |
| 615 | 617 |
| 616 #endif // V8_API_H_ | 618 #endif // V8_API_H_ |
| OLD | NEW |