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

Side by Side Diff: Source/platform/heap/Visitor.h

Issue 783513002: Oilpan: add eager tracing stack depth checks. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove redundant empty line Created 6 years 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 505
506 #if ENABLE(GC_PROFILE_MARKING) 506 #if ENABLE(GC_PROFILE_MARKING)
507 void setHostInfo(void* object, const String& name) 507 void setHostInfo(void* object, const String& name)
508 { 508 {
509 m_hostObject = object; 509 m_hostObject = object;
510 m_hostName = name; 510 m_hostName = name;
511 } 511 }
512 #endif 512 #endif
513 513
514 protected: 514 protected:
515 Visitor()
516 : m_traceDepth(0)
517 {
518 }
519
515 virtual void registerWeakCell(void**, WeakPointerCallback) = 0; 520 virtual void registerWeakCell(void**, WeakPointerCallback) = 0;
516 #if ENABLE(GC_PROFILE_MARKING) 521 #if ENABLE(GC_PROFILE_MARKING)
517 void* m_hostObject; 522 void* m_hostObject;
518 String m_hostName; 523 String m_hostName;
519 #endif 524 #endif
520 525
521 private: 526 private:
522 template<typename T> 527 template<typename T>
523 static void handleWeakCell(Visitor* self, void* obj) 528 static void handleWeakCell(Visitor* self, void* obj)
524 { 529 {
525 T** cell = reinterpret_cast<T**>(obj); 530 T** cell = reinterpret_cast<T**>(obj);
526 if (*cell && !self->isAlive(*cell)) 531 if (*cell && !self->isAlive(*cell))
527 *cell = 0; 532 *cell = 0;
528 } 533 }
534
535 // The maximum depth of eager, unrolled trace() calls that is
haraken 2014/12/04 15:45:09 is => are
sof 2014/12/04 20:15:44 The maximum depth ... is
536 // considered safe and allowed.
537 const int kMaxEagerTraceDepth = 100;
538
539 template<typename U, bool>friend class DefaultTraceTrait;
haraken 2014/12/04 15:45:09 Add one space after '>'
sof 2014/12/04 20:15:44 Done.
540
541 inline bool canTraceEagerly() const { return m_traceDepth < kMaxEagerTraceDe pth; }
542 inline void incTraceDepth() { m_traceDepth++; }
haraken 2014/12/04 15:45:09 incrementTraceDepth
sof 2014/12/04 20:15:43 Done.
543 inline void decTraceDepth() { ASSERT(m_traceDepth > 0); m_traceDepth--; }
haraken 2014/12/04 15:45:09 decrementTraceDepth
sof 2014/12/04 20:15:44 Done.
544
545 int m_traceDepth;
529 }; 546 };
530 547
531 // We trace vectors by using the trace trait on each element, which means you 548 // We trace vectors by using the trace trait on each element, which means you
532 // can have vectors of general objects (not just pointers to objects) that can 549 // can have vectors of general objects (not just pointers to objects) that can
533 // be traced. 550 // be traced.
534 template<typename T, size_t N> 551 template<typename T, size_t N>
535 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > { 552 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > {
536 typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector; 553 typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector;
537 554
538 static void trace(Visitor* visitor, const Vector& vector) 555 static void trace(Visitor* visitor, const Vector& vector)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 static void mark(Visitor* visitor, const T* t) 589 static void mark(Visitor* visitor, const T* t)
573 { 590 {
574 // Default mark method of the trait just calls the two-argument mark 591 // Default mark method of the trait just calls the two-argument mark
575 // method on the visitor. The second argument is the static trace method 592 // method on the visitor. The second argument is the static trace method
576 // of the trait, which by default calls the instance method 593 // of the trait, which by default calls the instance method
577 // trace(Visitor*) on the object. 594 // trace(Visitor*) on the object.
578 // 595 //
579 // If the trait allows it, invoke the trace callback right here on the 596 // If the trait allows it, invoke the trace callback right here on the
580 // not-yet-marked object. 597 // not-yet-marked object.
581 if (!DISABLE_ALL_EAGER_TRACING && TraceEagerlyTrait<T>::value) { 598 if (!DISABLE_ALL_EAGER_TRACING && TraceEagerlyTrait<T>::value) {
582 if (visitor->ensureMarked(t)) 599 // Protect against too deep trace call chains, and the
583 TraceTrait<T>::trace(visitor, const_cast<T*>(t)); 600 // unbounded system stack usage they can bring about.
584 return; 601 //
602 // Assert against deep stacks so as to flush them out,
603 // but test and appropriately handle them should they occur
604 // in release builds.
605 ASSERT(visitor->canTraceEagerly());
606 if (visitor->canTraceEagerly()) {
haraken 2014/12/04 15:45:09 LIKELY just in case? Not sure.
sof 2014/12/04 20:15:44 Good idea; I had that when initially evaluating th
607 if (visitor->ensureMarked(t)) {
608 visitor->incTraceDepth();
609 TraceTrait<T>::trace(visitor, const_cast<T*>(t));
610 visitor->decTraceDepth();
611 }
612 return;
613 }
585 } 614 }
586 visitor->mark(const_cast<T*>(t), &TraceTrait<T>::trace); 615 visitor->mark(const_cast<T*>(t), &TraceTrait<T>::trace);
587 } 616 }
588 617
589 #if ENABLE(ASSERT) 618 #if ENABLE(ASSERT)
590 static void checkGCInfo(Visitor* visitor, const T* t) 619 static void checkGCInfo(Visitor* visitor, const T* t)
591 { 620 {
592 visitor->checkGCInfo(const_cast<T*>(t), GCInfoTrait<T>::get()); 621 visitor->checkGCInfo(const_cast<T*>(t), GCInfoTrait<T>::get());
593 } 622 }
594 #endif 623 #endif
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 struct GCInfoTrait { 770 struct GCInfoTrait {
742 static const GCInfo* get() 771 static const GCInfo* get()
743 { 772 {
744 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); 773 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get();
745 } 774 }
746 }; 775 };
747 776
748 } 777 }
749 778
750 #endif 779 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698