| 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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 | 385 |
| 386 // The number of uses required to consider a string useful. | 386 // The number of uses required to consider a string useful. |
| 387 static const int kUseLimit = 32; | 387 static const int kUseLimit = 32; |
| 388 | 388 |
| 389 friend class Isolate; | 389 friend class Isolate; |
| 390 | 390 |
| 391 DISALLOW_COPY_AND_ASSIGN(StringTracker); | 391 DISALLOW_COPY_AND_ASSIGN(StringTracker); |
| 392 }; | 392 }; |
| 393 | 393 |
| 394 | 394 |
| 395 class DeferredHandles { | |
| 396 public: | |
| 397 ~DeferredHandles(); | |
| 398 | |
| 399 private: | |
| 400 DeferredHandles(DeferredHandles* next, Object** last_block_limit, | |
| 401 HandleScopeImplementer* impl) | |
| 402 : next_(next), previous_(NULL), last_block_limit_(last_block_limit), | |
| 403 impl_(impl) {} | |
| 404 | |
| 405 void Iterate(ObjectVisitor* v); | |
| 406 | |
| 407 List<Object**> blocks_; | |
| 408 DeferredHandles* next_; | |
| 409 DeferredHandles* previous_; | |
| 410 Object** last_block_limit_; | |
| 411 HandleScopeImplementer* impl_; | |
| 412 | |
| 413 friend class HandleScopeImplementer; | |
| 414 }; | |
| 415 | |
| 416 | |
| 417 // This class is here in order to be able to declare it a friend of | 395 // This class is here in order to be able to declare it a friend of |
| 418 // HandleScope. Moving these methods to be members of HandleScope would be | 396 // HandleScope. Moving these methods to be members of HandleScope would be |
| 419 // neat in some ways, but it would expose internal implementation details in | 397 // neat in some ways, but it would expose internal implementation details in |
| 420 // our public header file, which is undesirable. | 398 // our public header file, which is undesirable. |
| 421 // | 399 // |
| 422 // An isolate has a single instance of this class to hold the current thread's | 400 // An isolate has a single instance of this class to hold the current thread's |
| 423 // data. In multithreaded V8 programs this data is copied in and out of storage | 401 // data. In multithreaded V8 programs this data is copied in and out of storage |
| 424 // so that the currently executing thread always has its own copy of this | 402 // so that the currently executing thread always has its own copy of this |
| 425 // data. | 403 // data. |
| 426 class HandleScopeImplementer { | 404 class HandleScopeImplementer { |
| 427 public: | 405 public: |
| 428 explicit HandleScopeImplementer(Isolate* isolate) | 406 explicit HandleScopeImplementer(Isolate* isolate) |
| 429 : isolate_(isolate), | 407 : isolate_(isolate), |
| 430 blocks_(0), | 408 blocks_(0), |
| 431 entered_contexts_(0), | 409 entered_contexts_(0), |
| 432 saved_contexts_(0), | 410 saved_contexts_(0), |
| 433 spare_(NULL), | 411 spare_(NULL), |
| 434 call_depth_(0), | 412 call_depth_(0) { } |
| 435 last_handle_before_deferred_block_(NULL), | |
| 436 deferred_handles_head_(NULL) { } | |
| 437 | 413 |
| 438 ~HandleScopeImplementer() { | 414 ~HandleScopeImplementer() { |
| 439 DeleteArray(spare_); | 415 DeleteArray(spare_); |
| 440 } | 416 } |
| 441 | 417 |
| 442 // Threading support for handle data. | 418 // Threading support for handle data. |
| 443 static int ArchiveSpacePerThread(); | 419 static int ArchiveSpacePerThread(); |
| 444 char* RestoreThread(char* from); | 420 char* RestoreThread(char* from); |
| 445 char* ArchiveThread(char* to); | 421 char* ArchiveThread(char* to); |
| 446 void FreeThreadResources(); | 422 void FreeThreadResources(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 462 | 438 |
| 463 // Returns the last entered context or an empty handle if no | 439 // Returns the last entered context or an empty handle if no |
| 464 // contexts have been entered. | 440 // contexts have been entered. |
| 465 inline Handle<Object> LastEnteredContext(); | 441 inline Handle<Object> LastEnteredContext(); |
| 466 | 442 |
| 467 inline void SaveContext(Context* context); | 443 inline void SaveContext(Context* context); |
| 468 inline Context* RestoreContext(); | 444 inline Context* RestoreContext(); |
| 469 inline bool HasSavedContexts(); | 445 inline bool HasSavedContexts(); |
| 470 | 446 |
| 471 inline List<internal::Object**>* blocks() { return &blocks_; } | 447 inline List<internal::Object**>* blocks() { return &blocks_; } |
| 472 Isolate* isolate() const { return isolate_; } | |
| 473 | 448 |
| 474 private: | 449 private: |
| 475 void ResetAfterArchive() { | 450 void ResetAfterArchive() { |
| 476 blocks_.Initialize(0); | 451 blocks_.Initialize(0); |
| 477 entered_contexts_.Initialize(0); | 452 entered_contexts_.Initialize(0); |
| 478 saved_contexts_.Initialize(0); | 453 saved_contexts_.Initialize(0); |
| 479 spare_ = NULL; | 454 spare_ = NULL; |
| 480 call_depth_ = 0; | 455 call_depth_ = 0; |
| 481 } | 456 } |
| 482 | 457 |
| 483 void Free() { | 458 void Free() { |
| 484 ASSERT(blocks_.length() == 0); | 459 ASSERT(blocks_.length() == 0); |
| 485 ASSERT(entered_contexts_.length() == 0); | 460 ASSERT(entered_contexts_.length() == 0); |
| 486 ASSERT(saved_contexts_.length() == 0); | 461 ASSERT(saved_contexts_.length() == 0); |
| 487 blocks_.Free(); | 462 blocks_.Free(); |
| 488 entered_contexts_.Free(); | 463 entered_contexts_.Free(); |
| 489 saved_contexts_.Free(); | 464 saved_contexts_.Free(); |
| 490 if (spare_ != NULL) { | 465 if (spare_ != NULL) { |
| 491 DeleteArray(spare_); | 466 DeleteArray(spare_); |
| 492 spare_ = NULL; | 467 spare_ = NULL; |
| 493 } | 468 } |
| 494 ASSERT(call_depth_ == 0); | 469 ASSERT(call_depth_ == 0); |
| 495 } | 470 } |
| 496 | 471 |
| 497 void BeginDeferredScope(); | |
| 498 DeferredHandles* Detach(Object** prev_limit); | |
| 499 void DestroyDeferredHandles(DeferredHandles* handles); | |
| 500 | |
| 501 Isolate* isolate_; | 472 Isolate* isolate_; |
| 502 List<internal::Object**> blocks_; | 473 List<internal::Object**> blocks_; |
| 503 // Used as a stack to keep track of entered contexts. | 474 // Used as a stack to keep track of entered contexts. |
| 504 List<Handle<Object> > entered_contexts_; | 475 List<Handle<Object> > entered_contexts_; |
| 505 // Used as a stack to keep track of saved contexts. | 476 // Used as a stack to keep track of saved contexts. |
| 506 List<Context*> saved_contexts_; | 477 List<Context*> saved_contexts_; |
| 507 Object** spare_; | 478 Object** spare_; |
| 508 int call_depth_; | 479 int call_depth_; |
| 509 Object** last_handle_before_deferred_block_; | |
| 510 DeferredHandles* deferred_handles_head_; | |
| 511 // This is only used for threading support. | 480 // This is only used for threading support. |
| 512 v8::ImplementationUtilities::HandleScopeData handle_scope_data_; | 481 v8::ImplementationUtilities::HandleScopeData handle_scope_data_; |
| 513 | 482 |
| 514 void IterateThis(ObjectVisitor* v); | 483 void IterateThis(ObjectVisitor* v); |
| 515 char* RestoreThreadHelper(char* from); | 484 char* RestoreThreadHelper(char* from); |
| 516 char* ArchiveThreadHelper(char* to); | 485 char* ArchiveThreadHelper(char* to); |
| 517 | 486 |
| 518 friend class DeferredHandles; | |
| 519 friend class DeferredHandleScope; | |
| 520 | |
| 521 DISALLOW_COPY_AND_ASSIGN(HandleScopeImplementer); | 487 DISALLOW_COPY_AND_ASSIGN(HandleScopeImplementer); |
| 522 }; | 488 }; |
| 523 | 489 |
| 524 | 490 |
| 525 const int kHandleBlockSize = v8::internal::KB - 2; // fit in one page | 491 const int kHandleBlockSize = v8::internal::KB - 2; // fit in one page |
| 526 | 492 |
| 527 | 493 |
| 528 void HandleScopeImplementer::SaveContext(Context* context) { | 494 void HandleScopeImplementer::SaveContext(Context* context) { |
| 529 saved_contexts_.Add(context); | 495 saved_contexts_.Add(context); |
| 530 } | 496 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 stress_type_ = stress_type; | 566 stress_type_ = stress_type; |
| 601 } | 567 } |
| 602 | 568 |
| 603 private: | 569 private: |
| 604 static v8::Testing::StressType stress_type_; | 570 static v8::Testing::StressType stress_type_; |
| 605 }; | 571 }; |
| 606 | 572 |
| 607 } } // namespace v8::internal | 573 } } // namespace v8::internal |
| 608 | 574 |
| 609 #endif // V8_API_H_ | 575 #endif // V8_API_H_ |
| OLD | NEW |