Added spec:commit task to commit changes to spec/ruby sources.
[rbx.git] / shotgun / lib / object_memory-inline.h
blobbabb41d9a103202f738c5cd2b6da44261c388166
1 #include "shotgun/lib/auto.h"
3 #if CONFIG_ENABLE_DTRACE
4 #include "shotgun/lib/dtrace_probes.h"
5 #endif
7 static inline void _om_apply_class_flags(OBJECT obj, OBJECT cls) {
8 obj->CanStoreIvars = (class_get_has_ivars(cls) == Qtrue);
9 obj->RequiresCleanup = (class_get_needs_cleanup(cls) == Qtrue);
10 obj->obj_type = N2I(class_get_object_type(cls));
13 static inline OBJECT _om_inline_new_object(object_memory om, OBJECT cls, unsigned int fields) {
14 unsigned int size;
15 gc_zone loc;
16 OBJECT obj;
18 if(fields > LargeObjectThreshold) {
19 mark_sweep_gc ms = om->ms;
20 obj = mark_sweep_allocate(ms, fields);
21 if(ms->enlarged) {
22 om->collect_now |= OMCollectMature;
25 loc = MatureObjectZone;
26 } else {
27 size = SIZE_IN_BYTES_FIELDS(fields);
28 if(!heap_enough_space_p(om->gc->current, size)) {
29 if(!heap_enough_space_p(om->gc->next, size)) {
30 mark_sweep_gc ms = om->ms;
31 obj = mark_sweep_allocate(ms, fields);
32 if(ms->enlarged) {
33 om->collect_now |= OMCollectMature;
36 loc = MatureObjectZone;
37 } else {
38 loc = YoungObjectZone;
39 obj = (OBJECT)baker_gc_allocate_spilled(om->gc, size);
40 // DEBUG("Ran out of space! spilled into %p\n", obj);
41 om->collect_now |= OMCollectYoung;
42 // baker_gc_enlarge_next(om->gc, om->gc->current->size * GC_SCALING_FACTOR);
44 } else {
45 obj = (OBJECT)baker_gc_allocate(om->gc, size);
46 loc = YoungObjectZone;
50 CLEAR_FLAGS(obj);
52 obj->gc_zone = loc;
54 rbs_set_class(om, obj, cls);
55 SET_NUM_FIELDS(obj, fields);
56 if(cls && REFERENCE_P(cls)) {
57 _om_apply_class_flags(obj, cls);
60 return obj;
63 static inline OBJECT _om_inline_new_object_init(object_memory om, OBJECT cls, unsigned int fields) {
64 OBJECT obj;
66 #if ENABLE_DTRACE
67 if (RUBINIUS_OBJECT_CREATE_START_ENABLED() && om->bootstrap_loaded == 1) {
68 object_create_start(cls);
70 #endif
72 obj = _om_inline_new_object(om, cls, fields);
73 fast_memfill((void*)BYTES_OF(obj), (uintptr_t)Qnil, fields);
75 #if ENABLE_DTRACE
76 if (RUBINIUS_OBJECT_CREATE_DONE_ENABLED() && om->bootstrap_loaded == 1) {
77 object_create_done(cls);
79 #endif
81 return obj;
84 static inline OBJECT _om_new_ultra(object_memory om, OBJECT cls, unsigned int size) {
85 OBJECT obj;
86 /* I'd love to remove this check, but context allocation could flow over. */
87 if(!heap_enough_space_p(om->gc->current, size)) {
88 obj = (OBJECT)baker_gc_allocate_spilled_ultra(om->gc, size);
89 om->collect_now |= OMCollectYoung;
90 } else {
91 obj = (OBJECT)baker_gc_allocate_ultra(om->gc, size);
94 CLEAR_FLAGS(obj);
95 obj->gc_zone = YoungObjectZone;
96 rbs_set_class(om, obj, cls);
98 return obj;