Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: src/api.h

Issue 10640012: Add a second kind of HandleScope that ties the lifetime of Handles created in its scope to the life… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix nits. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
395 // This class is here in order to be able to declare it a friend of 417 // This class is here in order to be able to declare it a friend of
396 // HandleScope. Moving these methods to be members of HandleScope would be 418 // HandleScope. Moving these methods to be members of HandleScope would be
397 // neat in some ways, but it would expose internal implementation details in 419 // neat in some ways, but it would expose internal implementation details in
398 // our public header file, which is undesirable. 420 // our public header file, which is undesirable.
399 // 421 //
400 // An isolate has a single instance of this class to hold the current thread's 422 // An isolate has a single instance of this class to hold the current thread's
401 // data. In multithreaded V8 programs this data is copied in and out of storage 423 // data. In multithreaded V8 programs this data is copied in and out of storage
402 // so that the currently executing thread always has its own copy of this 424 // so that the currently executing thread always has its own copy of this
403 // data. 425 // data.
404 class HandleScopeImplementer { 426 class HandleScopeImplementer {
405 public: 427 public:
406 explicit HandleScopeImplementer(Isolate* isolate) 428 explicit HandleScopeImplementer(Isolate* isolate)
407 : isolate_(isolate), 429 : isolate_(isolate),
408 blocks_(0), 430 blocks_(0),
409 entered_contexts_(0), 431 entered_contexts_(0),
410 saved_contexts_(0), 432 saved_contexts_(0),
411 spare_(NULL), 433 spare_(NULL),
412 call_depth_(0) { } 434 call_depth_(0),
435 last_handle_before_deferred_block_(NULL),
436 deferred_handles_head_(NULL) { }
413 437
414 ~HandleScopeImplementer() { 438 ~HandleScopeImplementer() {
415 DeleteArray(spare_); 439 DeleteArray(spare_);
416 } 440 }
417 441
418 // Threading support for handle data. 442 // Threading support for handle data.
419 static int ArchiveSpacePerThread(); 443 static int ArchiveSpacePerThread();
420 char* RestoreThread(char* from); 444 char* RestoreThread(char* from);
421 char* ArchiveThread(char* to); 445 char* ArchiveThread(char* to);
422 void FreeThreadResources(); 446 void FreeThreadResources();
(...skipping 15 matching lines...) Expand all
438 462
439 // Returns the last entered context or an empty handle if no 463 // Returns the last entered context or an empty handle if no
440 // contexts have been entered. 464 // contexts have been entered.
441 inline Handle<Object> LastEnteredContext(); 465 inline Handle<Object> LastEnteredContext();
442 466
443 inline void SaveContext(Context* context); 467 inline void SaveContext(Context* context);
444 inline Context* RestoreContext(); 468 inline Context* RestoreContext();
445 inline bool HasSavedContexts(); 469 inline bool HasSavedContexts();
446 470
447 inline List<internal::Object**>* blocks() { return &blocks_; } 471 inline List<internal::Object**>* blocks() { return &blocks_; }
472 Isolate* isolate() const { return isolate_; }
448 473
449 private: 474 private:
450 void ResetAfterArchive() { 475 void ResetAfterArchive() {
451 blocks_.Initialize(0); 476 blocks_.Initialize(0);
452 entered_contexts_.Initialize(0); 477 entered_contexts_.Initialize(0);
453 saved_contexts_.Initialize(0); 478 saved_contexts_.Initialize(0);
454 spare_ = NULL; 479 spare_ = NULL;
455 call_depth_ = 0; 480 call_depth_ = 0;
456 } 481 }
457 482
458 void Free() { 483 void Free() {
459 ASSERT(blocks_.length() == 0); 484 ASSERT(blocks_.length() == 0);
460 ASSERT(entered_contexts_.length() == 0); 485 ASSERT(entered_contexts_.length() == 0);
461 ASSERT(saved_contexts_.length() == 0); 486 ASSERT(saved_contexts_.length() == 0);
462 blocks_.Free(); 487 blocks_.Free();
463 entered_contexts_.Free(); 488 entered_contexts_.Free();
464 saved_contexts_.Free(); 489 saved_contexts_.Free();
465 if (spare_ != NULL) { 490 if (spare_ != NULL) {
466 DeleteArray(spare_); 491 DeleteArray(spare_);
467 spare_ = NULL; 492 spare_ = NULL;
468 } 493 }
469 ASSERT(call_depth_ == 0); 494 ASSERT(call_depth_ == 0);
470 } 495 }
471 496
497 void BeginDeferredScope();
498 DeferredHandles* Detach(Object** prev_limit);
499 void DestroyDeferredHandles(DeferredHandles* handles);
500
472 Isolate* isolate_; 501 Isolate* isolate_;
473 List<internal::Object**> blocks_; 502 List<internal::Object**> blocks_;
474 // Used as a stack to keep track of entered contexts. 503 // Used as a stack to keep track of entered contexts.
475 List<Handle<Object> > entered_contexts_; 504 List<Handle<Object> > entered_contexts_;
476 // Used as a stack to keep track of saved contexts. 505 // Used as a stack to keep track of saved contexts.
477 List<Context*> saved_contexts_; 506 List<Context*> saved_contexts_;
478 Object** spare_; 507 Object** spare_;
479 int call_depth_; 508 int call_depth_;
509 Object** last_handle_before_deferred_block_;
510 DeferredHandles* deferred_handles_head_;
480 // This is only used for threading support. 511 // This is only used for threading support.
481 v8::ImplementationUtilities::HandleScopeData handle_scope_data_; 512 v8::ImplementationUtilities::HandleScopeData handle_scope_data_;
482 513
483 void IterateThis(ObjectVisitor* v); 514 void IterateThis(ObjectVisitor* v);
484 char* RestoreThreadHelper(char* from); 515 char* RestoreThreadHelper(char* from);
485 char* ArchiveThreadHelper(char* to); 516 char* ArchiveThreadHelper(char* to);
486 517
518 friend class DeferredHandles;
519 friend class DeferredHandleScope;
520
487 DISALLOW_COPY_AND_ASSIGN(HandleScopeImplementer); 521 DISALLOW_COPY_AND_ASSIGN(HandleScopeImplementer);
488 }; 522 };
489 523
490 524
491 const int kHandleBlockSize = v8::internal::KB - 2; // fit in one page 525 const int kHandleBlockSize = v8::internal::KB - 2; // fit in one page
492 526
493 527
494 void HandleScopeImplementer::SaveContext(Context* context) { 528 void HandleScopeImplementer::SaveContext(Context* context) {
495 saved_contexts_.Add(context); 529 saved_contexts_.Add(context);
496 } 530 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 stress_type_ = stress_type; 600 stress_type_ = stress_type;
567 } 601 }
568 602
569 private: 603 private:
570 static v8::Testing::StressType stress_type_; 604 static v8::Testing::StressType stress_type_;
571 }; 605 };
572 606
573 } } // namespace v8::internal 607 } } // namespace v8::internal
574 608
575 #endif // V8_API_H_ 609 #endif // V8_API_H_
OLDNEW
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698