Replace HNDTYPE defines with enum in gcinterface header.
authorAditya Mandaleeka <adityam@microsoft.com>
Thu, 9 Mar 2017 02:40:12 +0000 (18:40 -0800)
committerAditya Mandaleeka <adityam@microsoft.com>
Mon, 13 Mar 2017 23:52:42 +0000 (16:52 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/9e1e0b7c8f4d5ef1602ab6947a597559effbe60f

src/coreclr/src/gc/gcinterface.h
src/coreclr/src/gc/handletable.h
src/coreclr/src/gc/objecthandle.h

index 1d0699c..9f88d7b 100644 (file)
@@ -102,6 +102,11 @@ struct WriteBarrierParameters
     uint8_t* write_watch_table;
 };
 
+ /*
+  * Scanning callback.
+  */
+typedef void (CALLBACK *HANDLESCANPROC)(PTR_UNCHECKED_OBJECTREF pref, uintptr_t *pExtraInfo, uintptr_t param1, uintptr_t param2);
+
 #include "gcinterface.ee.h"
 
 // The allocation context must be known to the VM for use in the allocation
@@ -236,6 +241,145 @@ enum end_no_gc_region_status
     end_no_gc_alloc_exceeded = 3
 };
 
+typedef enum 
+{
+    /*
+     * WEAK HANDLES
+     *
+     * Weak handles are handles that track an object as long as it is alive,
+     * but do not keep the object alive if there are no strong references to it.
+     *
+     */
+
+    /*
+     * SHORT-LIVED WEAK HANDLES
+     *
+     * Short-lived weak handles are weak handles that track an object until the
+     * first time it is detected to be unreachable.  At this point, the handle is
+     * severed, even if the object will be visible from a pending finalization
+     * graph.  This further implies that short weak handles do not track
+     * across object resurrections.
+     *
+     */
+    HNDTYPE_WEAK_SHORT   = 0,
+
+    /*
+     * LONG-LIVED WEAK HANDLES
+     *
+     * Long-lived weak handles are weak handles that track an object until the
+     * object is actually reclaimed.  Unlike short weak handles, long weak handles
+     * continue to track their referents through finalization and across any
+     * resurrections that may occur.
+     *
+     */
+    HNDTYPE_WEAK_LONG    = 1,
+    HNDTYPE_WEAK_DEFAULT = 1,
+
+    /*
+     * STRONG HANDLES
+     *
+     * Strong handles are handles which function like a normal object reference.
+     * The existence of a strong handle for an object will cause the object to
+     * be promoted (remain alive) through a garbage collection cycle.
+     *
+     */
+    HNDTYPE_STRONG       = 2,
+    HNDTYPE_DEFAULT      = 2,
+
+    /*
+     * PINNED HANDLES
+     *
+     * Pinned handles are strong handles which have the added property that they
+     * prevent an object from moving during a garbage collection cycle.  This is
+     * useful when passing a pointer to object innards out of the runtime while GC
+     * may be enabled.
+     *
+     * NOTE:  PINNING AN OBJECT IS EXPENSIVE AS IT PREVENTS THE GC FROM ACHIEVING
+     *        OPTIMAL PACKING OF OBJECTS DURING EPHEMERAL COLLECTIONS.  THIS TYPE
+     *        OF HANDLE SHOULD BE USED SPARINGLY!
+     */
+    HNDTYPE_PINNED       = 3,
+
+    /*
+     * VARIABLE HANDLES
+     *
+     * Variable handles are handles whose type can be changed dynamically.  They
+     * are larger than other types of handles, and are scanned a little more often,
+     * but are useful when the handle owner needs an efficient way to change the
+     * strength of a handle on the fly.
+     * 
+     */
+    HNDTYPE_VARIABLE     = 4,
+
+    /*
+     * REFCOUNTED HANDLES
+     *
+     * Refcounted handles are handles that behave as strong handles while the
+     * refcount on them is greater than 0 and behave as weak handles otherwise.
+     *
+     * N.B. These are currently NOT general purpose.
+     *      The implementation is tied to COM Interop.
+     *
+     */
+    HNDTYPE_REFCOUNTED   = 5,
+
+    /*
+     * DEPENDENT HANDLES
+     *
+     * Dependent handles are two handles that need to have the same lifetime.  One handle refers to a secondary object 
+     * that needs to have the same lifetime as the primary object. The secondary object should not cause the primary 
+     * object to be referenced, but as long as the primary object is alive, so must be the secondary
+     *
+     * They are currently used for EnC for adding new field members to existing instantiations under EnC modes where
+     * the primary object is the original instantiation and the secondary represents the added field.
+     *
+     * They are also used to implement the ConditionalWeakTable class in mscorlib.dll. If you want to use
+     * these from managed code, they are exposed to BCL through the managed DependentHandle class.
+     *
+     *
+     */
+    HNDTYPE_DEPENDENT    = 6,
+
+    /*
+     * PINNED HANDLES for asynchronous operation
+     *
+     * Pinned handles are strong handles which have the added property that they
+     * prevent an object from moving during a garbage collection cycle.  This is
+     * useful when passing a pointer to object innards out of the runtime while GC
+     * may be enabled.
+     *
+     * NOTE:  PINNING AN OBJECT IS EXPENSIVE AS IT PREVENTS THE GC FROM ACHIEVING
+     *        OPTIMAL PACKING OF OBJECTS DURING EPHEMERAL COLLECTIONS.  THIS TYPE
+     *        OF HANDLE SHOULD BE USED SPARINGLY!
+     */
+    HNDTYPE_ASYNCPINNED  = 7,
+
+    /*
+     * SIZEDREF HANDLES
+     *
+     * SizedRef handles are strong handles. Each handle has a piece of user data associated
+     * with it that stores the size of the object this handle refers to. These handles
+     * are scanned as strong roots during each GC but only during full GCs would the size
+     * be calculated.
+     *
+     */
+    HNDTYPE_SIZEDREF     = 8,
+
+    /*
+     * WINRT WEAK HANDLES
+     *
+     * WinRT weak reference handles hold two different types of weak handles to any
+     * RCW with an underlying COM object that implements IWeakReferenceSource.  The
+     * object reference itself is a short weak handle to the RCW.  In addition an
+     * IWeakReference* to the underlying COM object is stored, allowing the handle
+     * to create a new RCW if the existing RCW is collected.  This ensures that any
+     * code holding onto a WinRT weak reference can always access an RCW to the
+     * underlying COM object as long as it has not been released by all of its strong
+     * references.
+     */
+    HNDTYPE_WEAK_WINRT   = 9
+} HandleType;
+
 typedef BOOL (* walk_fn)(Object*, void*);
 typedef void (* gen_walk_fn)(void* context, int generation, uint8_t* range_start, uint8_t* range_end, uint8_t* range_reserved);
 typedef void (* record_surv_fn)(uint8_t* begin, uint8_t* end, ptrdiff_t reloc, size_t context, BOOL compacting_p, BOOL bgc_p);
