Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 169 lines (132 sloc) 4.586 kb
28676a2 @rue TypeInfo stores info whether cleanup required.
rue authored
1 #ifndef RBX_VM_TYPE_INFO_HPP
2 #define RBX_VM_TYPE_INFO_HPP
bbe450f Code purge and reorganization.
Evan Phoenix authored
3
feb91b4 Tons of stuff (too much probably)
Evan Phoenix authored
4 #include <map>
5 #include <stdexcept>
eaa8061 Add accessor specialization for internal types
Evan Phoenix authored
6 #include <vector>
feb91b4 Tons of stuff (too much probably)
Evan Phoenix authored
7
eaa8061 Add accessor specialization for internal types
Evan Phoenix authored
8 #include "object_types.hpp"
9 #include "prelude.hpp"
10 #include "executor.hpp"
879a046 A whole slew. Enhanced type-info, debugged GC.
Evan Phoenix authored
11
bbe450f Code purge and reorganization.
Evan Phoenix authored
12 namespace rubinius {
28676a2 @rue TypeInfo stores info whether cleanup required.
rue authored
13
bbe450f Code purge and reorganization.
Evan Phoenix authored
14 class Class;
3a0e9a4 @rue Renamed vm/object.hpp to vm/object_utils.hpp. File/#include shuffling.
rue authored
15 class Object;
16 class ObjectMark;
5e917ee Move TypeInfo::init under ObjectMemory
Evan Phoenix authored
17 class ObjectMemory;
dfc8638 Refactor out header flag access
Evan Phoenix authored
18 class ObjectHeader;
bbe450f Code purge and reorganization.
Evan Phoenix authored
19
460e0ac @evanphx Introduce GCToken to track all GCable code paths
evanphx authored
20 class GCTokenImpl {
21 private:
22 int dummy;
23 };
24
25 typedef GCTokenImpl& GCToken;
26
28676a2 @rue TypeInfo stores info whether cleanup required.
rue authored
27 /**
28 * Static type information for the VM.
29 *
30 * Due to memory layout restrictions, virtual methods cannot exist
31 * on builtin types. This class abstracts those operations out of
32 * the classes themselves. Using virtual dispatch here allows the
33 * correct method implementation to be invoked, based on the object's
34 * obj_type field.
35 *
36 * @see doc/builtin_internal_resource_releasing.txt
37 * @see vm/object_types.hpp
38 * @see builtin/object.hpp
39 */
bbe450f Code purge and reorganization.
Evan Phoenix authored
40 class TypeInfo {
5e917ee Move TypeInfo::init under ObjectMemory
Evan Phoenix authored
41 public: // Types
feb91b4 Tons of stuff (too much probably)
Evan Phoenix authored
42
28676a2 @rue TypeInfo stores info whether cleanup required.
rue authored
43 typedef std::map<native_int, long> Slots;
eaa8061 Add accessor specialization for internal types
Evan Phoenix authored
44 typedef std::vector<executor> AccessorPrimitives;
0252c23 Add push_my_offset, a fast (but unsafe) version of push_my_field
Evan Phoenix authored
45 typedef std::vector<uintptr_t> SlotLocations;
bbe450f Code purge and reorganization.
Evan Phoenix authored
46
5e917ee Move TypeInfo::init under ObjectMemory
Evan Phoenix authored
47 private: /* Instance vars */
48 VM* state_;
49
50 public:
51
52 size_t instance_size;
9735a95 @libc Baker GC optimizations.
libc authored
53 static size_t instance_sizes[(int)LastObjectType];
5e917ee Move TypeInfo::init under ObjectMemory
Evan Phoenix authored
54 Slots slots;
eaa8061 Add accessor specialization for internal types
Evan Phoenix authored
55 AccessorPrimitives slot_accessors;
0252c23 Add push_my_offset, a fast (but unsafe) version of push_my_field
Evan Phoenix authored
56 SlotLocations slot_locations;
5e917ee Move TypeInfo::init under ObjectMemory
Evan Phoenix authored
57 object_type type;
58 std::string type_name;
72cc050 Add flag to disallow direct allocation. Fixes #335.
Evan Phoenix authored
59 bool allow_user_allocate;
5e917ee Move TypeInfo::init under ObjectMemory
Evan Phoenix authored
60
61 public: /* Class initializers */
62
63 static void init(ObjectMemory* om);
64 static void auto_init(ObjectMemory* om);
65 static void auto_learn_fields(STATE);
b55c456 More TypeInfo and ObjectHeader cleanup
Evan Phoenix authored
66 virtual void auto_mark(Object* obj, ObjectMark& mark) = 0;
c785864 Add ability to have custom mark logic
Evan Phoenix authored
67
28676a2 @rue TypeInfo stores info whether cleanup required.
rue authored
68 public: /* Ctors */
69
70 /**
71 * Make a new TypeInfo.
72 *
73 * To support TypeInfo hierarchies where some classes may
74 * and some may not need e.g. a cleanup, the instantiation
75 * will set the cleanup flag if _any_ of the classes in
76 * the chain request it.
77 */
7cdde43 Allocate cleanup phase 1
Evan Phoenix authored
78 TypeInfo(object_type type);
28676a2 @rue TypeInfo stores info whether cleanup required.
rue authored
79
879a046 A whole slew. Enhanced type-info, debugged GC.
Evan Phoenix authored
80 virtual ~TypeInfo();
28676a2 @rue TypeInfo stores info whether cleanup required.
rue authored
81
82 public: /* Interface */
83
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
84 void set_state(STATE);
5e917ee Move TypeInfo::init under ObjectMemory
Evan Phoenix authored
85
86 VM* state() {
87 return state_;
88 }
89
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
90 virtual void mark(Object* obj, ObjectMark& mark);
45be183 Add new Immix GC as the mature GC
Evan Phoenix authored
91
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
92 virtual void set_field(STATE, Object* target, size_t index, Object* val);
93 virtual Object* get_field(STATE, Object* target, size_t index);
751d850 @brixen Some additional docs for TaskProbe and show functions.
brixen authored
94
0252c23 Add push_my_offset, a fast (but unsafe) version of push_my_field
Evan Phoenix authored
95 virtual void populate_slot_locations() { }
96
9735a95 @libc Baker GC optimizations.
libc authored
97 /**
98 * Slow case, should be called only if instance_size is zero
99 */
100 virtual size_t object_size(const ObjectHeader * obj);
dfc8638 Refactor out header flag access
Evan Phoenix authored
101
751d850 @brixen Some additional docs for TaskProbe and show functions.
brixen authored
102 /**
7caf020 Remove broken const-ness
Evan Phoenix authored
103 * Currently prints the same output as show_simple. Is specialized by
751d850 @brixen Some additional docs for TaskProbe and show functions.
brixen authored
104 * complex classes to e.g. limit the recursion into nested
105 * objects to make the output more manageable. See e.g. Tuple
106 * and CompiledMethod. Immediates and numeric classes print
107 * their value for both show and show_simple.
108 */
7caf020 Remove broken const-ness
Evan Phoenix authored
109 virtual void show(STATE, Object* self, int level);
110
111 /**
112 * Default output for any object. Prints just the class name
113 * and address. It is expected that classes will define their own
114 * show output.
115 */
116 virtual void show_simple(STATE, Object* self, int level);
751d850 @brixen Some additional docs for TaskProbe and show functions.
brixen authored
117
118 /**
119 * Prints spaces to indent the following text to the requested
120 * level. Levels are specified as 0, 1, 2, ... and the multiplier
121 * is 2. So, text at level 2 will have 2 * 2 = 4 spaces in front.
122 */
d9b3457 @brixen Cleaned up TypeInfo::show helper functions.
brixen authored
123 virtual void indent(int level);
751d850 @brixen Some additional docs for TaskProbe and show functions.
brixen authored
124
125 /**
126 * Indents the attribute name to the requested level. @see indent.
127 */
b84458d @brixen A couple more TypeInfo::show helpers.
brixen authored
128 virtual void indent_attribute(int level, const char* name);
751d850 @brixen Some additional docs for TaskProbe and show functions.
brixen authored
129
130 /**
131 * Prints out the class name and address. Used for simple classes
132 * that may append other info on the same line.
133 *
134 * #<SomeClass:0x346882
135 */
1f0ca40 @rue Rudimentary const correctness fixes. This needs attention.
rue authored
136 virtual void class_info(STATE, const Object* self, bool newline = false);
751d850 @brixen Some additional docs for TaskProbe and show functions.
brixen authored
137
138 /**
139 * Prints out the class name and address followed by a newline. Used
140 * for complex classes that will print additional member info.
141 *
142 * #<SomeClass:0x3287648\n
143 */
1f0ca40 @rue Rudimentary const correctness fixes. This needs attention.
rue authored
144 virtual void class_header(STATE, const Object* self);
751d850 @brixen Some additional docs for TaskProbe and show functions.
brixen authored
145
146 /**
147 * Prints "..." + endl at the requested indent level.
148 */
fa0a28d @brixen Made show output for CompiledMethod simpler.
brixen authored
149 virtual void ellipsis(int level);
751d850 @brixen Some additional docs for TaskProbe and show functions.
brixen authored
150
151 /**
152 * Indents to level-1 and prints ">" + endl.
153 */
b84458d @brixen A couple more TypeInfo::show helpers.
brixen authored
154 virtual void close_body(int level);
28676a2 @rue TypeInfo stores info whether cleanup required.
rue authored
155
bbe450f Code purge and reorganization.
Evan Phoenix authored
156 };
879a046 A whole slew. Enhanced type-info, debugged GC.
Evan Phoenix authored
157
28676a2 @rue TypeInfo stores info whether cleanup required.
rue authored
158 }
159
160
879a046 A whole slew. Enhanced type-info, debugged GC.
Evan Phoenix authored
161 #define BASIC_TYPEINFO(super) \
7cdde43 Allocate cleanup phase 1
Evan Phoenix authored
162 Info(object_type type) : super(type) { } \
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
163 virtual void auto_mark(Object* obj, ObjectMark& mark); \
164 virtual void set_field(STATE, Object* target, size_t index, Object* val); \
0252c23 Add push_my_offset, a fast (but unsafe) version of push_my_field
Evan Phoenix authored
165 virtual Object* get_field(STATE, Object* target, size_t index); \
166 virtual void populate_slot_locations();
bbe450f Code purge and reorganization.
Evan Phoenix authored
167
168 #endif
Something went wrong with that request. Please try again.