Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/base/nsISupportsImpl.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
// IWYU pragma: private, include "nsISupports.h"
7
8
9
#ifndef nsISupportsImpl_h__
10
#define nsISupportsImpl_h__
11
12
#include "nscore.h"
13
#include "nsISupportsBase.h"
14
#include "nsISupportsUtils.h"
15
16
#if !defined(XPCOM_GLUE_AVOID_NSPR)
17
#include "prthread.h" /* needed for cargo-culting headers */
18
#endif
19
20
#include "nsDebug.h"
21
#include "nsXPCOM.h"
22
#include <atomic>
23
#include "mozilla/Attributes.h"
24
#include "mozilla/Assertions.h"
25
#include "mozilla/Atomics.h"
26
#include "mozilla/Compiler.h"
27
#include "mozilla/Likely.h"
28
#include "mozilla/MacroArgs.h"
29
#include "mozilla/MacroForEach.h"
30
#include "mozilla/TypeTraits.h"
31
32
#define MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(X) \
33
3.57M
  static_assert(!mozilla::IsDestructible<X>::value, \
34
3.57M
                "Reference-counted class " #X " should not have a public destructor. " \
35
3.57M
                "Make this class's destructor non-public");
36
37
inline nsISupports*
38
ToSupports(nsISupports* aSupports)
39
{
40
  return aSupports;
41
}
42
43
////////////////////////////////////////////////////////////////////////////////
44
// Macros to help detect thread-safety:
45
46
#ifdef MOZ_THREAD_SAFETY_OWNERSHIP_CHECKS_SUPPORTED
47
48
#include "prthread.h" /* needed for thread-safety checks */
49
50
class nsAutoOwningThread
51
{
52
public:
53
  nsAutoOwningThread();
54
55
  // We move the actual assertion checks out-of-line to minimize code bloat,
56
  // but that means we have to pass a non-literal string to
57
  // MOZ_CRASH_UNSAFE_OOL.  To make that more safe, the public interface
58
  // requires a literal string and passes that to the private interface; we
59
  // can then be assured that we effectively are passing a literal string
60
  // to MOZ_CRASH_UNSAFE_OOL.
61
  template<int N>
62
  void AssertOwnership(const char (&aMsg)[N]) const
63
  {
64
    AssertCurrentThreadOwnsMe(aMsg);
65
  }
66
67
  bool IsCurrentThread() const;
68
69
private:
70
  void AssertCurrentThreadOwnsMe(const char* aMsg) const;
71
72
  void* mThread;
73
};
74
75
#define NS_DECL_OWNINGTHREAD            nsAutoOwningThread _mOwningThread;
76
#define NS_ASSERT_OWNINGTHREAD_AGGREGATE(agg, _class) \
77
  agg->_mOwningThread.AssertOwnership(#_class " not thread-safe")
78
#define NS_ASSERT_OWNINGTHREAD(_class) NS_ASSERT_OWNINGTHREAD_AGGREGATE(this, _class)
79
#else // !MOZ_THREAD_SAFETY_OWNERSHIP_CHECKS_SUPPORTED
80
81
#define NS_DECL_OWNINGTHREAD            /* nothing */
82
#define NS_ASSERT_OWNINGTHREAD_AGGREGATE(agg, _class) ((void)0)
83
793
#define NS_ASSERT_OWNINGTHREAD(_class)  ((void)0)
84
85
#endif // MOZ_THREAD_SAFETY_OWNERSHIP_CHECKS_SUPPORTED
86
87
88
// Macros for reference-count and constructor logging
89
90
#if defined(NS_BUILD_REFCNT_LOGGING)
91
92
#define NS_LOG_ADDREF(_p, _rc, _type, _size) \
93
  NS_LogAddRef((_p), (_rc), (_type), (uint32_t) (_size))
94
95
#define NS_LOG_RELEASE(_p, _rc, _type) \
96
  NS_LogRelease((_p), (_rc), (_type))
97
98
#include "mozilla/TypeTraits.h"
99
#define MOZ_ASSERT_CLASSNAME(_type)                         \
100
  static_assert(mozilla::IsClass<_type>::value,             \
101
                "Token '" #_type "' is not a class type.")
102
103
#define MOZ_ASSERT_NOT_ISUPPORTS(_type)                        \
104
  static_assert(!mozilla::IsBaseOf<nsISupports, _type>::value, \
105
                "nsISupports classes don't need to call MOZ_COUNT_CTOR or MOZ_COUNT_DTOR");
106
107
// Note that the following constructor/destructor logging macros are redundant
108
// for refcounted objects that log via the NS_LOG_ADDREF/NS_LOG_RELEASE macros.
109
// Refcount logging is preferred.
110
#define MOZ_COUNT_CTOR(_type)                                 \
111
do {                                                          \
112
  MOZ_ASSERT_CLASSNAME(_type);                                \
113
  MOZ_ASSERT_NOT_ISUPPORTS(_type);                            \
114
  NS_LogCtor((void*)this, #_type, sizeof(*this));             \
115
} while (0)
116
117
#define MOZ_COUNT_CTOR_INHERITED(_type, _base)                    \
118
do {                                                              \
119
  MOZ_ASSERT_CLASSNAME(_type);                                    \
120
  MOZ_ASSERT_CLASSNAME(_base);                                    \
121
  MOZ_ASSERT_NOT_ISUPPORTS(_type);                                \
122
  NS_LogCtor((void*)this, #_type, sizeof(*this) - sizeof(_base)); \
123
} while (0)
124
125
#define MOZ_LOG_CTOR(_ptr, _name, _size) \
126
do {                                     \
127
  NS_LogCtor((void*)_ptr, _name, _size); \
128
} while (0)
129
130
#define MOZ_COUNT_DTOR(_type)                                 \
131
do {                                                          \
132
  MOZ_ASSERT_CLASSNAME(_type);                                \
133
  MOZ_ASSERT_NOT_ISUPPORTS(_type);                            \
134
  NS_LogDtor((void*)this, #_type, sizeof(*this));             \
135
} while (0)
136
137
#define MOZ_COUNT_DTOR_INHERITED(_type, _base)                    \
138
do {                                                              \
139
  MOZ_ASSERT_CLASSNAME(_type);                                    \
140
  MOZ_ASSERT_CLASSNAME(_base);                                    \
141
  MOZ_ASSERT_NOT_ISUPPORTS(_type);                                \
142
  NS_LogDtor((void*)this, #_type, sizeof(*this) - sizeof(_base)); \
143
} while (0)
144
145
#define MOZ_LOG_DTOR(_ptr, _name, _size) \
146
do {                                     \
147
  NS_LogDtor((void*)_ptr, _name, _size); \
148
} while (0)
149
150
/* nsCOMPtr.h allows these macros to be defined by clients
151
 * These logging functions require dynamic_cast<void*>, so they don't
152
 * do anything useful if we don't have dynamic_cast<void*>.
153
 * Note: The explicit comparison to nullptr is needed to avoid warnings
154
 *       when _p is a nullptr itself. */
155
#define NSCAP_LOG_ASSIGNMENT(_c, _p)                                \
156
  if (_p != nullptr)                                                \
157
    NS_LogCOMPtrAddRef((_c),static_cast<nsISupports*>(_p))
158
159
#define NSCAP_LOG_RELEASE(_c, _p)                                   \
160
  if (_p)                                                           \
161
    NS_LogCOMPtrRelease((_c), static_cast<nsISupports*>(_p))
162
163
#else /* !NS_BUILD_REFCNT_LOGGING */
164
165
#define NS_LOG_ADDREF(_p, _rc, _type, _size)
166
#define NS_LOG_RELEASE(_p, _rc, _type)
167
#define MOZ_COUNT_CTOR(_type)
168
#define MOZ_COUNT_CTOR_INHERITED(_type, _base)
169
#define MOZ_LOG_CTOR(_ptr, _name, _size)
170
#define MOZ_COUNT_DTOR(_type)
171
#define MOZ_COUNT_DTOR_INHERITED(_type, _base)
172
#define MOZ_LOG_DTOR(_ptr, _name, _size)
173
174
#endif /* NS_BUILD_REFCNT_LOGGING */
175
176
177
// Support for ISupports classes which interact with cycle collector.
178
179
80.2M
#define NS_NUMBER_OF_FLAGS_IN_REFCNT 2
180
61.0M
#define NS_IN_PURPLE_BUFFER (1 << 0)
181
38.5M
#define NS_IS_PURPLE (1 << 1)
182
38.5M
#define NS_REFCOUNT_CHANGE (1 << NS_NUMBER_OF_FLAGS_IN_REFCNT)
183
41.6M
#define NS_REFCOUNT_VALUE(_val) (_val >> NS_NUMBER_OF_FLAGS_IN_REFCNT)
184
185
class nsCycleCollectingAutoRefCnt
186
{
187
public:
188
189
  typedef void (*Suspect)(void* aPtr,
190
                          nsCycleCollectionParticipant* aCp,
191
                          nsCycleCollectingAutoRefCnt* aRefCnt,
192
                          bool* aShouldDelete);
193
194
3.24M
  nsCycleCollectingAutoRefCnt() : mRefCntAndFlags(0) {}
195
196
  explicit nsCycleCollectingAutoRefCnt(uintptr_t aValue)
197
    : mRefCntAndFlags(aValue << NS_NUMBER_OF_FLAGS_IN_REFCNT)
198
  {
199
  }
200
201
  nsCycleCollectingAutoRefCnt(const nsCycleCollectingAutoRefCnt&) = delete;
202
  void operator=(const nsCycleCollectingAutoRefCnt&) = delete;
203
204
  template<Suspect suspect = NS_CycleCollectorSuspect3>
205
  MOZ_ALWAYS_INLINE uintptr_t incr(nsISupports* aOwner)
206
  {
207
    return incr<suspect>(aOwner, nullptr);
208
  }
209
210
  template<Suspect suspect = NS_CycleCollectorSuspect3>
211
  MOZ_ALWAYS_INLINE uintptr_t incr(void* aOwner,
212
                                   nsCycleCollectionParticipant* aCp)
213
19.3M
  {
214
19.3M
    mRefCntAndFlags += NS_REFCOUNT_CHANGE;
215
19.3M
    mRefCntAndFlags &= ~NS_IS_PURPLE;
216
19.3M
    // For incremental cycle collection, use the purple buffer to track objects
217
19.3M
    // that have been AddRef'd.
218
19.3M
    if (!IsInPurpleBuffer()) {
219
3.24M
      mRefCntAndFlags |= NS_IN_PURPLE_BUFFER;
220
3.24M
      // Refcount isn't zero, so Suspect won't delete anything.
221
3.24M
      MOZ_ASSERT(get() > 0);
222
3.24M
      suspect(aOwner, aCp, this, nullptr);
223
3.24M
    }
224
19.3M
    return NS_REFCOUNT_VALUE(mRefCntAndFlags);
225
19.3M
  }
226
227
  MOZ_ALWAYS_INLINE void stabilizeForDeletion()
228
0
  {
229
0
    // Set refcnt to 1 and mark us to be in the purple buffer.
230
0
    // This way decr won't call suspect again.
231
0
    mRefCntAndFlags = NS_REFCOUNT_CHANGE | NS_IN_PURPLE_BUFFER;
232
0
  }
233
234
  template<Suspect suspect = NS_CycleCollectorSuspect3>
235
  MOZ_ALWAYS_INLINE uintptr_t decr(nsISupports* aOwner,
236
                                   bool* aShouldDelete = nullptr)
237
  {
238
    return decr<suspect>(aOwner, nullptr, aShouldDelete);
239
  }
240
241
  template<Suspect suspect = NS_CycleCollectorSuspect3>
242
  MOZ_ALWAYS_INLINE uintptr_t decr(void* aOwner,
243
                                   nsCycleCollectionParticipant* aCp,
244
                                   bool* aShouldDelete = nullptr)
245
19.2M
  {
246
19.2M
    MOZ_ASSERT(get() > 0);
247
19.2M
    if (!IsInPurpleBuffer()) {
248
0
      mRefCntAndFlags -= NS_REFCOUNT_CHANGE;
249
0
      mRefCntAndFlags |= (NS_IN_PURPLE_BUFFER | NS_IS_PURPLE);
250
0
      uintptr_t retval = NS_REFCOUNT_VALUE(mRefCntAndFlags);
251
0
      // Suspect may delete 'aOwner' and 'this'!
252
0
      suspect(aOwner, aCp, this, aShouldDelete);
253
0
      return retval;
254
0
    }
255
19.2M
    mRefCntAndFlags -= NS_REFCOUNT_CHANGE;
256
19.2M
    mRefCntAndFlags |= (NS_IN_PURPLE_BUFFER | NS_IS_PURPLE);
257
19.2M
    return NS_REFCOUNT_VALUE(mRefCntAndFlags);
258
19.2M
  }
259
260
  MOZ_ALWAYS_INLINE void RemovePurple()
261
  {
262
    MOZ_ASSERT(IsPurple(), "must be purple");
263
    mRefCntAndFlags &= ~NS_IS_PURPLE;
264
  }
265
266
  MOZ_ALWAYS_INLINE void RemoveFromPurpleBuffer()
267
0
  {
268
0
    MOZ_ASSERT(IsInPurpleBuffer());
269
0
    mRefCntAndFlags &= ~(NS_IS_PURPLE | NS_IN_PURPLE_BUFFER);
270
0
  }
271
272
  MOZ_ALWAYS_INLINE bool IsPurple() const
273
0
  {
274
0
    return !!(mRefCntAndFlags & NS_IS_PURPLE);
275
0
  }
276
277
  MOZ_ALWAYS_INLINE bool IsInPurpleBuffer() const
278
38.5M
  {
279
38.5M
    return !!(mRefCntAndFlags & NS_IN_PURPLE_BUFFER);
280
38.5M
  }
281
282
  MOZ_ALWAYS_INLINE nsrefcnt get() const
283
3.11M
  {
284
3.11M
    return NS_REFCOUNT_VALUE(mRefCntAndFlags);
285
3.11M
  }
286
287
  MOZ_ALWAYS_INLINE operator nsrefcnt() const
288
  {
289
    return get();
290
  }
291
292
private:
293
  uintptr_t mRefCntAndFlags;
294
};
295
296
class nsAutoRefCnt
297
{
298
public:
299
  nsAutoRefCnt() : mValue(0) {}
300
  explicit nsAutoRefCnt(nsrefcnt aValue) : mValue(aValue) {}
301
302
  nsAutoRefCnt(const nsAutoRefCnt&) = delete;
303
  void operator=(const nsAutoRefCnt&) = delete;
304
305
  // only support prefix increment/decrement
306
  nsrefcnt operator++() { return ++mValue; }
307
  nsrefcnt operator--() { return --mValue; }
308
309
  nsrefcnt operator=(nsrefcnt aValue) { return (mValue = aValue); }
310
183M
  operator nsrefcnt() const { return mValue; }
311
  nsrefcnt get() const { return mValue; }
312
313
  static const bool isThreadSafe = false;
314
private:
315
  nsrefcnt operator++(int) = delete;
316
  nsrefcnt operator--(int) = delete;
317
  nsrefcnt mValue;
318
};
319
320
namespace mozilla {
321
template <recordreplay::Behavior Recording>
322
class ThreadSafeAutoRefCntWithRecording
323
{
324
public:
325
  ThreadSafeAutoRefCntWithRecording() : mValue(0) {}
326
  explicit ThreadSafeAutoRefCntWithRecording(nsrefcnt aValue) : mValue(aValue) {}
327
328
  ThreadSafeAutoRefCntWithRecording(const ThreadSafeAutoRefCntWithRecording&) = delete;
329
  void operator=(const ThreadSafeAutoRefCntWithRecording&) = delete;
330
331
  // only support prefix increment/decrement
332
  MOZ_ALWAYS_INLINE nsrefcnt operator++()
333
  {
334
    // Memory synchronization is not required when incrementing a
335
    // reference count.  The first increment of a reference count on a
336
    // thread is not important, since the first use of the object on a
337
    // thread can happen before it.  What is important is the transfer
338
    // of the pointer to that thread, which may happen prior to the
339
    // first increment on that thread.  The necessary memory
340
    // synchronization is done by the mechanism that transfers the
341
    // pointer between threads.
342
    detail::AutoRecordAtomicAccess<Recording> record;
343
    return mValue.fetch_add(1, std::memory_order_relaxed) + 1;
344
  }
345
  MOZ_ALWAYS_INLINE nsrefcnt operator--()
346
  {
347
    // Since this may be the last release on this thread, we need
348
    // release semantics so that prior writes on this thread are visible
349
    // to the thread that destroys the object when it reads mValue with
350
    // acquire semantics.
351
    detail::AutoRecordAtomicAccess<Recording> record;
352
    nsrefcnt result = mValue.fetch_sub(1, std::memory_order_release) - 1;
353
    if (result == 0) {
354
      // We're going to destroy the object on this thread, so we need
355
      // acquire semantics to synchronize with the memory released by
356
      // the last release on other threads, that is, to ensure that
357
      // writes prior to that release are now visible on this thread.
358
      std::atomic_thread_fence(std::memory_order_acquire);
359
    }
360
    return result;
361
  }
362
363
  MOZ_ALWAYS_INLINE nsrefcnt operator=(nsrefcnt aValue)
364
2.99M
  {
365
2.99M
    // Use release semantics since we're not sure what the caller is
366
2.99M
    // doing.
367
2.99M
    detail::AutoRecordAtomicAccess<Recording> record;
368
2.99M
    mValue.store(aValue, std::memory_order_release);
369
2.99M
    return aValue;
370
2.99M
  }
371
  MOZ_ALWAYS_INLINE operator nsrefcnt() const { return get(); }
372
  MOZ_ALWAYS_INLINE nsrefcnt get() const
373
  {
374
    // Use acquire semantics since we're not sure what the caller is
375
    // doing.
376
    detail::AutoRecordAtomicAccess<Recording> record;
377
    return mValue.load(std::memory_order_acquire);
378
  }
379
380
  static const bool isThreadSafe = true;
381
private:
382
  nsrefcnt operator++(int) = delete;
383
  nsrefcnt operator--(int) = delete;
384
  std::atomic<nsrefcnt> mValue;
385
};
386
387
typedef ThreadSafeAutoRefCntWithRecording<recordreplay::Behavior::DontPreserve>
388
  ThreadSafeAutoRefCnt;
389
390
} // namespace mozilla
391
392
///////////////////////////////////////////////////////////////////////////////
393
394
/**
395
 * Declare the reference count variable and the implementations of the
396
 * AddRef and QueryInterface methods.
397
 */
398
399
#define NS_DECL_ISUPPORTS                                                     \
400
public:                                                                       \
401
  NS_IMETHOD QueryInterface(REFNSIID aIID,                                    \
402
                            void** aInstancePtr) override;                    \
403
  NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override;                 \
404
  NS_IMETHOD_(MozExternalRefCountType) Release(void) override;                \
405
  typedef mozilla::FalseType HasThreadSafeRefCnt;                             \
406
protected:                                                                    \
407
  nsAutoRefCnt mRefCnt;                                                       \
408
  NS_DECL_OWNINGTHREAD                                                        \
409
public:
410
411
#define NS_DECL_THREADSAFE_ISUPPORTS_WITH_RECORDING(_recording)               \
412
public:                                                                       \
413
  NS_IMETHOD QueryInterface(REFNSIID aIID,                                    \
414
                            void** aInstancePtr) override;                    \
415
  NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override;                 \
416
  NS_IMETHOD_(MozExternalRefCountType) Release(void) override;                \
417
  typedef mozilla::TrueType HasThreadSafeRefCnt;                              \
418
protected:                                                                    \
419
  ::mozilla::ThreadSafeAutoRefCntWithRecording<_recording> mRefCnt;           \
420
  NS_DECL_OWNINGTHREAD                                                        \
421
public:
422
423
#define NS_DECL_THREADSAFE_ISUPPORTS                                          \
424
  NS_DECL_THREADSAFE_ISUPPORTS_WITH_RECORDING(mozilla::recordreplay::Behavior::DontPreserve)
425
426
#define NS_DECL_CYCLE_COLLECTING_ISUPPORTS                                    \
427
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS_META(override)
428
429
#define NS_DECL_CYCLE_COLLECTING_ISUPPORTS_FINAL                              \
430
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS_META(final)
431
432
#define NS_DECL_CYCLE_COLLECTING_ISUPPORTS_META(...)                          \
433
public:                                                                       \
434
  NS_IMETHOD QueryInterface(REFNSIID aIID,                                    \
435
                            void** aInstancePtr) __VA_ARGS__;                 \
436
  NS_IMETHOD_(MozExternalRefCountType) AddRef(void) __VA_ARGS__;              \
437
  NS_IMETHOD_(MozExternalRefCountType) Release(void) __VA_ARGS__;             \
438
  NS_IMETHOD_(void) DeleteCycleCollectable(void);                             \
439
  typedef mozilla::FalseType HasThreadSafeRefCnt;                             \
440
protected:                                                                    \
441
  nsCycleCollectingAutoRefCnt mRefCnt;                                        \
442
  NS_DECL_OWNINGTHREAD                                                        \
443
public:
444
445
446
///////////////////////////////////////////////////////////////////////////////
447
448
/*
449
 * Implementation of AddRef and Release for non-nsISupports (ie "native")
450
 * cycle-collected classes that use the purple buffer to avoid leaks.
451
 */
452
453
#define NS_IMPL_CC_NATIVE_ADDREF_BODY(_class)                                 \
454
0
    MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                \
455
0
    MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                      \
456
0
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
457
0
    nsrefcnt count =                                                          \
458
0
      mRefCnt.incr(static_cast<void*>(this),                                  \
459
0
                   _class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant()); \
460
0
    NS_LOG_ADDREF(this, count, #_class, sizeof(*this));                       \
461
0
    return count;
462
463
#define NS_IMPL_CC_MAIN_THREAD_ONLY_NATIVE_ADDREF_BODY(_class)     \
464
    MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                     \
465
    MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");           \
466
    NS_ASSERT_OWNINGTHREAD(_class);                                \
467
    nsrefcnt count =                                               \
468
      mRefCnt.incr<NS_CycleCollectorSuspectUsingNursery>(          \
469
        static_cast<void*>(this),                                  \
470
        _class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant()); \
471
    NS_LOG_ADDREF(this, count, #_class, sizeof(*this));            \
472
    return count;
473
474
#define NS_IMPL_CC_NATIVE_RELEASE_BODY(_class)                                \
475
0
    MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                          \
476
0
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
477
0
    nsrefcnt count =                                                          \
478
0
      mRefCnt.decr(static_cast<void*>(this),                                  \
479
0
                   _class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant()); \
480
0
    NS_LOG_RELEASE(this, count, #_class);                                     \
481
0
    return count;
482
483
#define NS_IMPL_CC_MAIN_THREAD_ONLY_NATIVE_RELEASE_BODY(_class)    \
484
    MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");               \
485
    NS_ASSERT_OWNINGTHREAD(_class);                                \
486
    nsrefcnt count =                                               \
487
      mRefCnt.decr<NS_CycleCollectorSuspectUsingNursery>(          \
488
        static_cast<void*>(this),                                  \
489
        _class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant()); \
490
    NS_LOG_RELEASE(this, count, #_class);                          \
491
    return count;
492
493
#define NS_IMPL_CYCLE_COLLECTING_NATIVE_ADDREF(_class)                        \
494
NS_METHOD_(MozExternalRefCountType) _class::AddRef(void)                      \
495
{                                                                             \
496
  NS_IMPL_CC_NATIVE_ADDREF_BODY(_class)                                       \
497
}
498
499
#define NS_IMPL_CYCLE_COLLECTING_NATIVE_RELEASE_WITH_LAST_RELEASE(_class, _last) \
500
NS_METHOD_(MozExternalRefCountType) _class::Release(void)                        \
501
{                                                                                \
502
    MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                             \
503
    NS_ASSERT_OWNINGTHREAD(_class);                                              \
504
    bool shouldDelete = false;                                                   \
505
    nsrefcnt count =                                                             \
506
      mRefCnt.decr(static_cast<void*>(this),                                     \
507
                   _class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant(),     \
508
                   &shouldDelete);                                               \
509
    NS_LOG_RELEASE(this, count, #_class);                                        \
510
    if (count == 0) {                                                            \
511
        mRefCnt.incr(static_cast<void*>(this),                                   \
512
                     _class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant());  \
513
        _last;                                                                   \
514
        mRefCnt.decr(static_cast<void*>(this),                                   \
515
                     _class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant());  \
516
        if (shouldDelete) {                                                      \
517
            mRefCnt.stabilizeForDeletion();                                      \
518
            DeleteCycleCollectable();                                            \
519
        }                                                                        \
520
    }                                                                            \
521
    return count;                                                                \
522
}
523
524
#define NS_IMPL_CYCLE_COLLECTING_NATIVE_RELEASE(_class)                       \
525
NS_METHOD_(MozExternalRefCountType) _class::Release(void)                     \
526
{                                                                             \
527
  NS_IMPL_CC_NATIVE_RELEASE_BODY(_class)                                      \
528
}
529
530
#define NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(_class)            \
531
public:                                                                       \
532
0
  NS_METHOD_(MozExternalRefCountType) AddRef(void) {                          \
533
0
    NS_IMPL_CC_NATIVE_ADDREF_BODY(_class)                                     \
534
0
  }                                                                           \
535
0
  NS_METHOD_(MozExternalRefCountType) Release(void) {                         \
536
0
    NS_IMPL_CC_NATIVE_RELEASE_BODY(_class)                                    \
537
0
  }                                                                           \
538
  typedef mozilla::FalseType HasThreadSafeRefCnt;                             \
539
protected:                                                                    \
540
  nsCycleCollectingAutoRefCnt mRefCnt;                                        \
541
  NS_DECL_OWNINGTHREAD                                                        \
542
public:
543
544
#define NS_INLINE_DECL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_NATIVE_REFCOUNTING(_class) \
545
public:                                                                             \
546
  NS_METHOD_(MozExternalRefCountType) AddRef(void) {                                \
547
    NS_IMPL_CC_MAIN_THREAD_ONLY_NATIVE_ADDREF_BODY(_class)                          \
548
  }                                                                                 \
549
  NS_METHOD_(MozExternalRefCountType) Release(void) {                               \
550
    NS_IMPL_CC_MAIN_THREAD_ONLY_NATIVE_RELEASE_BODY(_class)                         \
551
  }                                                                                 \
552
  typedef mozilla::FalseType HasThreadSafeRefCnt;                                   \
553
protected:                                                                          \
554
  nsCycleCollectingAutoRefCnt mRefCnt;                                              \
555
  NS_DECL_OWNINGTHREAD                                                              \
556
public:
557
558
///////////////////////////////////////////////////////////////////////////////
559
560
/**
561
 * Use this macro to declare and implement the AddRef & Release methods for a
562
 * given non-XPCOM <i>_class</i>.
563
 *
564
 * @param _class The name of the class implementing the method
565
 * @param _destroy A statement that is executed when the object's
566
 *   refcount drops to zero.
567
 * @param optional override Mark the AddRef & Release methods as overrides.
568
 */
569
#define NS_INLINE_DECL_REFCOUNTING_WITH_DESTROY(_class, _destroy, ...)        \
570
public:                                                                       \
571
0
  NS_METHOD_(MozExternalRefCountType) AddRef(void) __VA_ARGS__ {              \
572
0
    MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                \
573
0
    MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                      \
574
0
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
575
0
    ++mRefCnt;                                                                \
576
0
    NS_LOG_ADDREF(this, mRefCnt, #_class, sizeof(*this));                     \
577
0
    return mRefCnt;                                                           \
578
0
  }                                                                           \
Unexecuted instantiation: mozilla::dom::ipc::SharedJSAllocatedData::AddRef()
Unexecuted instantiation: mozilla::MicroTaskRunnable::AddRef()
Unexecuted instantiation: mozilla::ProfilerParent::AddRef()
Unexecuted instantiation: nsNPAPIPlugin::AddRef()
Unexecuted instantiation: mozilla::dom::PaymentRequestParent::AddRef()
Unexecuted instantiation: mozilla::ProfilerChild::AddRef()
Unexecuted instantiation: MockSchedulerGroup::AddRef()
Unexecuted instantiation: IdleObject::AddRef()
Unexecuted instantiation: IdleObjectWithoutSetDeadline::AddRef()
Unexecuted instantiation: IdleObjectInheritedSetDeadline::AddRef()
579
0
  NS_METHOD_(MozExternalRefCountType) Release(void) __VA_ARGS__ {             \
580
0
    MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                          \
581
0
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
582
0
    --mRefCnt;                                                                \
583
0
    NS_LOG_RELEASE(this, mRefCnt, #_class);                                   \
584
0
    if (mRefCnt == 0) {                                                       \
585
0
      mRefCnt = 1; /* stabilize */                                            \
586
0
      _destroy;                                                               \
587
0
      return 0;                                                               \
588
0
    }                                                                         \
589
0
    return mRefCnt;                                                           \
590
0
  }                                                                           \
Unexecuted instantiation: mozilla::dom::ipc::SharedJSAllocatedData::Release()
Unexecuted instantiation: mozilla::MicroTaskRunnable::Release()
Unexecuted instantiation: mozilla::ProfilerParent::Release()
Unexecuted instantiation: nsNPAPIPlugin::Release()
Unexecuted instantiation: mozilla::dom::PaymentRequestParent::Release()
Unexecuted instantiation: mozilla::ProfilerChild::Release()
Unexecuted instantiation: IdleObject::Release()
Unexecuted instantiation: MockSchedulerGroup::Release()
Unexecuted instantiation: IdleObjectWithoutSetDeadline::Release()
Unexecuted instantiation: IdleObjectInheritedSetDeadline::Release()
591
  typedef mozilla::FalseType HasThreadSafeRefCnt;                             \
592
protected:                                                                    \
593
  nsAutoRefCnt mRefCnt;                                                       \
594
  NS_DECL_OWNINGTHREAD                                                        \
595
public:
596
597
/**
598
 * Use this macro to declare and implement the AddRef & Release methods for a
599
 * given non-XPCOM <i>_class</i>.
600
 *
601
 * @param _class The name of the class implementing the method
602
 * @param optional override Mark the AddRef & Release methods as overrides.
603
 */
604
#define NS_INLINE_DECL_REFCOUNTING(_class, ...)                               \
605
  NS_INLINE_DECL_REFCOUNTING_WITH_DESTROY(_class, delete(this), __VA_ARGS__)
606
607
#define NS_INLINE_DECL_THREADSAFE_REFCOUNTING_META(_class, _decl, ...)        \
608
public:                                                                       \
609
474
  _decl(MozExternalRefCountType) AddRef(void) __VA_ARGS__ {                   \
610
474
    MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                \
611
474
    MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                      \
612
474
    nsrefcnt count = ++mRefCnt;                                               \
613
474
    NS_LOG_ADDREF(this, count, #_class, sizeof(*this));                       \
614
474
    return (nsrefcnt) count;                                                  \
615
474
  }                                                                           \
Unexecuted instantiation: mozilla::ChildProfilerController::AddRef()
ThreadInfo::AddRef()
Line
Count
Source
609
474
  _decl(MozExternalRefCountType) AddRef(void) __VA_ARGS__ {                   \
610
474
    MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                \
611
474
    MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                      \
612
474
    nsrefcnt count = ++mRefCnt;                                               \
613
474
    NS_LOG_ADDREF(this, count, #_class, sizeof(*this));                       \
614
474
    return (nsrefcnt) count;                                                  \
615
474
  }                                                                           \
Unexecuted instantiation: mozilla::ProfilerIOInterposeObserver::AddRef()
616
425
  _decl(MozExternalRefCountType) Release(void) __VA_ARGS__ {                  \
617
425
    MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                          \
618
425
    nsrefcnt count = --mRefCnt;                                               \
619
425
    NS_LOG_RELEASE(this, count, #_class);                                     \
620
425
    if (count == 0) {                                                         \
621
0
      delete (this);                                                          \
622
0
      return 0;                                                               \
623
0
    }                                                                         \
624
425
    return count;                                                             \
625
425
  }                                                                           \
Unexecuted instantiation: mozilla::ProfilerIOInterposeObserver::Release()
ThreadInfo::Release()
Line
Count
Source
616
425
  _decl(MozExternalRefCountType) Release(void) __VA_ARGS__ {                  \
617
425
    MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                          \
618
425
    nsrefcnt count = --mRefCnt;                                               \
619
425
    NS_LOG_RELEASE(this, count, #_class);                                     \
620
425
    if (count == 0) {                                                         \
621
0
      delete (this);                                                          \
622
0
      return 0;                                                               \
623
0
    }                                                                         \
624
425
    return count;                                                             \
625
425
  }                                                                           \
626
  typedef mozilla::TrueType HasThreadSafeRefCnt;                              \
627
protected:                                                                    \
628
  ::mozilla::ThreadSafeAutoRefCnt mRefCnt;                                    \
629
public:
630
631
/**
632
 * Use this macro to declare and implement the AddRef & Release methods for a
633
 * given non-XPCOM <i>_class</i> in a threadsafe manner.
634
 *
635
 * DOES NOT DO REFCOUNT STABILIZATION!
636
 *
637
 * @param _class The name of the class implementing the method
638
 */
639
#define NS_INLINE_DECL_THREADSAFE_REFCOUNTING(_class, ...)                    \
640
NS_INLINE_DECL_THREADSAFE_REFCOUNTING_META(_class, NS_METHOD_, __VA_ARGS__)
641
642
/**
643
 * Like NS_INLINE_DECL_THREADSAFE_REFCOUNTING with AddRef & Release declared
644
 * virtual.
645
 */
646
#define NS_INLINE_DECL_THREADSAFE_VIRTUAL_REFCOUNTING(_class, ...)            \
647
NS_INLINE_DECL_THREADSAFE_REFCOUNTING_META(_class, NS_IMETHOD_, __VA_ARGS__)
648
649
/**
650
 * Use this macro in interface classes that you want to be able to reference
651
 * using RefPtr, but don't want to provide a refcounting implemenation. The
652
 * refcounting implementation can be provided by concrete subclasses that
653
 * implement the interface.
654
 */
655
#define NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING                               \
656
public:                                                                       \
657
  NS_IMETHOD_(MozExternalRefCountType) AddRef(void) = 0;                      \
658
  NS_IMETHOD_(MozExternalRefCountType) Release(void) = 0;                     \
659
public:
660
661
/**
662
 * Use this macro to implement the AddRef method for a given <i>_class</i>
663
 * @param _class The name of the class implementing the method
664
 * @param _name The class name to be passed to XPCOM leak checking
665
 */
666
#define NS_IMPL_NAMED_ADDREF(_class, _name)                                   \
667
3.57M
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
3.57M
{                                                                             \
669
3.57M
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
3.57M
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
3.57M
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
3.57M
  if (!mRefCnt.isThreadSafe)                                                  \
673
3.57M
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
3.57M
  nsrefcnt count = ++mRefCnt;                                                 \
675
3.57M
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
3.57M
  return count;                                                               \
677
3.57M
}
Unexecuted instantiation: mozilla::JSObjectHolder::AddRef()
mozilla::LogModulePrefWatcher::AddRef()
Line
Count
Source
667
15
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
15
{                                                                             \
669
15
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
15
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
15
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
15
  if (!mRefCnt.isThreadSafe)                                                  \
673
15
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
15
  nsrefcnt count = ++mRefCnt;                                                 \
675
15
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
15
  return count;                                                               \
677
15
}
Unified_cpp_xpcom_base0.cpp:(anonymous namespace)::nsMemoryPressureWatcher::AddRef()
Line
Count
Source
667
6
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
6
{                                                                             \
669
6
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
6
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
6
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
6
  if (!mRefCnt.isThreadSafe)                                                  \
673
6
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
6
  nsrefcnt count = ++mRefCnt;                                                 \
675
6
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
6
  return count;                                                               \
677
6
}
Unexecuted instantiation: Unified_cpp_xpcom_base0.cpp:(anonymous namespace)::nsJemallocFreeDirtyPagesRunnable::AddRef()
nsConsoleMessage::AddRef()
Line
Count
Source
667
17.8k
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
17.8k
{                                                                             \
669
17.8k
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
17.8k
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
17.8k
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
17.8k
  if (!mRefCnt.isThreadSafe)                                                  \
673
17.8k
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
17.8k
  nsrefcnt count = ++mRefCnt;                                                 \
675
17.8k
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
17.8k
  return count;                                                               \
677
17.8k
}
nsConsoleService::AddRef()
Line
Count
Source
667
8.90k
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
8.90k
{                                                                             \
669
8.90k
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
8.90k
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
8.90k
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
8.90k
  if (!mRefCnt.isThreadSafe)                                                  \
673
8.90k
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
8.90k
  nsrefcnt count = ++mRefCnt;                                                 \
675
8.90k
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
8.90k
  return count;                                                               \
677
8.90k
}
nsCycleCollector::AddRef()
Line
Count
Source
667
6
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
6
{                                                                             \
669
6
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
6
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
6
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
6
  if (!mRefCnt.isThreadSafe)                                                  \
673
6
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
6
  nsrefcnt count = ++mRefCnt;                                                 \
675
6
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
6
  return count;                                                               \
677
6
}
Unexecuted instantiation: nsCycleCollectorLogSinkToFile::AddRef()
Unexecuted instantiation: nsCycleCollectorLogger::AddRef()
FdWatcher::AddRef()
Line
Count
Source
667
9
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
9
{                                                                             \
669
9
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
9
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
9
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
9
  if (!mRefCnt.isThreadSafe)                                                  \
673
9
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
9
  nsrefcnt count = ++mRefCnt;                                                 \
675
9
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
9
  return count;                                                               \
677
9
}
nsErrorService::AddRef()
Line
Count
Source
667
12
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
12
{                                                                             \
669
12
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
12
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
12
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
12
  if (!mRefCnt.isThreadSafe)                                                  \
673
12
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
12
  nsrefcnt count = ++mRefCnt;                                                 \
675
12
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
12
  return count;                                                               \
677
12
}
Unexecuted instantiation: nsGZFileWriter::AddRef()
Unexecuted instantiation: nsInterfaceRequestorAgg::AddRef()
Unexecuted instantiation: nsMemoryInfoDumper::AddRef()
Unexecuted instantiation: nsDumpGCAndCCLogsCallbackHolder::AddRef()
Unexecuted instantiation: HandleReportAndFinishReportingCallbacks::AddRef()
Unexecuted instantiation: TempDirFinishCallback::AddRef()
VsizeReporter::AddRef()
Line
Count
Source
667
9
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
9
{                                                                             \
669
9
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
9
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
9
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
9
  if (!mRefCnt.isThreadSafe)                                                  \
673
9
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
9
  nsrefcnt count = ++mRefCnt;                                                 \
675
9
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
9
  return count;                                                               \
677
9
}
ResidentReporter::AddRef()
Line
Count
Source
667
9
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
9
{                                                                             \
669
9
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
9
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
9
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
9
  if (!mRefCnt.isThreadSafe)                                                  \
673
9
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
9
  nsrefcnt count = ++mRefCnt;                                                 \
675
9
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
9
  return count;                                                               \
677
9
}
ResidentUniqueReporter::AddRef()
Line
Count
Source
667
9
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
9
{                                                                             \
669
9
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
9
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
9
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
9
  if (!mRefCnt.isThreadSafe)                                                  \
673
9
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
9
  nsrefcnt count = ++mRefCnt;                                                 \
675
9
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
9
  return count;                                                               \
677
9
}
SystemHeapReporter::AddRef()
Line
Count
Source
667
9
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
9
{                                                                             \
669
9
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
9
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
9
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
9
  if (!mRefCnt.isThreadSafe)                                                  \
673
9
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
9
  nsrefcnt count = ++mRefCnt;                                                 \
675
9
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
9
  return count;                                                               \
677
9
}
ResidentPeakReporter::AddRef()
Line
Count
Source
667
9
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
9
{                                                                             \
669
9
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
9
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
9
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
9
  if (!mRefCnt.isThreadSafe)                                                  \
673
9
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
9
  nsrefcnt count = ++mRefCnt;                                                 \
675
9
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
9
  return count;                                                               \
677
9
}
PageFaultsSoftReporter::AddRef()
Line
Count
Source
667
9
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
9
{                                                                             \
669
9
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
9
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
9
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
9
  if (!mRefCnt.isThreadSafe)                                                  \
673
9
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
9
  nsrefcnt count = ++mRefCnt;                                                 \
675
9
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
9
  return count;                                                               \
677
9
}
PageFaultsHardReporter::AddRef()
Line
Count
Source
667
9
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
9
{                                                                             \
669
9
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
9
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
9
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
9
  if (!mRefCnt.isThreadSafe)                                                  \
673
9
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
9
  nsrefcnt count = ++mRefCnt;                                                 \
675
9
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
9
  return count;                                                               \
677
9
}
AtomTablesReporter::AddRef()
Line
Count
Source
667
9
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
9
{                                                                             \
669
9
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
9
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
9
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
9
  if (!mRefCnt.isThreadSafe)                                                  \
673
9
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
9
  nsrefcnt count = ++mRefCnt;                                                 \
675
9
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
9
  return count;                                                               \
677
9
}
ThreadsReporter::AddRef()
Line
Count
Source
667
9
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
9
{                                                                             \
669
9
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
9
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
9
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
9
  if (!mRefCnt.isThreadSafe)                                                  \
673
9
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
9
  nsrefcnt count = ++mRefCnt;                                                 \
675
9
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
9
  return count;                                                               \
677
9
}
nsMemoryReporterManager::AddRef()
Line
Count
Source
667
155
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
155
{                                                                             \
669
155
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
155
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
155
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
155
  if (!mRefCnt.isThreadSafe)                                                  \
673
155
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
155
  nsrefcnt count = ++mRefCnt;                                                 \
675
155
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
155
  return count;                                                               \
677
155
}
Unexecuted instantiation: nsMessageLoop::AddRef()
Unexecuted instantiation: nsSecurityConsoleMessage::AddRef()
nsUUIDGenerator::AddRef()
Line
Count
Source
667
24
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
24
{                                                                             \
669
24
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
24
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
24
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
24
  if (!mRefCnt.isThreadSafe)                                                  \
673
24
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
24
  nsrefcnt count = ++mRefCnt;                                                 \
675
24
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
24
  return count;                                                               \
677
24
}
Unexecuted instantiation: nsVersionComparatorImpl::AddRef()
nsWeakReference::AddRef()
Line
Count
Source
667
393
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
393
{                                                                             \
669
393
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
393
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
393
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
393
  if (!mRefCnt.isThreadSafe)                                                  \
673
393
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
393
  nsrefcnt count = ++mRefCnt;                                                 \
675
393
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
393
  return count;                                                               \
677
393
}
Unexecuted instantiation: Unified_cpp_xpcom_base2.cpp:(anonymous namespace)::MessageLoopTimerCallback::AddRef()
mozilla::GenericFactory::AddRef()
Line
Count
Source
667
1.92M
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
1.92M
{                                                                             \
669
1.92M
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
1.92M
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
1.92M
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
1.92M
  if (!mRefCnt.isThreadSafe)                                                  \
673
1.92M
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
1.92M
  nsrefcnt count = ++mRefCnt;                                                 \
675
1.92M
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
1.92M
  return count;                                                               \
677
1.92M
}
Unexecuted instantiation: nsCategoryObserver::AddRef()
CategoryEntry::AddRef()
Line
Count
Source
667
9
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
9
{                                                                             \
669
9
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
9
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
9
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
9
  if (!mRefCnt.isThreadSafe)                                                  \
673
9
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
9
  nsrefcnt count = ++mRefCnt;                                                 \
675
9
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
9
  return count;                                                               \
677
9
}
nsComponentManagerImpl::AddRef()
Line
Count
Source
667
1.62M
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
1.62M
{                                                                             \
669
1.62M
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
1.62M
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
1.62M
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
1.62M
  if (!mRefCnt.isThreadSafe)                                                  \
673
1.62M
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
1.62M
  nsrefcnt count = ++mRefCnt;                                                 \
675
1.62M
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
1.62M
  return count;                                                               \
677
1.62M
}
Unexecuted instantiation: nsInvalidPluginTag::AddRef()
Unexecuted instantiation: mozilla::plugins::BlocklistPromiseHandler::AddRef()
Unexecuted instantiation: nsPluginHost::AddRef()
Unexecuted instantiation: ClearDataFromSitesClosure::AddRef()
Unexecuted instantiation: GetSitesClosure::AddRef()
Unexecuted instantiation: mozilla::dom::ContentListener::AddRef()
Unexecuted instantiation: mozilla::dom::TabParent::AddRef()
Unexecuted instantiation: mozilla::dom::SynthesizedEventObserver::AddRef()
Unexecuted instantiation: mozilla::dom::FakeChannel::AddRef()
Unexecuted instantiation: mozilla::dom::URLClassifierParent::AddRef()
Unexecuted instantiation: mozilla::dom::URLClassifierLocalParent::AddRef()
GeckoProfilerReporter::AddRef()
Line
Count
Source
667
9
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
668
9
{                                                                             \
669
9
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
670
9
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
671
9
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
672
9
  if (!mRefCnt.isThreadSafe)                                                  \
673
9
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
674
9
  nsrefcnt count = ++mRefCnt;                                                 \
675
9
  NS_LOG_ADDREF(this, count, _name, sizeof(*this));                           \
676
9
  return count;                                                               \
677
9
}
Unexecuted instantiation: nsProfiler::AddRef()
Unexecuted instantiation: nsProfilerStartParams::AddRef()
Unexecuted instantiation: LengthStream::AddRef()
Unexecuted instantiation: ClosedStream::AddRef()
Unexecuted instantiation: AsyncStream::AddRef()
Unexecuted instantiation: NonBufferableStringStream::AddRef()
Unexecuted instantiation: QIInputStream::AddRef()
Unexecuted instantiation: TestObserver::AddRef()
Unexecuted instantiation: WaitCondition::AddRef()
Unexecuted instantiation: ErrorCondition::AddRef()
Unexecuted instantiation: Task::AddRef()
Unexecuted instantiation: TestThreadPoolListener::Listener::AddRef()
Unexecuted instantiation: nsFoo::AddRef()
Unexecuted instantiation: nsBar::AddRef()
Unexecuted instantiation: TestThreadUtils::SpyWithISupports::AddRef()
Unexecuted instantiation: TestThreadUtils::ThreadUtilsObject::AddRef()
Unexecuted instantiation: nsRunner::AddRef()
Unexecuted instantiation: nsStressRunner::AddRef()
Unexecuted instantiation: AsyncShutdownPreparer::AddRef()
Unexecuted instantiation: AsyncShutdownWaiter::AddRef()
Unexecuted instantiation: SameThreadSentinel::AddRef()
Unexecuted instantiation: TimerCallback::AddRef()
Unexecuted instantiation: FuzzTestThreadState::AddRef()
678
679
/**
680
 * Use this macro to implement the AddRef method for a given <i>_class</i>
681
 * @param _class The name of the class implementing the method
682
 */
683
#define NS_IMPL_ADDREF(_class)                                                \
684
  NS_IMPL_NAMED_ADDREF(_class, #_class)
685
686
/**
687
 * Use this macro to implement the AddRef method for a given <i>_class</i>
688
 * implemented as a wholly owned aggregated object intended to implement
689
 * interface(s) for its owner
690
 * @param _class The name of the class implementing the method
691
 * @param _aggregator the owning/containing object
692
 */
693
#define NS_IMPL_ADDREF_USING_AGGREGATOR(_class, _aggregator)                  \
694
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
695
{                                                                             \
696
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
697
  MOZ_ASSERT(_aggregator, "null aggregator");                                 \
698
  return (_aggregator)->AddRef();                                             \
699
}
700
701
// We decrement the refcnt before logging the actual release, but when logging
702
// named things, accessing the name may not be valid after the refcnt
703
// decrement, because the object may have been destroyed on a different thread.
704
// Use this macro to ensure that we have a local copy of the name prior to
705
// the refcnt decrement.  (We use a macro to make absolutely sure the name
706
// isn't loaded in builds where it wouldn't be used.)
707
#ifdef NS_BUILD_REFCNT_LOGGING
708
#define NS_LOAD_NAME_BEFORE_RELEASE(localname, _name) \
709
  const char* const localname = _name
710
#else
711
#define NS_LOAD_NAME_BEFORE_RELEASE(localname, _name)
712
#endif
713
714
/**
715
 * Use this macro to implement the Release method for a given
716
 * <i>_class</i>.
717
 * @param _class The name of the class implementing the method
718
 * @param _name The class name to be passed to XPCOM leak checking
719
 * @param _destroy A statement that is executed when the object's
720
 *   refcount drops to zero.
721
 *
722
 * For example,
723
 *
724
 *   NS_IMPL_RELEASE_WITH_DESTROY(Foo, "Foo", Destroy(this))
725
 *
726
 * will cause
727
 *
728
 *   Destroy(this);
729
 *
730
 * to be invoked when the object's refcount drops to zero. This
731
 * allows for arbitrary teardown activity to occur (e.g., deallocation
732
 * of object allocated with placement new).
733
 */
734
#define NS_IMPL_NAMED_RELEASE_WITH_DESTROY(_class, _name, _destroy)           \
735
3.57M
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
3.57M
{                                                                             \
737
3.57M
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
3.57M
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
3.57M
  if (!mRefCnt.isThreadSafe)                                                  \
740
3.57M
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
3.57M
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
3.57M
  nsrefcnt count = --mRefCnt;                                                 \
743
3.57M
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
3.57M
  if (count == 0) {                                                           \
745
8.65k
    mRefCnt = 1; /* stabilize */                                              \
746
8.65k
    _destroy;                                                                 \
747
8.65k
    return 0;                                                                 \
748
8.65k
  }                                                                           \
749
3.57M
  return count;                                                               \
750
3.57M
}
Unexecuted instantiation: mozilla::JSObjectHolder::Release()
mozilla::LogModulePrefWatcher::Release()
Line
Count
Source
735
6
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
6
{                                                                             \
737
6
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
6
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
6
  if (!mRefCnt.isThreadSafe)                                                  \
740
6
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
6
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
6
  nsrefcnt count = --mRefCnt;                                                 \
743
6
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
6
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
6
  return count;                                                               \
750
6
}
Unified_cpp_xpcom_base0.cpp:(anonymous namespace)::nsMemoryPressureWatcher::Release()
Line
Count
Source
735
3
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
3
{                                                                             \
737
3
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
3
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
3
  if (!mRefCnt.isThreadSafe)                                                  \
740
3
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
3
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
3
  nsrefcnt count = --mRefCnt;                                                 \
743
3
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
3
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
3
  return count;                                                               \
750
3
}
Unexecuted instantiation: Unified_cpp_xpcom_base0.cpp:(anonymous namespace)::nsJemallocFreeDirtyPagesRunnable::Release()
nsConsoleMessage::Release()
Line
Count
Source
735
17.5k
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
17.5k
{                                                                             \
737
17.5k
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
17.5k
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
17.5k
  if (!mRefCnt.isThreadSafe)                                                  \
740
17.5k
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
17.5k
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
17.5k
  nsrefcnt count = --mRefCnt;                                                 \
743
17.5k
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
17.5k
  if (count == 0) {                                                           \
745
8.65k
    mRefCnt = 1; /* stabilize */                                              \
746
8.65k
    _destroy;                                                                 \
747
8.65k
    return 0;                                                                 \
748
8.65k
  }                                                                           \
749
17.5k
  return count;                                                               \
750
17.5k
}
nsConsoleService::Release()
Line
Count
Source
735
8.90k
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
8.90k
{                                                                             \
737
8.90k
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
8.90k
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
8.90k
  if (!mRefCnt.isThreadSafe)                                                  \
740
8.90k
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
8.90k
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
8.90k
  nsrefcnt count = --mRefCnt;                                                 \
743
8.90k
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
8.90k
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
8.90k
  return count;                                                               \
750
8.90k
}
nsCycleCollector::Release()
Line
Count
Source
735
3
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
3
{                                                                             \
737
3
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
3
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
3
  if (!mRefCnt.isThreadSafe)                                                  \
740
3
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
3
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
3
  nsrefcnt count = --mRefCnt;                                                 \
743
3
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
3
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
3
  return count;                                                               \
750
3
}
Unexecuted instantiation: nsCycleCollectorLogSinkToFile::Release()
Unexecuted instantiation: nsCycleCollectorLogger::Release()
FdWatcher::Release()
Line
Count
Source
735
3
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
3
{                                                                             \
737
3
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
3
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
3
  if (!mRefCnt.isThreadSafe)                                                  \
740
3
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
3
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
3
  nsrefcnt count = --mRefCnt;                                                 \
743
3
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
3
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
3
  return count;                                                               \
750
3
}
nsErrorService::Release()
Line
Count
Source
735
9
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
9
{                                                                             \
737
9
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
9
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
9
  if (!mRefCnt.isThreadSafe)                                                  \
740
9
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
9
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
9
  nsrefcnt count = --mRefCnt;                                                 \
743
9
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
9
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
9
  return count;                                                               \
750
9
}
Unexecuted instantiation: nsGZFileWriter::Release()
Unexecuted instantiation: nsInterfaceRequestorAgg::Release()
Unexecuted instantiation: nsMemoryInfoDumper::Release()
Unexecuted instantiation: nsDumpGCAndCCLogsCallbackHolder::Release()
Unexecuted instantiation: HandleReportAndFinishReportingCallbacks::Release()
Unexecuted instantiation: TempDirFinishCallback::Release()
VsizeReporter::Release()
Line
Count
Source
735
6
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
6
{                                                                             \
737
6
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
6
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
6
  if (!mRefCnt.isThreadSafe)                                                  \
740
6
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
6
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
6
  nsrefcnt count = --mRefCnt;                                                 \
743
6
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
6
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
6
  return count;                                                               \
750
6
}
ResidentReporter::Release()
Line
Count
Source
735
6
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
6
{                                                                             \
737
6
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
6
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
6
  if (!mRefCnt.isThreadSafe)                                                  \
740
6
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
6
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
6
  nsrefcnt count = --mRefCnt;                                                 \
743
6
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
6
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
6
  return count;                                                               \
750
6
}
ResidentUniqueReporter::Release()
Line
Count
Source
735
6
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
6
{                                                                             \
737
6
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
6
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
6
  if (!mRefCnt.isThreadSafe)                                                  \
740
6
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
6
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
6
  nsrefcnt count = --mRefCnt;                                                 \
743
6
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
6
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
6
  return count;                                                               \
750
6
}
SystemHeapReporter::Release()
Line
Count
Source
735
6
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
6
{                                                                             \
737
6
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
6
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
6
  if (!mRefCnt.isThreadSafe)                                                  \
740
6
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
6
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
6
  nsrefcnt count = --mRefCnt;                                                 \
743
6
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
6
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
6
  return count;                                                               \
750
6
}
ResidentPeakReporter::Release()
Line
Count
Source
735
6
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
6
{                                                                             \
737
6
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
6
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
6
  if (!mRefCnt.isThreadSafe)                                                  \
740
6
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
6
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
6
  nsrefcnt count = --mRefCnt;                                                 \
743
6
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
6
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
6
  return count;                                                               \
750
6
}
PageFaultsSoftReporter::Release()
Line
Count
Source
735
6
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
6
{                                                                             \
737
6
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
6
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
6
  if (!mRefCnt.isThreadSafe)                                                  \
740
6
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
6
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
6
  nsrefcnt count = --mRefCnt;                                                 \
743
6
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
6
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
6
  return count;                                                               \
750
6
}
PageFaultsHardReporter::Release()
Line
Count
Source
735
6
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
6
{                                                                             \
737
6
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
6
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
6
  if (!mRefCnt.isThreadSafe)                                                  \
740
6
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
6
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
6
  nsrefcnt count = --mRefCnt;                                                 \
743
6
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
6
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
6
  return count;                                                               \
750
6
}
AtomTablesReporter::Release()
Line
Count
Source
735
6
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
6
{                                                                             \
737
6
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
6
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
6
  if (!mRefCnt.isThreadSafe)                                                  \
740
6
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
6
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
6
  nsrefcnt count = --mRefCnt;                                                 \
743
6
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
6
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
6
  return count;                                                               \
750
6
}
ThreadsReporter::Release()
Line
Count
Source
735
6
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
6
{                                                                             \
737
6
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
6
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
6
  if (!mRefCnt.isThreadSafe)                                                  \
740
6
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
6
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
6
  nsrefcnt count = --mRefCnt;                                                 \
743
6
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
6
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
6
  return count;                                                               \
750
6
}
nsMemoryReporterManager::Release()
Line
Count
Source
735
152
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
152
{                                                                             \
737
152
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
152
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
152
  if (!mRefCnt.isThreadSafe)                                                  \
740
152
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
152
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
152
  nsrefcnt count = --mRefCnt;                                                 \
743
152
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
152
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
152
  return count;                                                               \
750
152
}
Unexecuted instantiation: nsMessageLoop::Release()
Unexecuted instantiation: nsSecurityConsoleMessage::Release()
nsUUIDGenerator::Release()
Line
Count
Source
735
15
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
15
{                                                                             \
737
15
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
15
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
15
  if (!mRefCnt.isThreadSafe)                                                  \
740
15
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
15
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
15
  nsrefcnt count = --mRefCnt;                                                 \
743
15
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
15
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
15
  return count;                                                               \
750
15
}
Unexecuted instantiation: nsVersionComparatorImpl::Release()
nsWeakReference::Release()
Line
Count
Source
735
172
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
172
{                                                                             \
737
172
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
172
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
172
  if (!mRefCnt.isThreadSafe)                                                  \
740
172
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
172
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
172
  nsrefcnt count = --mRefCnt;                                                 \
743
172
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
172
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
172
  return count;                                                               \
750
172
}
Unexecuted instantiation: Unified_cpp_xpcom_base2.cpp:(anonymous namespace)::MessageLoopTimerCallback::Release()
mozilla::GenericFactory::Release()
Line
Count
Source
735
1.91M
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
1.91M
{                                                                             \
737
1.91M
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
1.91M
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
1.91M
  if (!mRefCnt.isThreadSafe)                                                  \
740
1.91M
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
1.91M
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
1.91M
  nsrefcnt count = --mRefCnt;                                                 \
743
1.91M
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
1.91M
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
1.91M
  return count;                                                               \
750
1.91M
}
Unexecuted instantiation: nsCategoryObserver::Release()
CategoryEntry::Release()
Line
Count
Source
735
9
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
9
{                                                                             \
737
9
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
9
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
9
  if (!mRefCnt.isThreadSafe)                                                  \
740
9
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
9
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
9
  nsrefcnt count = --mRefCnt;                                                 \
743
9
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
9
  if (count == 0) {                                                           \
745
3
    mRefCnt = 1; /* stabilize */                                              \
746
3
    _destroy;                                                                 \
747
3
    return 0;                                                                 \
748
3
  }                                                                           \
749
9
  return count;                                                               \
750
9
}
nsComponentManagerImpl::Release()
Line
Count
Source
735
1.62M
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
1.62M
{                                                                             \
737
1.62M
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
1.62M
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
1.62M
  if (!mRefCnt.isThreadSafe)                                                  \
740
1.62M
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
1.62M
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
1.62M
  nsrefcnt count = --mRefCnt;                                                 \
743
1.62M
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
1.62M
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
1.62M
  return count;                                                               \
750
1.62M
}
Unexecuted instantiation: nsInvalidPluginTag::Release()
Unexecuted instantiation: mozilla::plugins::BlocklistPromiseHandler::Release()
Unexecuted instantiation: nsPluginHost::Release()
Unexecuted instantiation: ClearDataFromSitesClosure::Release()
Unexecuted instantiation: GetSitesClosure::Release()
Unexecuted instantiation: mozilla::dom::ContentListener::Release()
Unexecuted instantiation: mozilla::dom::TabParent::Release()
Unexecuted instantiation: mozilla::dom::SynthesizedEventObserver::Release()
Unexecuted instantiation: mozilla::dom::FakeChannel::Release()
Unexecuted instantiation: mozilla::dom::URLClassifierParent::Release()
Unexecuted instantiation: mozilla::dom::URLClassifierLocalParent::Release()
GeckoProfilerReporter::Release()
Line
Count
Source
735
6
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
736
6
{                                                                             \
737
6
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
738
6
  MOZ_ASSERT(_name != nullptr, "Must specify a name");                        \
739
6
  if (!mRefCnt.isThreadSafe)                                                  \
740
6
    NS_ASSERT_OWNINGTHREAD(_class);                                           \
741
6
  NS_LOAD_NAME_BEFORE_RELEASE(nametmp, _name);                                \
742
6
  nsrefcnt count = --mRefCnt;                                                 \
743
6
  NS_LOG_RELEASE(this, count, nametmp);                                       \
744
6
  if (count == 0) {                                                           \
745
0
    mRefCnt = 1; /* stabilize */                                              \
746
0
    _destroy;                                                                 \
747
0
    return 0;                                                                 \
748
0
  }                                                                           \
749
6
  return count;                                                               \
750
6
}
Unexecuted instantiation: nsProfiler::Release()
Unexecuted instantiation: nsProfilerStartParams::Release()
Unexecuted instantiation: LengthStream::Release()
Unexecuted instantiation: ClosedStream::Release()
Unexecuted instantiation: AsyncStream::Release()
Unexecuted instantiation: NonBufferableStringStream::Release()
Unexecuted instantiation: QIInputStream::Release()
Unexecuted instantiation: TestObserver::Release()
Unexecuted instantiation: WaitCondition::Release()
Unexecuted instantiation: ErrorCondition::Release()
Unexecuted instantiation: Task::Release()
Unexecuted instantiation: TestThreadPoolListener::Listener::Release()
Unexecuted instantiation: nsFoo::Release()
Unexecuted instantiation: nsBar::Release()
Unexecuted instantiation: TestThreadUtils::SpyWithISupports::Release()
Unexecuted instantiation: TestThreadUtils::ThreadUtilsObject::Release()
Unexecuted instantiation: nsRunner::Release()
Unexecuted instantiation: nsStressRunner::Release()
Unexecuted instantiation: AsyncShutdownPreparer::Release()
Unexecuted instantiation: AsyncShutdownWaiter::Release()
Unexecuted instantiation: SameThreadSentinel::Release()
Unexecuted instantiation: TimerCallback::Release()
Unexecuted instantiation: FuzzTestThreadState::Release()
751
752
#define NS_IMPL_RELEASE_WITH_DESTROY(_class, _destroy)                        \
753
  NS_IMPL_NAMED_RELEASE_WITH_DESTROY(_class, #_class, _destroy)
754
755
/**
756
 * Use this macro to implement the Release method for a given <i>_class</i>
757
 * @param _class The name of the class implementing the method
758
 *
759
 * A note on the 'stabilization' of the refcnt to one. At that point,
760
 * the object's refcount will have gone to zero. The object's
761
 * destructor may trigger code that attempts to QueryInterface() and
762
 * Release() 'this' again. Doing so will temporarily increment and
763
 * decrement the refcount. (Only a logic error would make one try to
764
 * keep a permanent hold on 'this'.)  To prevent re-entering the
765
 * destructor, we make sure that no balanced refcounting can return
766
 * the refcount to |0|.
767
 */
768
#define NS_IMPL_RELEASE(_class) \
769
  NS_IMPL_RELEASE_WITH_DESTROY(_class, delete (this))
770
771
#define NS_IMPL_NAMED_RELEASE(_class, _name)                                  \
772
  NS_IMPL_NAMED_RELEASE_WITH_DESTROY(_class, _name, delete (this))
773
774
/**
775
 * Use this macro to implement the Release method for a given <i>_class</i>
776
 * implemented as a wholly owned aggregated object intended to implement
777
 * interface(s) for its owner
778
 * @param _class The name of the class implementing the method
779
 * @param _aggregator the owning/containing object
780
 */
781
#define NS_IMPL_RELEASE_USING_AGGREGATOR(_class, _aggregator)                 \
782
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
783
{                                                                             \
784
  MOZ_ASSERT(_aggregator, "null aggregator");                                 \
785
  return (_aggregator)->Release();                                            \
786
}
787
788
789
#define NS_IMPL_CYCLE_COLLECTING_ADDREF(_class)                               \
790
0
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
791
0
{                                                                             \
792
0
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
793
0
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
794
0
  NS_ASSERT_OWNINGTHREAD(_class);                                             \
795
0
  nsISupports *base = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this);    \
796
0
  nsrefcnt count = mRefCnt.incr(base);                                        \
797
0
  NS_LOG_ADDREF(this, count, #_class, sizeof(*this));                         \
798
0
  return count;                                                               \
799
0
}
800
801
#define NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_ADDREF(_class)              \
802
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void)                  \
803
{                                                                             \
804
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                  \
805
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                        \
806
  NS_ASSERT_OWNINGTHREAD(_class);                                             \
807
  nsISupports *base = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this);    \
808
  nsrefcnt count = mRefCnt.incr<NS_CycleCollectorSuspectUsingNursery>(base);  \
809
  NS_LOG_ADDREF(this, count, #_class, sizeof(*this));                         \
810
  return count;                                                               \
811
}
812
813
#define NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_DESTROY(_class, _destroy)       \
814
0
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
815
0
{                                                                             \
816
0
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
817
0
  NS_ASSERT_OWNINGTHREAD(_class);                                             \
818
0
  nsISupports *base = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this);    \
819
0
  nsrefcnt count = mRefCnt.decr(base);                                        \
820
0
  NS_LOG_RELEASE(this, count, #_class);                                       \
821
0
  return count;                                                               \
822
0
}                                                                             \
823
0
NS_IMETHODIMP_(void) _class::DeleteCycleCollectable(void)                     \
824
0
{                                                                             \
825
0
  _destroy;                                                                   \
826
0
}
827
828
#define NS_IMPL_CYCLE_COLLECTING_RELEASE(_class)                              \
829
  NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_DESTROY(_class, delete (this))
830
831
// _LAST_RELEASE can be useful when certain resources should be released
832
// as soon as we know the object will be deleted.
833
#define NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(_class, _last)     \
834
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                 \
835
{                                                                             \
836
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                            \
837
  NS_ASSERT_OWNINGTHREAD(_class);                                             \
838
  bool shouldDelete = false;                                                  \
839
  nsISupports *base = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this);    \
840
  nsrefcnt count = mRefCnt.decr(base, &shouldDelete);                         \
841
  NS_LOG_RELEASE(this, count, #_class);                                       \
842
  if (count == 0) {                                                           \
843
      mRefCnt.incr(base);                                                     \
844
      _last;                                                                  \
845
      mRefCnt.decr(base);                                                     \
846
      if (shouldDelete) {                                                     \
847
          mRefCnt.stabilizeForDeletion();                                     \
848
          DeleteCycleCollectable();                                           \
849
      }                                                                       \
850
  }                                                                           \
851
  return count;                                                               \
852
}                                                                             \
853
NS_IMETHODIMP_(void) _class::DeleteCycleCollectable(void)                     \
854
{                                                                             \
855
  delete this;                                                                \
856
}
857
858
#define NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE(_class)            \
859
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                \
860
{                                                                            \
861
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                           \
862
  NS_ASSERT_OWNINGTHREAD(_class);                                            \
863
  nsISupports *base = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this);   \
864
  nsrefcnt count = mRefCnt.decr<NS_CycleCollectorSuspectUsingNursery>(base); \
865
  NS_LOG_RELEASE(this, count, #_class);                                      \
866
  return count;                                                              \
867
}                                                                            \
868
NS_IMETHODIMP_(void) _class::DeleteCycleCollectable(void)                    \
869
{                                                                            \
870
  delete this;                                                               \
871
}
872
873
// _LAST_RELEASE can be useful when certain resources should be released
874
// as soon as we know the object will be deleted.
875
#define NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(_class, _last)  \
876
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void)                               \
877
{                                                                                           \
878
  MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                                          \
879
  NS_ASSERT_OWNINGTHREAD(_class);                                                           \
880
  bool shouldDelete = false;                                                                \
881
  nsISupports *base = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this);                  \
882
  nsrefcnt count = mRefCnt.decr<NS_CycleCollectorSuspectUsingNursery>(base, &shouldDelete); \
883
  NS_LOG_RELEASE(this, count, #_class);                                                     \
884
  if (count == 0) {                                                                         \
885
      mRefCnt.incr<NS_CycleCollectorSuspectUsingNursery>(base);                             \
886
      _last;                                                                                \
887
      mRefCnt.decr<NS_CycleCollectorSuspectUsingNursery>(base);                             \
888
      if (shouldDelete) {                                                                   \
889
          mRefCnt.stabilizeForDeletion();                                                   \
890
          DeleteCycleCollectable();                                                         \
891
      }                                                                                     \
892
  }                                                                                         \
893
  return count;                                                                             \
894
}                                                                                           \
895
NS_IMETHODIMP_(void) _class::DeleteCycleCollectable(void)                                   \
896
{                                                                                           \
897
  delete this;                                                                              \
898
}
899
900
///////////////////////////////////////////////////////////////////////////////
901
902
/**
903
 * There are two ways of implementing QueryInterface, and we use both:
904
 *
905
 * Table-driven QueryInterface uses a static table of IID->offset mappings
906
 * and a shared helper function. Using it tends to reduce codesize and improve
907
 * runtime performance (due to processor cache hits).
908
 *
909
 * Macro-driven QueryInterface generates a QueryInterface function directly
910
 * using common macros. This is necessary if special QueryInterface features
911
 * are being used (such as tearoffs and conditional interfaces).
912
 *
913
 * These methods can be combined into a table-driven function call followed
914
 * by custom code for tearoffs and conditionals.
915
 */
916
917
struct QITableEntry
918
{
919
  const nsIID* iid;     // null indicates end of the QITableEntry array
920
  int32_t   offset;
921
};
922
923
nsresult NS_FASTCALL
924
NS_TableDrivenQI(void* aThis, REFNSIID aIID,
925
                 void** aInstancePtr, const QITableEntry* aEntries);
926
927
/**
928
 * Implement table-driven queryinterface
929
 */
930
931
#define NS_INTERFACE_TABLE_HEAD(_class)                                       \
932
114
NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr)      \
933
114
{                                                                             \
934
114
  NS_ASSERTION(aInstancePtr,                                                  \
935
114
               "QueryInterface requires a non-NULL destination!");            \
936
114
  nsresult rv = NS_ERROR_FAILURE;
937
938
#define NS_INTERFACE_TABLE_BEGIN                                              \
939
114
  static const QITableEntry table[] = {
940
941
#define NS_INTERFACE_TABLE_ENTRY(_class, _interface)                          \
942
222
  { &NS_GET_IID(_interface),                                                  \
943
222
    int32_t(reinterpret_cast<char*>(                                          \
944
222
                        static_cast<_interface*>((_class*) 0x1000)) -         \
945
222
               reinterpret_cast<char*>((_class*) 0x1000))                     \
946
222
  },
947
948
#define NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(_class, _interface, _implClass)    \
949
114
  { &NS_GET_IID(_interface),                                                  \
950
114
    int32_t(reinterpret_cast<char*>(                                          \
951
114
                        static_cast<_interface*>(                             \
952
114
                                       static_cast<_implClass*>(              \
953
114
                                                      (_class*) 0x1000))) -   \
954
114
               reinterpret_cast<char*>((_class*) 0x1000))                     \
955
114
  },
956
957
/*
958
 * XXX: we want to use mozilla::ArrayLength (or equivalent,
959
 * MOZ_ARRAY_LENGTH) in this condition, but some versions of GCC don't
960
 * see that the static_assert condition is actually constant in those
961
 * cases, even with constexpr support (?).
962
 */
963
#define NS_INTERFACE_TABLE_END_WITH_PTR(_ptr)                                 \
964
114
  { nullptr, 0 } };                                                           \
965
114
  static_assert((sizeof(table)/sizeof(table[0])) > 1, "need at least 1 interface"); \
966
114
  rv = NS_TableDrivenQI(static_cast<void*>(_ptr),                             \
967
114
                        aIID, aInstancePtr, table);
968
969
#define NS_INTERFACE_TABLE_END                                                \
970
114
  NS_INTERFACE_TABLE_END_WITH_PTR(this)
971
972
#define NS_INTERFACE_TABLE_TAIL                                               \
973
114
  return rv;                                                                  \
974
114
}
975
976
#define NS_INTERFACE_TABLE_TAIL_INHERITING(_baseclass)                        \
977
0
  if (NS_SUCCEEDED(rv))                                                       \
978
0
    return rv;                                                                \
979
0
  return _baseclass::QueryInterface(aIID, aInstancePtr);                      \
980
0
}
981
982
#define NS_INTERFACE_TABLE_TAIL_USING_AGGREGATOR(_aggregator)                 \
983
  if (NS_SUCCEEDED(rv))                                                       \
984
    return rv;                                                                \
985
  NS_ASSERTION(_aggregator, "null aggregator");                               \
986
  return _aggregator->QueryInterface(aIID, aInstancePtr)                      \
987
}
988
989
/**
990
 * This implements query interface with two assumptions: First, the
991
 * class in question implements nsISupports and its own interface and
992
 * nothing else. Second, the implementation of the class's primary
993
 * inheritance chain leads to its own interface.
994
 *
995
 * @param _class The name of the class implementing the method
996
 * @param _classiiddef The name of the #define symbol that defines the IID
997
 * for the class (e.g. NS_ISUPPORTS_IID)
998
 */
999
1000
#define NS_IMPL_QUERY_HEAD(_class)                                            \
1001
8.90k
NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr)      \
1002
8.90k
{                                                                             \
1003
8.90k
  NS_ASSERTION(aInstancePtr,                                                  \
1004
8.90k
               "QueryInterface requires a non-NULL destination!");            \
1005
8.90k
  nsISupports* foundInterface;
1006
1007
#define NS_IMPL_QUERY_BODY(_interface)                                        \
1008
8.90k
  if ( aIID.Equals(NS_GET_IID(_interface)) )                                  \
1009
8.90k
    foundInterface = static_cast<_interface*>(this);                          \
1010
8.90k
  else
1011
1012
#define NS_IMPL_QUERY_BODY_CONDITIONAL(_interface, condition)                 \
1013
0
  if ( (condition) && aIID.Equals(NS_GET_IID(_interface)))                    \
1014
0
    foundInterface = static_cast<_interface*>(this);                          \
1015
0
  else
1016
1017
#define NS_IMPL_QUERY_BODY_AMBIGUOUS(_interface, _implClass)                  \
1018
0
  if ( aIID.Equals(NS_GET_IID(_interface)) )                                  \
1019
0
    foundInterface = static_cast<_interface*>(                                \
1020
0
                                    static_cast<_implClass*>(this));          \
1021
0
  else
1022
1023
// Use this for querying to concrete class types which cannot be unambiguously
1024
// cast to nsISupports. See also nsQueryObject.h.
1025
#define NS_IMPL_QUERY_BODY_CONCRETE(_class)                                   \
1026
  if (aIID.Equals(NS_GET_IID(_class))) {                                      \
1027
    *aInstancePtr = do_AddRef(static_cast<_class*>(this)).take();             \
1028
    return NS_OK;                                                             \
1029
  } else
1030
1031
#define NS_IMPL_QUERY_BODY_AGGREGATED(_interface, _aggregate)                 \
1032
  if ( aIID.Equals(NS_GET_IID(_interface)) )                                  \
1033
    foundInterface = static_cast<_interface*>(_aggregate);                    \
1034
  else
1035
1036
#define NS_IMPL_QUERY_TAIL_GUTS                                               \
1037
0
    foundInterface = 0;                                                       \
1038
8.90k
  nsresult status;                                                            \
1039
8.90k
  if ( !foundInterface )                                                      \
1040
0
    {                                                                         \
1041
0
      /* nsISupports should be handled by this point. If not, fail. */        \
1042
0
      MOZ_ASSERT(!aIID.Equals(NS_GET_IID(nsISupports)));                      \
1043
0
      status = NS_NOINTERFACE;                                                \
1044
0
    }                                                                         \
1045
0
  else                                                                        \
1046
8.90k
    {                                                                         \
1047
8.90k
      NS_ADDREF(foundInterface);                                              \
1048
8.90k
      status = NS_OK;                                                         \
1049
8.90k
    }                                                                         \
1050
0
  *aInstancePtr = foundInterface;                                             \
1051
0
  return status;                                                              \
1052
8.90k
}
1053
1054
#define NS_IMPL_QUERY_TAIL_INHERITING(_baseclass)                             \
1055
0
    foundInterface = 0;                                                       \
1056
0
  nsresult status;                                                            \
1057
0
  if ( !foundInterface )                                                      \
1058
0
    status = _baseclass::QueryInterface(aIID, (void**)&foundInterface);       \
1059
0
  else                                                                        \
1060
0
    {                                                                         \
1061
0
      NS_ADDREF(foundInterface);                                              \
1062
0
      status = NS_OK;                                                         \
1063
0
    }                                                                         \
1064
0
  *aInstancePtr = foundInterface;                                             \
1065
0
  return status;                                                              \
1066
0
}
1067
1068
#define NS_IMPL_QUERY_TAIL_USING_AGGREGATOR(_aggregator)                      \
1069
    foundInterface = 0;                                                       \
1070
  nsresult status;                                                            \
1071
  if ( !foundInterface ) {                                                    \
1072
    NS_ASSERTION(_aggregator, "null aggregator");                             \
1073
    status = _aggregator->QueryInterface(aIID, (void**)&foundInterface);      \
1074
  } else                                                                      \
1075
    {                                                                         \
1076
      NS_ADDREF(foundInterface);                                              \
1077
      status = NS_OK;                                                         \
1078
    }                                                                         \
1079
  *aInstancePtr = foundInterface;                                             \
1080
  return status;                                                              \
1081
}
1082
1083
#define NS_IMPL_QUERY_TAIL(_supports_interface)                               \
1084
  NS_IMPL_QUERY_BODY_AMBIGUOUS(nsISupports, _supports_interface)              \
1085
  NS_IMPL_QUERY_TAIL_GUTS
1086
1087
1088
/*
1089
  This is the new scheme.  Using this notation now will allow us to switch to
1090
  a table driven mechanism when it's ready.  Note the difference between this
1091
  and the (currently) underlying NS_IMPL_QUERY_INTERFACE mechanism.  You must
1092
  explicitly mention |nsISupports| when using the interface maps.
1093
*/
1094
8.90k
#define NS_INTERFACE_MAP_BEGIN(_implClass)      NS_IMPL_QUERY_HEAD(_implClass)
1095
8.90k
#define NS_INTERFACE_MAP_ENTRY(_interface)      NS_IMPL_QUERY_BODY(_interface)
1096
#define NS_INTERFACE_MAP_ENTRY_CONDITIONAL(_interface, condition)             \
1097
0
  NS_IMPL_QUERY_BODY_CONDITIONAL(_interface, condition)
1098
#define NS_INTERFACE_MAP_ENTRY_AGGREGATED(_interface,_aggregate)              \
1099
  NS_IMPL_QUERY_BODY_AGGREGATED(_interface,_aggregate)
1100
1101
0
#define NS_INTERFACE_MAP_END                    NS_IMPL_QUERY_TAIL_GUTS
1102
#define NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(_interface, _implClass)              \
1103
0
  NS_IMPL_QUERY_BODY_AMBIGUOUS(_interface, _implClass)
1104
#define NS_INTERFACE_MAP_ENTRY_CONCRETE(_class)                               \
1105
  NS_IMPL_QUERY_BODY_CONCRETE(_class)
1106
#define NS_INTERFACE_MAP_END_INHERITING(_baseClass)                           \
1107
0
  NS_IMPL_QUERY_TAIL_INHERITING(_baseClass)
1108
#define NS_INTERFACE_MAP_END_AGGREGATED(_aggregator)                          \
1109
  NS_IMPL_QUERY_TAIL_USING_AGGREGATOR(_aggregator)
1110
1111
#define NS_INTERFACE_TABLE0(_class)                                           \
1112
0
  NS_INTERFACE_TABLE_BEGIN                                                    \
1113
0
    NS_INTERFACE_TABLE_ENTRY(_class, nsISupports)                             \
1114
0
  NS_INTERFACE_TABLE_END
1115
1116
#define NS_INTERFACE_TABLE(aClass, ...)                                       \
1117
114
  static_assert(MOZ_ARG_COUNT(__VA_ARGS__) > 0,                               \
1118
114
                "Need more arguments to NS_INTERFACE_TABLE");                 \
1119
114
  NS_INTERFACE_TABLE_BEGIN                                                    \
1120
222
    MOZ_FOR_EACH(NS_INTERFACE_TABLE_ENTRY, (aClass,), (__VA_ARGS__))          \
1121
114
    NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(aClass, nsISupports,                   \
1122
114
                                       MOZ_ARG_1(__VA_ARGS__))                \
1123
114
  NS_INTERFACE_TABLE_END
1124
1125
#define NS_IMPL_QUERY_INTERFACE0(_class)                                      \
1126
0
  NS_INTERFACE_TABLE_HEAD(_class)                                             \
1127
0
  NS_INTERFACE_TABLE0(_class)                                                 \
1128
0
  NS_INTERFACE_TABLE_TAIL
Unexecuted instantiation: nsInvalidPluginTag::QueryInterface(nsID const&, void**)
Unexecuted instantiation: mozilla::plugins::BlocklistPromiseHandler::QueryInterface(nsID const&, void**)
Unexecuted instantiation: nsFoo::QueryInterface(nsID const&, void**)
Unexecuted instantiation: nsBar::QueryInterface(nsID const&, void**)
1129
1130
#define NS_IMPL_QUERY_INTERFACE(aClass, ...)                                  \
1131
114
  NS_INTERFACE_TABLE_HEAD(aClass)                                             \
1132
114
  NS_INTERFACE_TABLE(aClass, __VA_ARGS__)                                     \
1133
114
  NS_INTERFACE_TABLE_TAIL
Unexecuted instantiation: mozilla::JSObjectHolder::QueryInterface(nsID const&, void**)
mozilla::LogModulePrefWatcher::QueryInterface(nsID const&, void**)
Line
Count
Source
1131
3
  NS_INTERFACE_TABLE_HEAD(aClass)                                             \
1132
3
  NS_INTERFACE_TABLE(aClass, __VA_ARGS__)                                     \
1133
3
  NS_INTERFACE_TABLE_TAIL
Unexecuted instantiation: Unified_cpp_xpcom_base0.cpp:(anonymous namespace)::nsMemoryPressureWatcher::QueryInterface(nsID const&, void**)
Unexecuted instantiation: Unified_cpp_xpcom_base0.cpp:(anonymous namespace)::nsJemallocFreeDirtyPagesRunnable::QueryInterface(nsID const&, void**)
Unexecuted instantiation: GenericClassInfo::QueryInterface(nsID const&, void**)
Unexecuted instantiation: nsConsoleMessage::QueryInterface(nsID const&, void**)
nsCycleCollector::QueryInterface(nsID const&, void**)
Line
Count
Source
1131
3
  NS_INTERFACE_TABLE_HEAD(aClass)                                             \
1132
3
  NS_INTERFACE_TABLE(aClass, __VA_ARGS__)                                     \
1133
3
  NS_INTERFACE_TABLE_TAIL
Unexecuted instantiation: nsCycleCollectorLogSinkToFile::QueryInterface(nsID const&, void**)
Unexecuted instantiation: nsCycleCollectorLogger::QueryInterface(nsID const&, void**)
Unexecuted instantiation: FdWatcher::QueryInterface(nsID const&, void**)
nsErrorService::QueryInterface(nsID const&, void**)
Line
Count
Source
1131
6
  NS_INTERFACE_TABLE_HEAD(aClass)                                             \
1132
6
  NS_INTERFACE_TABLE(aClass, __VA_ARGS__)                                     \
1133
6
  NS_INTERFACE_TABLE_TAIL
Unexecuted instantiation: nsGZFileWriter::QueryInterface(nsID const&, void**)
Unexecuted instantiation: nsInterfaceRequestorAgg::QueryInterface(nsID const&, void**)
Unexecuted instantiation: nsMemoryImpl::QueryInterface(nsID const&, void**)
Unexecuted instantiation: nsMemoryImpl::FlushEvent::QueryInterface(nsID const&, void**)
Unexecuted instantiation: nsMemoryInfoDumper::QueryInterface(nsID const&, void**)
Unexecuted instantiation: nsDumpGCAndCCLogsCallbackHolder::QueryInterface(nsID const&, void**)
Unexecuted instantiation: HandleReportAndFinishReportingCallbacks::QueryInterface(nsID const&, void**)
Unexecuted instantiation: TempDirFinishCallback::QueryInterface(nsID const&, void**)
Unexecuted instantiation: VsizeReporter::QueryInterface(nsID const&, void**)
Unexecuted instantiation: ResidentReporter::QueryInterface(nsID const&, void**)
Unexecuted instantiation: ResidentUniqueReporter::QueryInterface(nsID const&, void**)
Unexecuted instantiation: SystemHeapReporter::QueryInterface(nsID const&, void**)
Unexecuted instantiation: ResidentPeakReporter::QueryInterface(nsID const&, void**)
Unexecuted instantiation: PageFaultsSoftReporter::QueryInterface(nsID const&, void**)
Unexecuted instantiation: PageFaultsHardReporter::QueryInterface(nsID const&, void**)
Unexecuted instantiation: AtomTablesReporter::QueryInterface(nsID const&, void**)
Unexecuted instantiation: ThreadsReporter::QueryInterface(nsID const&, void**)
nsMemoryReporterManager::QueryInterface(nsID const&, void**)
Line
Count
Source
1131
76
  NS_INTERFACE_TABLE_HEAD(aClass)                                             \
1132
76
  NS_INTERFACE_TABLE(aClass, __VA_ARGS__)                                     \
1133
76
  NS_INTERFACE_TABLE_TAIL
Unexecuted instantiation: nsMessageLoop::QueryInterface(nsID const&, void**)
Unexecuted instantiation: nsSecurityConsoleMessage::QueryInterface(nsID const&, void**)
nsUUIDGenerator::QueryInterface(nsID const&, void**)
Line
Count
Source
1131
6
  NS_INTERFACE_TABLE_HEAD(aClass)                                             \
1132
6
  NS_INTERFACE_TABLE(aClass, __VA_ARGS__)                                     \
1133
6
  NS_INTERFACE_TABLE_TAIL
Unexecuted instantiation: nsVersionComparatorImpl::QueryInterface(nsID const&, void**)
Unexecuted instantiation: nsWeakReference::QueryInterface(nsID const&, void**)
Unexecuted instantiation: Unified_cpp_xpcom_base2.cpp:(anonymous namespace)::MessageLoopTimerCallback::QueryInterface(nsID const&, void**)
Unexecuted instantiation: mozilla::GenericFactory::QueryInterface(nsID const&, void**)
Unexecuted instantiation: nsCategoryObserver::QueryInterface(nsID const&, void**)
CategoryEntry::QueryInterface(nsID const&, void**)
Line
Count
Source
1131
3
  NS_INTERFACE_TABLE_HEAD(aClass)                                             \
1132
3
  NS_INTERFACE_TABLE(aClass, __VA_ARGS__)                                     \
1133
3
  NS_INTERFACE_TABLE_TAIL
nsCategoryManager::QueryInterface(nsID const&, void**)
Line
Count
Source
1131
14
  NS_INTERFACE_TABLE_HEAD(aClass)                                             \
1132
14
  NS_INTERFACE_TABLE(aClass, __VA_ARGS__)                                     \
1133
14
  NS_INTERFACE_TABLE_TAIL
nsComponentManagerImpl::QueryInterface(nsID const&, void**)
Line
Count
Source
1131
3
  NS_INTERFACE_TABLE_HEAD(aClass)                                             \
1132
3
  NS_INTERFACE_TABLE(aClass, __VA_ARGS__)                                     \
1133
3
  NS_INTERFACE_TABLE_TAIL
Unexecuted instantiation: nsPluginHost::QueryInterface(nsID const&, void**)
Unexecuted instantiation: GetSitesClosure::QueryInterface(nsID const&, void**)
Unexecuted instantiation: mozilla::dom::ContentListener::QueryInterface(nsID const&, void**)
Unexecuted instantiation: mozilla::dom::TabParent::QueryInterface(nsID const&, void**)
Unexecuted instantiation: mozilla::dom::SynthesizedEventObserver::QueryInterface(nsID const&, void**)
Unexecuted instantiation: mozilla::dom::FakeChannel::QueryInterface(nsID const&, void**)
Unexecuted instantiation: mozilla::dom::URLClassifierParent::QueryInterface(nsID const&, void**)
Unexecuted instantiation: mozilla::dom::URLClassifierLocalParent::QueryInterface(nsID const&, void**)
Unexecuted instantiation: GeckoProfilerReporter::QueryInterface(nsID const&, void**)
Unexecuted instantiation: nsProfiler::QueryInterface(nsID const&, void**)
Unexecuted instantiation: nsProfilerStartParams::QueryInterface(nsID const&, void**)
Unexecuted instantiation: ClosedStream::QueryInterface(nsID const&, void**)
Unexecuted instantiation: AsyncStream::QueryInterface(nsID const&, void**)
Unexecuted instantiation: NonBufferableStringStream::QueryInterface(nsID const&, void**)
Unexecuted instantiation: TestObserver::QueryInterface(nsID const&, void**)
Unexecuted instantiation: WaitCondition::QueryInterface(nsID const&, void**)
Unexecuted instantiation: ErrorCondition::QueryInterface(nsID const&, void**)
Unexecuted instantiation: Task::QueryInterface(nsID const&, void**)
Unexecuted instantiation: TestThreadPoolListener::Listener::QueryInterface(nsID const&, void**)
Unexecuted instantiation: TestThreadUtils::SpyWithISupports::QueryInterface(nsID const&, void**)
Unexecuted instantiation: TestThreadUtils::ThreadUtilsObject::QueryInterface(nsID const&, void**)
Unexecuted instantiation: nsRunner::QueryInterface(nsID const&, void**)
Unexecuted instantiation: nsStressRunner::QueryInterface(nsID const&, void**)
Unexecuted instantiation: AsyncShutdownPreparer::QueryInterface(nsID const&, void**)
Unexecuted instantiation: AsyncShutdownWaiter::QueryInterface(nsID const&, void**)
Unexecuted instantiation: SameThreadSentinel::QueryInterface(nsID const&, void**)
Unexecuted instantiation: TimerCallback::QueryInterface(nsID const&, void**)
Unexecuted instantiation: FuzzTestThreadState::QueryInterface(nsID const&, void**)
1134
1135
/**
1136
 * Declare that you're going to inherit from something that already
1137
 * implements nsISupports, but also implements an additional interface, thus
1138
 * causing an ambiguity. In this case you don't need another mRefCnt, you
1139
 * just need to forward the definitions to the appropriate superclass. E.g.
1140
 *
1141
 * class Bar : public Foo, public nsIBar {  // both provide nsISupports
1142
 * public:
1143
 *   NS_DECL_ISUPPORTS_INHERITED
1144
 *   ...other nsIBar and Bar methods...
1145
 * };
1146
 */
1147
#define NS_DECL_ISUPPORTS_INHERITED                                           \
1148
public:                                                                       \
1149
  NS_IMETHOD QueryInterface(REFNSIID aIID,                                    \
1150
                            void** aInstancePtr) override;                \
1151
  NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override;             \
1152
  NS_IMETHOD_(MozExternalRefCountType) Release(void) override;            \
1153
1154
/**
1155
 * These macros can be used in conjunction with NS_DECL_ISUPPORTS_INHERITED
1156
 * to implement the nsISupports methods, forwarding the invocations to a
1157
 * superclass that already implements nsISupports. Don't do anything for
1158
 * subclasses of Runnable because it deals with subclass logging in its own
1159
 * way, using the mName field.
1160
 *
1161
 * Note that I didn't make these inlined because they're virtual methods.
1162
 */
1163
1164
namespace mozilla {
1165
class Runnable;
1166
} // namespace mozilla
1167
1168
#define NS_IMPL_ADDREF_INHERITED_GUTS(Class, Super)                           \
1169
0
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(Class)                                   \
1170
0
  nsrefcnt r = Super::AddRef();                                               \
1171
0
  if (!mozilla::IsConvertible<Class*, mozilla::Runnable*>::value) {           \
1172
0
    NS_LOG_ADDREF(this, r, #Class, sizeof(*this));                            \
1173
0
  }                                                                           \
1174
0
  return r /* Purposefully no trailing semicolon */
1175
1176
#define NS_IMPL_ADDREF_INHERITED(Class, Super)                                \
1177
0
NS_IMETHODIMP_(MozExternalRefCountType) Class::AddRef(void)                   \
1178
0
{                                                                             \
1179
0
  NS_IMPL_ADDREF_INHERITED_GUTS(Class, Super);                                \
1180
0
}
Unexecuted instantiation: Unified_cpp_xpcom_base2.cpp:(anonymous namespace)::GCAndCCLogDumpRunnable::AddRef()
Unexecuted instantiation: CategoryEnumerator::AddRef()
Unexecuted instantiation: mozilla::dom::TabChild::DelayedDeleteRunnable::AddRef()
Unexecuted instantiation: mozilla::dom::TabChild::AddRef()
Unexecuted instantiation: mozilla::dom::TabChildMessageManager::AddRef()
Unexecuted instantiation: CheckResponsivenessTask::AddRef()
1181
1182
#define NS_IMPL_RELEASE_INHERITED_GUTS(Class, Super)                          \
1183
0
  nsrefcnt r = Super::Release();                                              \
1184
0
  if (!mozilla::IsConvertible<Class*, mozilla::Runnable*>::value) {           \
1185
0
    NS_LOG_RELEASE(this, r, #Class);                                          \
1186
0
  }                                                                           \
1187
0
  return r /* Purposefully no trailing semicolon */
1188
1189
#define NS_IMPL_RELEASE_INHERITED(Class, Super)                               \
1190
0
NS_IMETHODIMP_(MozExternalRefCountType) Class::Release(void)                  \
1191
0
{                                                                             \
1192
0
  NS_IMPL_RELEASE_INHERITED_GUTS(Class, Super);                               \
1193
0
}
Unexecuted instantiation: Unified_cpp_xpcom_base2.cpp:(anonymous namespace)::GCAndCCLogDumpRunnable::Release()
Unexecuted instantiation: CategoryEnumerator::Release()
Unexecuted instantiation: mozilla::dom::TabChild::DelayedDeleteRunnable::Release()
Unexecuted instantiation: mozilla::dom::TabChild::Release()
Unexecuted instantiation: mozilla::dom::TabChildMessageManager::Release()
Unexecuted instantiation: CheckResponsivenessTask::Release()
1194
1195
/**
1196
 * As above but not logging the addref/release; needed if the base
1197
 * class might be aggregated.
1198
 */
1199
#define NS_IMPL_NONLOGGING_ADDREF_INHERITED(Class, Super)                     \
1200
NS_IMETHODIMP_(MozExternalRefCountType) Class::AddRef(void)                   \
1201
{                                                                             \
1202
  MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(Class)                                   \
1203
  return Super::AddRef();                                                     \
1204
}
1205
1206
#define NS_IMPL_NONLOGGING_RELEASE_INHERITED(Class, Super)                    \
1207
NS_IMETHODIMP_(MozExternalRefCountType) Class::Release(void)                  \
1208
{                                                                             \
1209
  return Super::Release();                                                    \
1210
}
1211
1212
#define NS_INTERFACE_TABLE_INHERITED0(Class) /* Nothing to do here */
1213
1214
#define NS_INTERFACE_TABLE_INHERITED(aClass, ...)                             \
1215
0
  static_assert(MOZ_ARG_COUNT(__VA_ARGS__) > 0,                               \
1216
0
                "Need more arguments to NS_INTERFACE_TABLE_INHERITED");       \
1217
0
  NS_INTERFACE_TABLE_BEGIN                                                    \
1218
0
    MOZ_FOR_EACH(NS_INTERFACE_TABLE_ENTRY, (aClass,), (__VA_ARGS__))          \
1219
0
  NS_INTERFACE_TABLE_END
1220
1221
#define NS_IMPL_QUERY_INTERFACE_INHERITED(aClass, aSuper, ...)                \
1222
0
  NS_INTERFACE_TABLE_HEAD(aClass)                                             \
1223
0
  NS_INTERFACE_TABLE_INHERITED(aClass, __VA_ARGS__)                           \
1224
0
  NS_INTERFACE_TABLE_TAIL_INHERITING(aSuper)
Unexecuted instantiation: Unified_cpp_xpcom_base2.cpp:(anonymous namespace)::GCAndCCLogDumpRunnable::QueryInterface(nsID const&, void**)
Unexecuted instantiation: CategoryEnumerator::QueryInterface(nsID const&, void**)
Unexecuted instantiation: mozilla::dom::TabChild::DelayedDeleteRunnable::QueryInterface(nsID const&, void**)
Unexecuted instantiation: CheckResponsivenessTask::QueryInterface(nsID const&, void**)
1225
1226
/**
1227
 * Convenience macros for implementing all nsISupports methods for
1228
 * a simple class.
1229
 * @param _class The name of the class implementing the method
1230
 * @param _classiiddef The name of the #define symbol that defines the IID
1231
 * for the class (e.g. NS_ISUPPORTS_IID)
1232
 */
1233
1234
#define NS_IMPL_ISUPPORTS0(_class)                                            \
1235
  NS_IMPL_ADDREF(_class)                                                      \
1236
  NS_IMPL_RELEASE(_class)                                                     \
1237
  NS_IMPL_QUERY_INTERFACE0(_class)
1238
1239
#define NS_IMPL_ISUPPORTS(aClass, ...)                                        \
1240
  NS_IMPL_ADDREF(aClass)                                                      \
1241
  NS_IMPL_RELEASE(aClass)                                                     \
1242
  NS_IMPL_QUERY_INTERFACE(aClass, __VA_ARGS__)
1243
1244
// When possible, prefer NS_INLINE_DECL_REFCOUNTING_INHERITED to
1245
// NS_IMPL_ISUPPORTS_INHERITED0.
1246
#define NS_IMPL_ISUPPORTS_INHERITED0(aClass, aSuper)                          \
1247
    NS_INTERFACE_TABLE_HEAD(aClass)                                           \
1248
    NS_INTERFACE_TABLE_TAIL_INHERITING(aSuper)                                \
1249
    NS_IMPL_ADDREF_INHERITED(aClass, aSuper)                                  \
1250
    NS_IMPL_RELEASE_INHERITED(aClass, aSuper)                                 \
1251
1252
#define NS_IMPL_ISUPPORTS_INHERITED(aClass, aSuper, ...)                      \
1253
  NS_IMPL_QUERY_INTERFACE_INHERITED(aClass, aSuper, __VA_ARGS__)              \
1254
  NS_IMPL_ADDREF_INHERITED(aClass, aSuper)                                    \
1255
  NS_IMPL_RELEASE_INHERITED(aClass, aSuper)
1256
1257
/**
1258
 * A macro to declare and implement addref/release for a class that does not
1259
 * need to QI to any interfaces other than the ones its parent class QIs to.
1260
 * This can be a no-op when we're not building with refcount logging, because in
1261
 * that case there's no real reason to have a separate addref/release on this
1262
 * class.
1263
 */
1264
#if defined(NS_BUILD_REFCNT_LOGGING)
1265
#define NS_INLINE_DECL_REFCOUNTING_INHERITED(Class, Super)      \
1266
  NS_IMETHOD_(MozExternalRefCountType) AddRef() override {      \
1267
    NS_IMPL_ADDREF_INHERITED_GUTS(Class, Super);                \
1268
  }                                                             \
1269
  NS_IMETHOD_(MozExternalRefCountType) Release() override {     \
1270
    NS_IMPL_RELEASE_INHERITED_GUTS(Class, Super);               \
1271
  }
1272
#else // NS_BUILD_REFCNT_LOGGING
1273
#define NS_INLINE_DECL_REFCOUNTING_INHERITED(Class, Super)
1274
#endif // NS_BUILD_REFCNT_LOGGINGx
1275
1276
/*
1277
 * Macro to glue together a QI that starts with an interface table
1278
 * and segues into an interface map (e.g. it uses singleton classinfo
1279
 * or tearoffs).
1280
 */
1281
#define NS_INTERFACE_TABLE_TO_MAP_SEGUE \
1282
  if (rv == NS_OK) return rv; \
1283
  nsISupports* foundInterface;
1284
1285
1286
///////////////////////////////////////////////////////////////////////////////
1287
1288
/**
1289
 * Macro to generate nsIClassInfo methods for classes which do not have
1290
 * corresponding nsIFactory implementations.
1291
 */
1292
#define NS_IMPL_THREADSAFE_CI(_class)                                         \
1293
NS_IMETHODIMP                                                                 \
1294
_class::GetInterfaces(uint32_t* _count, nsIID*** _array)                      \
1295
{                                                                             \
1296
  return NS_CI_INTERFACE_GETTER_NAME(_class)(_count, _array);                 \
1297
}                                                                             \
1298
                                                                              \
1299
NS_IMETHODIMP                                                                 \
1300
_class::GetScriptableHelper(nsIXPCScriptable** _retval)                       \
1301
{                                                                             \
1302
  *_retval = nullptr;                                                         \
1303
  return NS_OK;                                                               \
1304
}                                                                             \
1305
                                                                              \
1306
NS_IMETHODIMP                                                                 \
1307
_class::GetContractID(nsACString& _contractID)                                \
1308
{                                                                             \
1309
  _contractID.SetIsVoid(true);                                                \
1310
  return NS_OK;                                                               \
1311
}                                                                             \
1312
                                                                              \
1313
NS_IMETHODIMP                                                                 \
1314
_class::GetClassDescription(nsACString& _classDescription)                    \
1315
{                                                                             \
1316
  _classDescription.SetIsVoid(true);                                          \
1317
  return NS_OK;                                                               \
1318
}                                                                             \
1319
                                                                              \
1320
NS_IMETHODIMP                                                                 \
1321
_class::GetClassID(nsCID** _classID)                                          \
1322
{                                                                             \
1323
  *_classID = nullptr;                                                        \
1324
  return NS_OK;                                                               \
1325
}                                                                             \
1326
                                                                              \
1327
NS_IMETHODIMP                                                                 \
1328
_class::GetFlags(uint32_t* _flags)                                            \
1329
{                                                                             \
1330
  *_flags = nsIClassInfo::THREADSAFE;                                         \
1331
  return NS_OK;                                                               \
1332
}                                                                             \
1333
                                                                              \
1334
NS_IMETHODIMP                                                                 \
1335
_class::GetClassIDNoAlloc(nsCID* _classIDNoAlloc)                             \
1336
{                                                                             \
1337
  return NS_ERROR_NOT_AVAILABLE;                                              \
1338
}
1339
1340
#endif