Loading...
Searching...
No Matches
mjs_gc.h
1/*
2 * Copyright (c) 2014 Cesanta Software Limited
3 * All rights reserved
4 */
5
6#ifndef MJS_GC_H_
7#define MJS_GC_H_
8
9#include "mjs_core.h"
10#include "mjs_mm.h"
11#include "mjs_internal.h"
12#include "mjs_gc_public.h"
13
14#if defined(__cplusplus)
15extern "C" {
16#endif /* __cplusplus */
17
18/*
19 * performs arithmetics on gc_cell pointers as if they were arena->cell_size
20 * bytes wide
21 */
22#define GC_CELL_OP(arena, cell, op, arg) \
23 ((struct gc_cell*)(((char*)(cell))op((arg) * (arena)->cell_size)))
24
25struct gc_cell {
26 union {
27 struct gc_cell* link;
28 uintptr_t word;
29 } head;
30};
31
32MJS_PRIVATE int gc_strings_is_gc_needed(struct mjs* mjs);
33
34/* perform gc if not inhibited */
35MJS_PRIVATE int maybe_gc(struct mjs* mjs);
36
37MJS_PRIVATE struct mjs_object* new_object(struct mjs*);
38MJS_PRIVATE struct mjs_property* new_property(struct mjs*);
39MJS_PRIVATE struct mjs_ffi_sig* new_ffi_sig(struct mjs* mjs);
40
41MJS_PRIVATE void gc_mark(struct mjs* mjs, mjs_val_t* val);
42
43MJS_PRIVATE void gc_arena_init(struct gc_arena*, size_t, size_t, size_t);
44MJS_PRIVATE void gc_arena_destroy(struct mjs*, struct gc_arena* a);
45MJS_PRIVATE void gc_sweep(struct mjs*, struct gc_arena*, size_t);
46MJS_PRIVATE void* gc_alloc_cell(struct mjs*, struct gc_arena*);
47
48MJS_PRIVATE uint64_t gc_string_mjs_val_to_offset(mjs_val_t v);
49
50/* return 0 if v is an object/function with a bad pointer */
51MJS_PRIVATE int gc_check_val(struct mjs* mjs, mjs_val_t v);
52
53/* checks whether a pointer is within the ranges of an arena */
54MJS_PRIVATE int gc_check_ptr(const struct gc_arena* a, const void* p);
55
56#if defined(__cplusplus)
57}
58#endif /* __cplusplus */
59
60#endif /* MJS_GC_H_ */
Definition mjs_mm.h:25
Definition mjs_gc.h:25
Definition mjs_ffi.h:30
Definition mjs_object.h:24
Definition mjs_object.h:18
Definition mjs_core.h:63