| 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 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 private: | 425 private: |
| 426 static const int kChainLengthThreshold = 15; | 426 static const int kChainLengthThreshold = 15; |
| 427 | 427 |
| 428 intptr_t idx_; | 428 intptr_t idx_; |
| 429 intptr_t chain_length_; | 429 intptr_t chain_length_; |
| 430 SlotsBuffer* next_; | 430 SlotsBuffer* next_; |
| 431 ObjectSlot slots_[kNumberOfElements]; | 431 ObjectSlot slots_[kNumberOfElements]; |
| 432 }; | 432 }; |
| 433 | 433 |
| 434 | 434 |
| 435 // CodeFlusher collects candidates for code flushing during marking and |
| 436 // processes those candidates after marking has completed in order to |
| 437 // reset those functions referencing code objects that would otherwise |
| 438 // be unreachable. Code objects can be referenced in two ways: |
| 439 // - SharedFunctionInfo references unoptimized code. |
| 440 // - JSFunction references either unoptimized or optimized code. |
| 441 // We are not allowed to flush unoptimized code for functions that got |
| 442 // optimized or inlined into optimized code, because we might bailout |
| 443 // into the unoptimized code again during deoptimization. |
| 444 class CodeFlusher { |
| 445 public: |
| 446 explicit CodeFlusher(Isolate* isolate) |
| 447 : isolate_(isolate), |
| 448 jsfunction_candidates_head_(NULL), |
| 449 shared_function_info_candidates_head_(NULL) {} |
| 450 |
| 451 void AddCandidate(SharedFunctionInfo* shared_info) { |
| 452 SetNextCandidate(shared_info, shared_function_info_candidates_head_); |
| 453 shared_function_info_candidates_head_ = shared_info; |
| 454 } |
| 455 |
| 456 void AddCandidate(JSFunction* function) { |
| 457 ASSERT(function->code() == function->shared()->code()); |
| 458 SetNextCandidate(function, jsfunction_candidates_head_); |
| 459 jsfunction_candidates_head_ = function; |
| 460 } |
| 461 |
| 462 void ProcessCandidates() { |
| 463 ProcessSharedFunctionInfoCandidates(); |
| 464 ProcessJSFunctionCandidates(); |
| 465 } |
| 466 |
| 467 private: |
| 468 void ProcessJSFunctionCandidates(); |
| 469 void ProcessSharedFunctionInfoCandidates(); |
| 470 |
| 471 static JSFunction** GetNextCandidateField(JSFunction* candidate) { |
| 472 return reinterpret_cast<JSFunction**>( |
| 473 candidate->address() + JSFunction::kCodeEntryOffset); |
| 474 } |
| 475 |
| 476 static JSFunction* GetNextCandidate(JSFunction* candidate) { |
| 477 return *GetNextCandidateField(candidate); |
| 478 } |
| 479 |
| 480 static void SetNextCandidate(JSFunction* candidate, |
| 481 JSFunction* next_candidate) { |
| 482 *GetNextCandidateField(candidate) = next_candidate; |
| 483 } |
| 484 |
| 485 static SharedFunctionInfo** GetNextCandidateField( |
| 486 SharedFunctionInfo* candidate) { |
| 487 Code* code = candidate->code(); |
| 488 return reinterpret_cast<SharedFunctionInfo**>( |
| 489 code->address() + Code::kGCMetadataOffset); |
| 490 } |
| 491 |
| 492 static SharedFunctionInfo* GetNextCandidate(SharedFunctionInfo* candidate) { |
| 493 return reinterpret_cast<SharedFunctionInfo*>( |
| 494 candidate->code()->gc_metadata()); |
| 495 } |
| 496 |
| 497 static void SetNextCandidate(SharedFunctionInfo* candidate, |
| 498 SharedFunctionInfo* next_candidate) { |
| 499 candidate->code()->set_gc_metadata(next_candidate); |
| 500 } |
| 501 |
| 502 Isolate* isolate_; |
| 503 JSFunction* jsfunction_candidates_head_; |
| 504 SharedFunctionInfo* shared_function_info_candidates_head_; |
| 505 |
| 506 DISALLOW_COPY_AND_ASSIGN(CodeFlusher); |
| 507 }; |
| 508 |
| 509 |
| 435 // Defined in isolate.h. | 510 // Defined in isolate.h. |
| 436 class ThreadLocalTop; | 511 class ThreadLocalTop; |
| 437 | 512 |
| 438 | 513 |
| 439 // ------------------------------------------------------------------------- | 514 // ------------------------------------------------------------------------- |
| 440 // Mark-Compact collector | 515 // Mark-Compact collector |
| 441 class MarkCompactCollector { | 516 class MarkCompactCollector { |
| 442 public: | 517 public: |
| 443 // Type of functions to compute forwarding addresses of objects in | 518 // Type of functions to compute forwarding addresses of objects in |
| 444 // compacted spaces. Given an object and its size, return a (non-failure) | 519 // compacted spaces. Given an object and its size, return a (non-failure) |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 // normal state. | 731 // normal state. |
| 657 // | 732 // |
| 658 // After: Live objects are marked and non-live objects are unmarked. | 733 // After: Live objects are marked and non-live objects are unmarked. |
| 659 | 734 |
| 660 friend class RootMarkingVisitor; | 735 friend class RootMarkingVisitor; |
| 661 friend class MarkingVisitor; | 736 friend class MarkingVisitor; |
| 662 friend class MarkCompactMarkingVisitor; | 737 friend class MarkCompactMarkingVisitor; |
| 663 friend class CodeMarkingVisitor; | 738 friend class CodeMarkingVisitor; |
| 664 friend class SharedFunctionInfoMarkingVisitor; | 739 friend class SharedFunctionInfoMarkingVisitor; |
| 665 | 740 |
| 666 // Mark non-optimize code for functions inlined into the given optimized | |
| 667 // code. This will prevent it from being flushed. | |
| 668 void MarkInlinedFunctionsCode(Code* code); | |
| 669 | |
| 670 // Mark code objects that are active on the stack to prevent them | 741 // Mark code objects that are active on the stack to prevent them |
| 671 // from being flushed. | 742 // from being flushed. |
| 672 void PrepareThreadForCodeFlushing(Isolate* isolate, ThreadLocalTop* top); | 743 void PrepareThreadForCodeFlushing(Isolate* isolate, ThreadLocalTop* top); |
| 673 | 744 |
| 674 void PrepareForCodeFlushing(); | 745 void PrepareForCodeFlushing(); |
| 675 | 746 |
| 676 // Marking operations for objects reachable from roots. | 747 // Marking operations for objects reachable from roots. |
| 677 void MarkLiveObjects(); | 748 void MarkLiveObjects(); |
| 678 | 749 |
| 679 void AfterMarking(); | 750 void AfterMarking(); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 | 865 |
| 795 friend class Heap; | 866 friend class Heap; |
| 796 }; | 867 }; |
| 797 | 868 |
| 798 | 869 |
| 799 const char* AllocationSpaceName(AllocationSpace space); | 870 const char* AllocationSpaceName(AllocationSpace space); |
| 800 | 871 |
| 801 } } // namespace v8::internal | 872 } } // namespace v8::internal |
| 802 | 873 |
| 803 #endif // V8_MARK_COMPACT_H_ | 874 #endif // V8_MARK_COMPACT_H_ |
| OLD | NEW |