XPCOMGC/Static Checker: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(storage classes)
(finalizers required... separate section)
Line 26: Line 26:
  <th>Global
  <th>Global
  <th>Destructor is Finalizer-safe
  <th>Destructor is Finalizer-safe
<th>Requires Finalizer
  <th>Notes
  <th>Notes
<tr>
<tr>
Line 34: Line 33:
  <td>No
  <td>No
  <td>No
  <td>No
<td>
  <td>
  <td>
  <td>must only be on the stack
  <td>must only be on the stack
Line 44: Line 42:
  <td>No
  <td>No
  <td>Yes
  <td>Yes
<td>
  <td>Requires rooting
  <td>Requires rooting
<tr>
<tr>
Line 52: Line 49:
  <td>
  <td>
  <td>No
  <td>No
  <td>Yes
  <td>May only appear on the GC heap
<td>
<tr>
<tr>
  <th>NS_NOGC_TYPE
  <th>NS_NOGC_TYPE
Line 59: Line 55:
  <td>
  <td>
  <td>No
  <td>No
<td>
  <td>
  <td>
  <td>
  <td>
Line 70: Line 65:
  <td>
  <td>
  <td>Yes
  <td>Yes
<td>
  <td>May be GC-allocated.
  <td>May be GC-allocated. Does not require finalizer
<tr>
<th>NS_GCFINALIZED_OK
<td>
<td>
<td>
<td>
<td>Yes
<td>Yes
<td>May be GC-allocated. Requires a finalizer. example: nsString
</table>
</table>
=== When are finalizers required? ===
Any class with a destructor must be finalized unless it is annotated with NS_FINALIZER_NOT_NEEDED</tt>

Revision as of 19:16, 15 July 2008

Taras and/or dmandelin will work on an extended GCC which will provide additional static-checking capabilities for the Mozilla codebase. The following is a preliminary set of static checks to perform for the XPCOMGC codebase. Initially many of these checks will fail and should be warnings, not hard errors.

  • If a class inherits from XPCOMGCFinalizedObject, the left-most base other than XPCOMGCFinalizedObject must be MMgc::GCFinalizedBase
  • Certain classes may be allocated only on the stack or on the heap... bsmedberg is happy to annotate these classes. TODO: how to annotate? It's important to catch instances where these classes are members of other classes being heap or stack allocated. And it's important that in both these cases, static allocations are disallowed.
  • For any class which inherits from MMgc::GCFinalizedBase:
    • The destructor must not dereference any member pointer to a GC object
    • The destructor must not call functions which are not annotated "safe for finalizers" TODO: how to annotate?
  • For any class inheriting from XPCOMGCObject or XPCOMGCFinalizedObject
    • raw members pointing to GC objects are not allowed... they must either be nsCOMPtr or they must be annotated indicating that they are a "safe" raw pointer. TODO: how to annotate?
  • For any class *not* inheriting from XPCOMGCObject or XPCOMGCFinalizedObject
    • the class must not contain nsCOMPtr member variables
    • the class may not contain member pointers to GC objects, unless those members are annotated "safe for GC marking" TODO: how to annotate?

Annotations are combined to find the most restrictive combination.

Annotation Stack Malloc GCHeap Global Destructor is Finalizer-safe Notes
NS_STACK_CLASS No No No must only be on the stack
NS_MANAGED No No Yes Requires rooting
NS_GC_TYPE No No No May only appear on the GC heap
NS_NOGC_TYPE No Must not appear on the GC heap
NS_GCOK Yes May be GC-allocated.

When are finalizers required?

Any class with a destructor must be finalized unless it is annotated with NS_FINALIZER_NOT_NEEDED