OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_HEAP_MARK_COMPACT_H_ | 5 #ifndef V8_HEAP_MARK_COMPACT_H_ |
6 #define V8_HEAP_MARK_COMPACT_H_ | 6 #define V8_HEAP_MARK_COMPACT_H_ |
7 | 7 |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/heap/spaces.h" | 9 #include "src/heap/spaces.h" |
10 | 10 |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 // optimized or inlined into optimized code, because we might bailout | 452 // optimized or inlined into optimized code, because we might bailout |
453 // into the unoptimized code again during deoptimization. | 453 // into the unoptimized code again during deoptimization. |
454 class CodeFlusher { | 454 class CodeFlusher { |
455 public: | 455 public: |
456 explicit CodeFlusher(Isolate* isolate) | 456 explicit CodeFlusher(Isolate* isolate) |
457 : isolate_(isolate), | 457 : isolate_(isolate), |
458 jsfunction_candidates_head_(NULL), | 458 jsfunction_candidates_head_(NULL), |
459 shared_function_info_candidates_head_(NULL), | 459 shared_function_info_candidates_head_(NULL), |
460 optimized_code_map_holder_head_(NULL) {} | 460 optimized_code_map_holder_head_(NULL) {} |
461 | 461 |
462 void AddCandidate(SharedFunctionInfo* shared_info) { | 462 inline void AddCandidate(SharedFunctionInfo* shared_info); |
463 if (GetNextCandidate(shared_info) == NULL) { | 463 inline void AddCandidate(JSFunction* function); |
464 SetNextCandidate(shared_info, shared_function_info_candidates_head_); | 464 inline void AddOptimizedCodeMap(SharedFunctionInfo* code_map_holder); |
465 shared_function_info_candidates_head_ = shared_info; | |
466 } | |
467 } | |
468 | |
469 void AddCandidate(JSFunction* function) { | |
470 DCHECK(function->code() == function->shared()->code()); | |
471 if (GetNextCandidate(function)->IsUndefined()) { | |
472 SetNextCandidate(function, jsfunction_candidates_head_); | |
473 jsfunction_candidates_head_ = function; | |
474 } | |
475 } | |
476 | |
477 void AddOptimizedCodeMap(SharedFunctionInfo* code_map_holder) { | |
478 if (GetNextCodeMap(code_map_holder)->IsUndefined()) { | |
479 SetNextCodeMap(code_map_holder, optimized_code_map_holder_head_); | |
480 optimized_code_map_holder_head_ = code_map_holder; | |
481 } | |
482 } | |
483 | 465 |
484 void EvictOptimizedCodeMap(SharedFunctionInfo* code_map_holder); | 466 void EvictOptimizedCodeMap(SharedFunctionInfo* code_map_holder); |
485 void EvictCandidate(SharedFunctionInfo* shared_info); | 467 void EvictCandidate(SharedFunctionInfo* shared_info); |
486 void EvictCandidate(JSFunction* function); | 468 void EvictCandidate(JSFunction* function); |
487 | 469 |
488 void ProcessCandidates() { | 470 void ProcessCandidates() { |
489 ProcessOptimizedCodeMaps(); | 471 ProcessOptimizedCodeMaps(); |
490 ProcessSharedFunctionInfoCandidates(); | 472 ProcessSharedFunctionInfoCandidates(); |
491 ProcessJSFunctionCandidates(); | 473 ProcessJSFunctionCandidates(); |
492 } | 474 } |
493 | 475 |
494 void EvictAllCandidates() { | 476 void EvictAllCandidates() { |
495 EvictOptimizedCodeMaps(); | 477 EvictOptimizedCodeMaps(); |
496 EvictJSFunctionCandidates(); | 478 EvictJSFunctionCandidates(); |
497 EvictSharedFunctionInfoCandidates(); | 479 EvictSharedFunctionInfoCandidates(); |
498 } | 480 } |
499 | 481 |
500 void IteratePointersToFromSpace(ObjectVisitor* v); | 482 void IteratePointersToFromSpace(ObjectVisitor* v); |
501 | 483 |
502 private: | 484 private: |
503 void ProcessOptimizedCodeMaps(); | 485 void ProcessOptimizedCodeMaps(); |
504 void ProcessJSFunctionCandidates(); | 486 void ProcessJSFunctionCandidates(); |
505 void ProcessSharedFunctionInfoCandidates(); | 487 void ProcessSharedFunctionInfoCandidates(); |
506 void EvictOptimizedCodeMaps(); | 488 void EvictOptimizedCodeMaps(); |
507 void EvictJSFunctionCandidates(); | 489 void EvictJSFunctionCandidates(); |
508 void EvictSharedFunctionInfoCandidates(); | 490 void EvictSharedFunctionInfoCandidates(); |
509 | 491 |
510 static JSFunction** GetNextCandidateSlot(JSFunction* candidate) { | 492 static inline JSFunction** GetNextCandidateSlot(JSFunction* candidate); |
511 return reinterpret_cast<JSFunction**>( | 493 static inline JSFunction* GetNextCandidate(JSFunction* candidate); |
512 HeapObject::RawField(candidate, JSFunction::kNextFunctionLinkOffset)); | 494 static inline void SetNextCandidate(JSFunction* candidate, |
513 } | 495 JSFunction* next_candidate); |
| 496 static inline void ClearNextCandidate(JSFunction* candidate, |
| 497 Object* undefined); |
514 | 498 |
515 static JSFunction* GetNextCandidate(JSFunction* candidate) { | 499 static inline SharedFunctionInfo* GetNextCandidate( |
516 Object* next_candidate = candidate->next_function_link(); | 500 SharedFunctionInfo* candidate); |
517 return reinterpret_cast<JSFunction*>(next_candidate); | 501 static inline void SetNextCandidate(SharedFunctionInfo* candidate, |
518 } | 502 SharedFunctionInfo* next_candidate); |
| 503 static inline void ClearNextCandidate(SharedFunctionInfo* candidate); |
519 | 504 |
520 static void SetNextCandidate(JSFunction* candidate, | 505 static inline SharedFunctionInfo* GetNextCodeMap(SharedFunctionInfo* holder); |
521 JSFunction* next_candidate) { | 506 static inline void SetNextCodeMap(SharedFunctionInfo* holder, |
522 candidate->set_next_function_link(next_candidate, | 507 SharedFunctionInfo* next_holder); |
523 UPDATE_WEAK_WRITE_BARRIER); | 508 static inline void ClearNextCodeMap(SharedFunctionInfo* holder); |
524 } | |
525 | |
526 static void ClearNextCandidate(JSFunction* candidate, Object* undefined) { | |
527 DCHECK(undefined->IsUndefined()); | |
528 candidate->set_next_function_link(undefined, SKIP_WRITE_BARRIER); | |
529 } | |
530 | |
531 static SharedFunctionInfo* GetNextCandidate(SharedFunctionInfo* candidate) { | |
532 Object* next_candidate = candidate->code()->gc_metadata(); | |
533 return reinterpret_cast<SharedFunctionInfo*>(next_candidate); | |
534 } | |
535 | |
536 static void SetNextCandidate(SharedFunctionInfo* candidate, | |
537 SharedFunctionInfo* next_candidate) { | |
538 candidate->code()->set_gc_metadata(next_candidate); | |
539 } | |
540 | |
541 static void ClearNextCandidate(SharedFunctionInfo* candidate) { | |
542 candidate->code()->set_gc_metadata(NULL, SKIP_WRITE_BARRIER); | |
543 } | |
544 | |
545 static SharedFunctionInfo* GetNextCodeMap(SharedFunctionInfo* holder) { | |
546 FixedArray* code_map = FixedArray::cast(holder->optimized_code_map()); | |
547 Object* next_map = code_map->get(SharedFunctionInfo::kNextMapIndex); | |
548 return reinterpret_cast<SharedFunctionInfo*>(next_map); | |
549 } | |
550 | |
551 static void SetNextCodeMap(SharedFunctionInfo* holder, | |
552 SharedFunctionInfo* next_holder) { | |
553 FixedArray* code_map = FixedArray::cast(holder->optimized_code_map()); | |
554 code_map->set(SharedFunctionInfo::kNextMapIndex, next_holder); | |
555 } | |
556 | |
557 static void ClearNextCodeMap(SharedFunctionInfo* holder) { | |
558 FixedArray* code_map = FixedArray::cast(holder->optimized_code_map()); | |
559 code_map->set_undefined(SharedFunctionInfo::kNextMapIndex); | |
560 } | |
561 | 509 |
562 Isolate* isolate_; | 510 Isolate* isolate_; |
563 JSFunction* jsfunction_candidates_head_; | 511 JSFunction* jsfunction_candidates_head_; |
564 SharedFunctionInfo* shared_function_info_candidates_head_; | 512 SharedFunctionInfo* shared_function_info_candidates_head_; |
565 SharedFunctionInfo* optimized_code_map_holder_head_; | 513 SharedFunctionInfo* optimized_code_map_holder_head_; |
566 | 514 |
567 DISALLOW_COPY_AND_ASSIGN(CodeFlusher); | 515 DISALLOW_COPY_AND_ASSIGN(CodeFlusher); |
568 }; | 516 }; |
569 | 517 |
570 | 518 |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 private: | 981 private: |
1034 MarkCompactCollector* collector_; | 982 MarkCompactCollector* collector_; |
1035 }; | 983 }; |
1036 | 984 |
1037 | 985 |
1038 const char* AllocationSpaceName(AllocationSpace space); | 986 const char* AllocationSpaceName(AllocationSpace space); |
1039 } | 987 } |
1040 } // namespace v8::internal | 988 } // namespace v8::internal |
1041 | 989 |
1042 #endif // V8_HEAP_MARK_COMPACT_H_ | 990 #endif // V8_HEAP_MARK_COMPACT_H_ |
OLD | NEW |