index bbb8b1d..2e84765 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef _HANDLETABLE_H
 #define _HANDLETABLE_H
 
+#include "gcinterface.h"
 
 /****************************************************************************
  *
@@ -103,11 +104,6 @@ void            HndWriteBarrier(OBJECTHANDLE handle, OBJECTREF value);
  */
 void            HndLogSetEvent(OBJECTHANDLE handle, _UNCHECKED_OBJECTREF value);
 
- /*
-  * Scanning callback.
-  */
-typedef void (CALLBACK *HANDLESCANPROC)(PTR_UNCHECKED_OBJECTREF pref, uintptr_t *pExtraInfo, uintptr_t param1, uintptr_t param2);
-
 /*
  * NON-GC handle enumeration
  */
index 34c2a0e..9c885bb 100644 (file)
 #define ObjectHandleIsNull(handle)                 HndIsNull(handle)
 #define IsHandleNullUnchecked(handle)              HndCheckForNullUnchecked(handle)
 
-
-/*
- * HANDLES
- *
- * The default type of handle is a strong handle.
- *
- */
-#define HNDTYPE_DEFAULT                         HNDTYPE_STRONG
-
-
-/*
- * WEAK HANDLES
- *
- * Weak handles are handles that track an object as long as it is alive,
- * but do not keep the object alive if there are no strong references to it.
- *
- * The default type of weak handle is 'long-lived' weak handle.
- *
- */
-#define HNDTYPE_WEAK_DEFAULT                    HNDTYPE_WEAK_LONG
-
-
-/*
- * SHORT-LIVED WEAK HANDLES
- *
- * Short-lived weak handles are weak handles that track an object until the
- * first time it is detected to be unreachable.  At this point, the handle is
- * severed, even if the object will be visible from a pending finalization
- * graph.  This further implies that short weak handles do not track
- * across object resurrections.
- *
- */
-#define HNDTYPE_WEAK_SHORT                      (0)
-
-
-/*
- * LONG-LIVED WEAK HANDLES
- *
- * Long-lived weak handles are weak handles that track an object until the
- * object is actually reclaimed.  Unlike short weak handles, long weak handles
- * continue to track their referents through finalization and across any
- * resurrections that may occur.
- *
- */
-#define HNDTYPE_WEAK_LONG                       (1)
-
-
-/*
- * STRONG HANDLES
- *
- * Strong handles are handles which function like a normal object reference.
- * The existence of a strong handle for an object will cause the object to
- * be promoted (remain alive) through a garbage collection cycle.
- *
- */
-#define HNDTYPE_STRONG                          (2)
-
-
-/*
- * PINNED HANDLES
- *
- * Pinned handles are strong handles which have the added property that they
- * prevent an object from moving during a garbage collection cycle.  This is
- * useful when passing a pointer to object innards out of the runtime while GC
- * may be enabled.
- *
- * NOTE:  PINNING AN OBJECT IS EXPENSIVE AS IT PREVENTS THE GC FROM ACHIEVING
- *        OPTIMAL PACKING OF OBJECTS DURING EPHEMERAL COLLECTIONS.  THIS TYPE
- *        OF HANDLE SHOULD BE USED SPARINGLY!
- */
-#define HNDTYPE_PINNED                          (3)
-
-
-/*
- * VARIABLE HANDLES
- *
- * Variable handles are handles whose type can be changed dynamically.  They
- * are larger than other types of handles, and are scanned a little more often,
- * but are useful when the handle owner needs an efficient way to change the
- * strength of a handle on the fly.
- * 
- */
-#define HNDTYPE_VARIABLE                        (4)
-
-#if defined(FEATURE_COMINTEROP) || defined(FEATURE_REDHAWK)
-/*
- * REFCOUNTED HANDLES
- *
- * Refcounted handles are handles that behave as strong handles while the
- * refcount on them is greater than 0 and behave as weak handles otherwise.
- *
- * N.B. These are currently NOT general purpose.
- *      The implementation is tied to COM Interop.
- *
- */
-#define HNDTYPE_REFCOUNTED                      (5)
-#endif // FEATURE_COMINTEROP || FEATURE_REDHAWK
-
-
-/*
- * DEPENDENT HANDLES
- *
- * Dependent handles are two handles that need to have the same lifetime.  One handle refers to a secondary object 
- * that needs to have the same lifetime as the primary object. The secondary object should not cause the primary 
- * object to be referenced, but as long as the primary object is alive, so must be the secondary
- *
- * They are currently used for EnC for adding new field members to existing instantiations under EnC modes where
- * the primary object is the original instantiation and the secondary represents the added field.
- *
- * They are also used to implement the ConditionalWeakTable class in mscorlib.dll. If you want to use
- * these from managed code, they are exposed to BCL through the managed DependentHandle class.
- *
- *
- */
-#define HNDTYPE_DEPENDENT                            (6)
-
-/*
- * PINNED HANDLES for asynchronous operation
- *
- * Pinned handles are strong handles which have the added property that they
- * prevent an object from moving during a garbage collection cycle.  This is
- * useful when passing a pointer to object innards out of the runtime while GC
- * may be enabled.
- *
- * NOTE:  PINNING AN OBJECT IS EXPENSIVE AS IT PREVENTS THE GC FROM ACHIEVING
- *        OPTIMAL PACKING OF OBJECTS DURING EPHEMERAL COLLECTIONS.  THIS TYPE
- *        OF HANDLE SHOULD BE USED SPARINGLY!
- */
-#define HNDTYPE_ASYNCPINNED                          (7)
-
-
-/*
- * SIZEDREF HANDLES
- *
- * SizedRef handles are strong handles. Each handle has a piece of user data associated
- * with it that stores the size of the object this handle refers to. These handles
- * are scanned as strong roots during each GC but only during full GCs would the size
- * be calculated.
- *
- */
-#define HNDTYPE_SIZEDREF                             (8)
-
-#ifdef FEATURE_COMINTEROP
-
-/*
- * WINRT WEAK HANDLES
- *
- * WinRT weak reference handles hold two different types of weak handles to any
- * RCW with an underlying COM object that implements IWeakReferenceSource.  The
- * object reference itself is a short weak handle to the RCW.  In addition an
- * IWeakReference* to the underlying COM object is stored, allowing the handle
- * to create a new RCW if the existing RCW is collected.  This ensures that any
- * code holding onto a WinRT weak reference can always access an RCW to the
- * underlying COM object as long as it has not been released by all of its strong
- * references.
- */
-#define HNDTYPE_WEAK_WINRT                           (9)
-
-#endif // FEATURE_COMINTEROP
-
 typedef DPTR(struct HandleTableMap) PTR_HandleTableMap;
 typedef DPTR(struct HandleTableBucket) PTR_HandleTableBucket;
 typedef DPTR(PTR_HandleTableBucket) PTR_PTR_HandleTableBucket;