/* Garbage collection for the GNU compiler.
- Copyright (C) 1998-2013 Free Software Foundation, Inc.
+ Copyright (C) 1998-2014 Free Software Foundation, Inc.
This file is part of GCC.
/* Allocation. */
/* The internal primitive. */
-extern void *ggc_internal_alloc_stat (size_t MEM_STAT_DECL)
- ATTRIBUTE_MALLOC;
+extern void *ggc_internal_alloc (size_t, void (*)(void *), size_t,
+ size_t CXX_MEM_STAT_INFO)
+ ATTRIBUTE_MALLOC;
-extern size_t ggc_round_alloc_size (size_t requested_size);
+ static inline
+ void *
+ ggc_internal_alloc (size_t s CXX_MEM_STAT_INFO)
+{
+ return ggc_internal_alloc (s, NULL, 0, 1 PASS_MEM_STAT);
+}
-#define ggc_internal_alloc(s) ggc_internal_alloc_stat (s MEM_STAT_INFO)
+extern size_t ggc_round_alloc_size (size_t requested_size);
/* Allocates cleared memory. */
-extern void *ggc_internal_cleared_alloc_stat (size_t MEM_STAT_DECL)
- ATTRIBUTE_MALLOC;
+extern void *ggc_internal_cleared_alloc (size_t, void (*)(void *),
+ size_t, size_t
+ CXX_MEM_STAT_INFO) ATTRIBUTE_MALLOC;
+
+static inline
+void *
+ggc_internal_cleared_alloc (size_t s CXX_MEM_STAT_INFO)
+{
+ return ggc_internal_cleared_alloc (s, NULL, 0, 1 PASS_MEM_STAT);
+}
/* Resize a block. */
-extern void *ggc_realloc_stat (void *, size_t MEM_STAT_DECL);
+extern void *ggc_realloc (void *, size_t CXX_MEM_STAT_INFO);
/* Free a block. To be used when known for certain it's not reachable. */
extern void ggc_free (void *);
extern void dump_ggc_loc_statistics (bool);
-/* Reallocators. */
+/* Reallocator. */
#define GGC_RESIZEVEC(T, P, N) \
- ((T *) ggc_realloc_stat ((P), (N) * sizeof (T) MEM_STAT_INFO))
+ ((T *) ggc_realloc ((P), (N) * sizeof (T) MEM_STAT_INFO))
-#define GGC_RESIZEVAR(T, P, N) \
- ((T *) ggc_realloc_stat ((P), (N) MEM_STAT_INFO))
+template<typename T>
+void
+finalize (void *p)
+{
+ static_cast<T *> (p)->~T ();
+}
-static inline void *
-ggc_internal_vec_alloc_stat (size_t s, size_t c MEM_STAT_DECL)
+template<typename T>
+static inline bool
+need_finalization_p ()
{
- return ggc_internal_alloc_stat (c * s PASS_MEM_STAT);
+#if GCC_VERSION >= 4003
+ return !__has_trivial_destructor (T);
+#else
+ return true;
+#endif
}
-static inline void *
-ggc_internal_cleared_vec_alloc_stat (size_t s, size_t c MEM_STAT_DECL)
+template<typename T>
+static inline T *
+ggc_alloc (ALONE_CXX_MEM_STAT_INFO)
{
- return ggc_internal_cleared_alloc_stat (c * s PASS_MEM_STAT);
+ if (need_finalization_p<T> ())
+ return static_cast<T *> (ggc_internal_alloc (sizeof (T), finalize<T>, 0, 1
+ PASS_MEM_STAT));
+ else
+ return static_cast<T *> (ggc_internal_alloc (sizeof (T), NULL, 0, 1
+ PASS_MEM_STAT));
}
-#define ggc_internal_cleared_vec_alloc(s, c) \
- (ggc_internal_cleared_vec_alloc_stat ((s), (c) MEM_STAT_INFO))
+template<typename T>
+static inline T *
+ggc_cleared_alloc (ALONE_CXX_MEM_STAT_INFO)
+{
+ if (need_finalization_p<T> ())
+ return static_cast<T *> (ggc_internal_cleared_alloc (sizeof (T),
+ finalize<T>, 0, 1
+ PASS_MEM_STAT));
+ else
+ return static_cast<T *> (ggc_internal_cleared_alloc (sizeof (T), NULL, 0, 1
+ PASS_MEM_STAT));
+}
-static inline void *
-ggc_alloc_atomic_stat (size_t s MEM_STAT_DECL)
+template<typename T>
+static inline T *
+ggc_vec_alloc (size_t c CXX_MEM_STAT_INFO)
{
- return ggc_internal_alloc_stat (s PASS_MEM_STAT);
+ if (need_finalization_p<T> ())
+ return static_cast<T *> (ggc_internal_alloc (c * sizeof (T), finalize<T>,
+ sizeof (T), c PASS_MEM_STAT));
+ else
+ return static_cast<T *> (ggc_internal_alloc (c * sizeof (T), NULL, 0, 0
+ PASS_MEM_STAT));
}
-#define ggc_alloc_atomic(S) (ggc_alloc_atomic_stat ((S) MEM_STAT_INFO))
+template<typename T>
+static inline T *
+ggc_cleared_vec_alloc (size_t c CXX_MEM_STAT_INFO)
+{
+ if (need_finalization_p<T> ())
+ return static_cast<T *> (ggc_internal_cleared_alloc (c * sizeof (T),
+ finalize<T>,
+ sizeof (T), c
+ PASS_MEM_STAT));
+ else
+ return static_cast<T *> (ggc_internal_cleared_alloc (c * sizeof (T), NULL,
+ 0, 0 PASS_MEM_STAT));
+}
-#define ggc_alloc_cleared_atomic(S) \
- (ggc_internal_cleared_alloc_stat ((S) MEM_STAT_INFO))
+static inline void *
+ggc_alloc_atomic (size_t s CXX_MEM_STAT_INFO)
+{
+ return ggc_internal_alloc (s PASS_MEM_STAT);
+}
extern void *ggc_cleared_alloc_htab_ignore_args (size_t, size_t)
ATTRIBUTE_MALLOC;
/* Allocate a gc-able string, and fill it with LENGTH bytes from CONTENTS.
If LENGTH is -1, then CONTENTS is assumed to be a
null-terminated string and the memory sized accordingly. */
-extern const char *ggc_alloc_string_stat (const char *contents, int length
- MEM_STAT_DECL);
-
-#define ggc_alloc_string(c, l) ggc_alloc_string_stat (c, l MEM_STAT_INFO)
+extern const char *ggc_alloc_string (const char *contents, int length
+ CXX_MEM_STAT_INFO);
/* Make a copy of S, in GC-able memory. */
-#define ggc_strdup(S) ggc_alloc_string_stat ((S), -1 MEM_STAT_INFO)
+#define ggc_strdup(S) ggc_alloc_string ((S), -1 MEM_STAT_INFO)
/* Invoke the collector. Garbage collection occurs only when this
function is called, not during allocations. */
extern void ggc_collect (void);
+/* Assume that all GGC memory is reachable and grow the limits for next collection. */
+extern void ggc_grow (void);
+
/* Register an additional root table. This can be useful for some
plugins. Does nothing if the passed pointer is NULL. */
extern void ggc_register_root_tab (const struct ggc_root_tab *);
extern void init_ggc_heuristics (void);
#define ggc_alloc_rtvec_sized(NELT) \
- ggc_alloc_rtvec_def (sizeof (struct rtvec_def) \
+ (rtvec_def *) ggc_internal_alloc (sizeof (struct rtvec_def) \
+ ((NELT) - 1) * sizeof (rtx)) \
/* Memory statistics passing versions of some allocators. Too few of them to
make gengtype produce them, so just define the needed ones here. */
static inline struct rtx_def *
-ggc_alloc_rtx_def_stat (size_t s MEM_STAT_DECL)
+ggc_alloc_rtx_def_stat (size_t s CXX_MEM_STAT_INFO)
{
- return (struct rtx_def *) ggc_internal_alloc_stat (s PASS_MEM_STAT);
+ return (struct rtx_def *) ggc_internal_alloc (s PASS_MEM_STAT);
}
static inline union tree_node *
-ggc_alloc_tree_node_stat (size_t s MEM_STAT_DECL)
+ggc_alloc_tree_node_stat (size_t s CXX_MEM_STAT_INFO)
{
- return (union tree_node *) ggc_internal_alloc_stat (s PASS_MEM_STAT);
+ return (union tree_node *) ggc_internal_alloc (s PASS_MEM_STAT);
}
static inline union tree_node *
-ggc_alloc_cleared_tree_node_stat (size_t s MEM_STAT_DECL)
+ggc_alloc_cleared_tree_node_stat (size_t s CXX_MEM_STAT_INFO)
{
- return (union tree_node *) ggc_internal_cleared_alloc_stat (s PASS_MEM_STAT);
+ return (union tree_node *) ggc_internal_cleared_alloc (s PASS_MEM_STAT);
}
-static inline union gimple_statement_d *
-ggc_alloc_cleared_gimple_statement_d_stat (size_t s MEM_STAT_DECL)
+static inline struct gimple_statement_base *
+ggc_alloc_cleared_gimple_statement_stat (size_t s CXX_MEM_STAT_INFO)
{
- return (union gimple_statement_d *)
- ggc_internal_cleared_alloc_stat (s PASS_MEM_STAT);
+ return (struct gimple_statement_base *)
+ ggc_internal_cleared_alloc (s PASS_MEM_STAT);
}
-/* gengtype will autogenerate traversal functions (in gtype-desc.c) for
- all GTY-marked types that it sees are referenced by a GTY marker.
-
- Unfortunately, it will not generate traveral functions for types that
- are only referenced by GTY((user)) types.
-
- The following templates are a substitute, providing equivalent
- traversal functions for such types. They are instantiated for
- types whose objects that are traversed during GC/PCH, and are
- called *every time* that an instance of type T is traversed during
- GC/PCH.
-
- They require the presence of the following member functions
-
- void gt_ggc_mx ();
- void gt_pch_nx ();
- void gt_pch_nx_with_op (gt_pointer_operator op, void *cookie);
+static inline void
+gt_ggc_mx (const char *s)
+{
+ ggc_test_and_set_mark (const_cast<char *> (s));
+}
- within class T, which are called *once* per object - the first
- time the object is visited during the traversal. */
+static inline void
+gt_pch_nx (const char *)
+{
+}
-template<class T>
-inline void gt_ggc_mx (T *p)
+static inline void
+gt_ggc_mx (int)
{
- if (ggc_test_and_set_mark (p))
- p->gt_ggc_mx ();
}
-template<class T>
-void gt_pch_nx_with_op (void *this_obj, void *p,
- gt_pointer_operator op, void *cookie)
+static inline void
+gt_pch_nx (int)
{
- if (p == this_obj)
- {
- T *t = static_cast<T *>(p);
- t->gt_pch_nx_with_op (op, cookie);
- }
}
-template<class T>
-inline void gt_pch_nx (T *p)
+static inline void
+gt_pch_nx (unsigned int)
{
- if (gt_pch_note_object (p, p, gt_pch_nx_with_op<T>))
- p->gt_pch_nx ();
}
#endif