nsCycleCollectionTraversalCallback.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsCycleCollectionTraversalCallback_h__
  6. #define nsCycleCollectionTraversalCallback_h__
  7. #include "jspubtd.h"
  8. #include "js/HeapAPI.h"
  9. #include "nsISupports.h"
  10. class nsCycleCollectionParticipant;
  11. class NS_NO_VTABLE nsCycleCollectionTraversalCallback
  12. {
  13. public:
  14. // You must call DescribeRefCountedNode() with an accurate
  15. // refcount, otherwise cycle collection will fail, and probably crash.
  16. // If the callback cares about objname, it should put
  17. // WANT_DEBUG_INFO in mFlags.
  18. NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt aRefcount,
  19. const char* aObjName) = 0;
  20. // Note, aCompartmentAddress is 0 if it is unknown.
  21. NS_IMETHOD_(void) DescribeGCedNode(bool aIsMarked,
  22. const char* aObjName,
  23. uint64_t aCompartmentAddress = 0) = 0;
  24. NS_IMETHOD_(void) NoteXPCOMChild(nsISupports* aChild) = 0;
  25. NS_IMETHOD_(void) NoteJSChild(const JS::GCCellPtr& aThing) = 0;
  26. NS_IMETHOD_(void) NoteNativeChild(void* aChild,
  27. nsCycleCollectionParticipant* aHelper) = 0;
  28. // Give a name to the edge associated with the next call to
  29. // NoteXPCOMChild, NoteJSObject, NoteJSScript, or NoteNativeChild.
  30. // Callbacks who care about this should set WANT_DEBUG_INFO in the
  31. // flags.
  32. NS_IMETHOD_(void) NoteNextEdgeName(const char* aName) = 0;
  33. enum
  34. {
  35. // Values for flags:
  36. // Caller should call NoteNextEdgeName and pass useful objName
  37. // to DescribeRefCountedNode and DescribeGCedNode.
  38. WANT_DEBUG_INFO = (1 << 0),
  39. // Caller should not skip objects that we know will be
  40. // uncollectable.
  41. WANT_ALL_TRACES = (1 << 1)
  42. };
  43. uint32_t Flags() const { return mFlags; }
  44. bool WantDebugInfo() const { return (mFlags & WANT_DEBUG_INFO) != 0; }
  45. bool WantAllTraces() const { return (mFlags & WANT_ALL_TRACES) != 0; }
  46. protected:
  47. nsCycleCollectionTraversalCallback() : mFlags(0) {}
  48. uint32_t mFlags;
  49. };
  50. #endif // nsCycleCollectionTraversalCallback_h__