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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 inline bool IsEmpty() { return top_ == bottom_; } | 198 inline bool IsEmpty() { return top_ == bottom_; } |
199 | 199 |
200 bool overflowed() const { return overflowed_; } | 200 bool overflowed() const { return overflowed_; } |
201 | 201 |
202 bool in_use() const { return in_use_; } | 202 bool in_use() const { return in_use_; } |
203 | 203 |
204 void ClearOverflowed() { overflowed_ = false; } | 204 void ClearOverflowed() { overflowed_ = false; } |
205 | 205 |
206 void SetOverflowed() { overflowed_ = true; } | 206 void SetOverflowed() { overflowed_ = true; } |
207 | 207 |
208 void DecrementLiveBytes(HeapObject* object); | |
Hannes Payer (out of office)
2015/08/14 05:05:48
This method does not really belong to MarkingDeque
Michael Starzinger
2015/08/14 07:56:23
Acknowledged. Yes, you are right. As per offline d
| |
209 | |
208 // Push the (marked) object on the marking stack if there is room, | 210 // Push the (marked) object on the marking stack if there is room, |
209 // otherwise mark the object as overflowed and wait for a rescan of the | 211 // otherwise mark the object as overflowed and wait for a rescan of the |
210 // heap. | 212 // heap. |
211 INLINE(void PushBlack(HeapObject* object)) { | 213 INLINE(void PushBlack(HeapObject* object)) { |
212 DCHECK(object->IsHeapObject()); | 214 DCHECK(object->IsHeapObject()); |
213 if (IsFull()) { | 215 if (IsFull()) { |
214 Marking::BlackToGrey(object); | 216 Marking::BlackToGrey(object); |
215 MemoryChunk::IncrementLiveBytesFromGC(object, -object->Size()); | 217 DecrementLiveBytes(object); |
216 SetOverflowed(); | 218 SetOverflowed(); |
217 } else { | 219 } else { |
218 array_[top_] = object; | 220 array_[top_] = object; |
219 top_ = ((top_ + 1) & mask_); | 221 top_ = ((top_ + 1) & mask_); |
220 } | 222 } |
221 } | 223 } |
222 | 224 |
223 INLINE(void PushGrey(HeapObject* object)) { | 225 INLINE(void PushGrey(HeapObject* object)) { |
224 DCHECK(object->IsHeapObject()); | 226 DCHECK(object->IsHeapObject()); |
225 if (IsFull()) { | 227 if (IsFull()) { |
(...skipping 20 matching lines...) Expand all Loading... | |
246 bottom_ = ((bottom_ - 1) & mask_); | 248 bottom_ = ((bottom_ - 1) & mask_); |
247 array_[bottom_] = object; | 249 array_[bottom_] = object; |
248 } | 250 } |
249 } | 251 } |
250 | 252 |
251 INLINE(void UnshiftBlack(HeapObject* object)) { | 253 INLINE(void UnshiftBlack(HeapObject* object)) { |
252 DCHECK(object->IsHeapObject()); | 254 DCHECK(object->IsHeapObject()); |
253 DCHECK(Marking::IsBlack(Marking::MarkBitFrom(object))); | 255 DCHECK(Marking::IsBlack(Marking::MarkBitFrom(object))); |
254 if (IsFull()) { | 256 if (IsFull()) { |
255 Marking::BlackToGrey(object); | 257 Marking::BlackToGrey(object); |
256 MemoryChunk::IncrementLiveBytesFromGC(object, -object->Size()); | 258 DecrementLiveBytes(object); |
257 SetOverflowed(); | 259 SetOverflowed(); |
258 } else { | 260 } else { |
259 bottom_ = ((bottom_ - 1) & mask_); | 261 bottom_ = ((bottom_ - 1) & mask_); |
260 array_[bottom_] = object; | 262 array_[bottom_] = object; |
261 } | 263 } |
262 } | 264 } |
263 | 265 |
264 HeapObject** array() { return array_; } | 266 HeapObject** array() { return array_; } |
265 int bottom() { return bottom_; } | 267 int bottom() { return bottom_; } |
266 int top() { return top_; } | 268 int top() { return top_; } |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 // optimized or inlined into optimized code, because we might bailout | 454 // optimized or inlined into optimized code, because we might bailout |
453 // into the unoptimized code again during deoptimization. | 455 // into the unoptimized code again during deoptimization. |
454 class CodeFlusher { | 456 class CodeFlusher { |
455 public: | 457 public: |
456 explicit CodeFlusher(Isolate* isolate) | 458 explicit CodeFlusher(Isolate* isolate) |
457 : isolate_(isolate), | 459 : isolate_(isolate), |
458 jsfunction_candidates_head_(NULL), | 460 jsfunction_candidates_head_(NULL), |
459 shared_function_info_candidates_head_(NULL), | 461 shared_function_info_candidates_head_(NULL), |
460 optimized_code_map_holder_head_(NULL) {} | 462 optimized_code_map_holder_head_(NULL) {} |
461 | 463 |
462 void AddCandidate(SharedFunctionInfo* shared_info) { | 464 inline void AddCandidate(SharedFunctionInfo* shared_info); |
463 if (GetNextCandidate(shared_info) == NULL) { | 465 inline void AddCandidate(JSFunction* function); |
464 SetNextCandidate(shared_info, shared_function_info_candidates_head_); | 466 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 | 467 |
484 void EvictOptimizedCodeMap(SharedFunctionInfo* code_map_holder); | 468 void EvictOptimizedCodeMap(SharedFunctionInfo* code_map_holder); |
485 void EvictCandidate(SharedFunctionInfo* shared_info); | 469 void EvictCandidate(SharedFunctionInfo* shared_info); |
486 void EvictCandidate(JSFunction* function); | 470 void EvictCandidate(JSFunction* function); |
487 | 471 |
488 void ProcessCandidates() { | 472 void ProcessCandidates() { |
489 ProcessOptimizedCodeMaps(); | 473 ProcessOptimizedCodeMaps(); |
490 ProcessSharedFunctionInfoCandidates(); | 474 ProcessSharedFunctionInfoCandidates(); |
491 ProcessJSFunctionCandidates(); | 475 ProcessJSFunctionCandidates(); |
492 } | 476 } |
493 | 477 |
494 void EvictAllCandidates() { | 478 void EvictAllCandidates() { |
495 EvictOptimizedCodeMaps(); | 479 EvictOptimizedCodeMaps(); |
496 EvictJSFunctionCandidates(); | 480 EvictJSFunctionCandidates(); |
497 EvictSharedFunctionInfoCandidates(); | 481 EvictSharedFunctionInfoCandidates(); |
498 } | 482 } |
499 | 483 |
500 void IteratePointersToFromSpace(ObjectVisitor* v); | 484 void IteratePointersToFromSpace(ObjectVisitor* v); |
501 | 485 |
502 private: | 486 private: |
503 void ProcessOptimizedCodeMaps(); | 487 void ProcessOptimizedCodeMaps(); |
504 void ProcessJSFunctionCandidates(); | 488 void ProcessJSFunctionCandidates(); |
505 void ProcessSharedFunctionInfoCandidates(); | 489 void ProcessSharedFunctionInfoCandidates(); |
506 void EvictOptimizedCodeMaps(); | 490 void EvictOptimizedCodeMaps(); |
507 void EvictJSFunctionCandidates(); | 491 void EvictJSFunctionCandidates(); |
508 void EvictSharedFunctionInfoCandidates(); | 492 void EvictSharedFunctionInfoCandidates(); |
509 | 493 |
510 static JSFunction** GetNextCandidateSlot(JSFunction* candidate) { | 494 static inline JSFunction** GetNextCandidateSlot(JSFunction* candidate); |
511 return reinterpret_cast<JSFunction**>( | 495 static inline JSFunction* GetNextCandidate(JSFunction* candidate); |
512 HeapObject::RawField(candidate, JSFunction::kNextFunctionLinkOffset)); | 496 static inline void SetNextCandidate(JSFunction* candidate, |
513 } | 497 JSFunction* next_candidate); |
498 static inline void ClearNextCandidate(JSFunction* candidate, | |
499 Object* undefined); | |
514 | 500 |
515 static JSFunction* GetNextCandidate(JSFunction* candidate) { | 501 static inline SharedFunctionInfo* GetNextCandidate( |
516 Object* next_candidate = candidate->next_function_link(); | 502 SharedFunctionInfo* candidate); |
517 return reinterpret_cast<JSFunction*>(next_candidate); | 503 static inline void SetNextCandidate(SharedFunctionInfo* candidate, |
518 } | 504 SharedFunctionInfo* next_candidate); |
505 static inline void ClearNextCandidate(SharedFunctionInfo* candidate); | |
519 | 506 |
520 static void SetNextCandidate(JSFunction* candidate, | 507 static inline SharedFunctionInfo* GetNextCodeMap(SharedFunctionInfo* holder); |
521 JSFunction* next_candidate) { | 508 static inline void SetNextCodeMap(SharedFunctionInfo* holder, |
522 candidate->set_next_function_link(next_candidate, | 509 SharedFunctionInfo* next_holder); |
523 UPDATE_WEAK_WRITE_BARRIER); | 510 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 | 511 |
562 Isolate* isolate_; | 512 Isolate* isolate_; |
563 JSFunction* jsfunction_candidates_head_; | 513 JSFunction* jsfunction_candidates_head_; |
564 SharedFunctionInfo* shared_function_info_candidates_head_; | 514 SharedFunctionInfo* shared_function_info_candidates_head_; |
565 SharedFunctionInfo* optimized_code_map_holder_head_; | 515 SharedFunctionInfo* optimized_code_map_holder_head_; |
566 | 516 |
567 DISALLOW_COPY_AND_ASSIGN(CodeFlusher); | 517 DISALLOW_COPY_AND_ASSIGN(CodeFlusher); |
568 }; | 518 }; |
569 | 519 |
570 | 520 |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1033 private: | 983 private: |
1034 MarkCompactCollector* collector_; | 984 MarkCompactCollector* collector_; |
1035 }; | 985 }; |
1036 | 986 |
1037 | 987 |
1038 const char* AllocationSpaceName(AllocationSpace space); | 988 const char* AllocationSpaceName(AllocationSpace space); |
1039 } | 989 } |
1040 } // namespace v8::internal | 990 } // namespace v8::internal |
1041 | 991 |
1042 #endif // V8_HEAP_MARK_COMPACT_H_ | 992 #endif // V8_HEAP_MARK_COMPACT_H_ |
OLD | NEW |