File: Runtime.h

package info (click to toggle)
storm-lang 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,028 kB
  • sloc: ansic: 261,471; cpp: 140,432; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (204 lines) | stat: -rw-r--r-- 7,156 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#pragma once
#include "GcArray.h"
#include <cstdarg>

namespace storm {
	struct GcType;
	struct GcCode;
	class GcWatch;
	class RootObject;
	class CloneEnv;
	class StdRequest;

	namespace runtime {

		/**
		 * This file declares the interface to the runtime that code in Core/ needs, but can not be
		 * implemented here, as the implementation differs depending on if Core/ is linked to the
		 * Compiler/ or a shared library. For shared libraries, include SharedLib.h from *one*
		 * source file, to get the implementation suitable for shared libraries (which just
		 * delegates calls to the compiler linked at runtime).
		 */

		// Get the Storm type description for a C++ type given its ID (used by the generated type information code).
		Type *cppType(Engine &e, Nat id);

		// Variadic argument variant of 'cppTemplate'.
		Type *cppTemplateVa(Engine &e, Nat id, Nat count, va_list params);

		// Get the Storm type description for a C++ template, given its ID and template type ids (we
		// do not support eg. Array<Array<X>> from C++.
		inline Type *cppTemplate(Engine &e, Nat id, Nat count, ...) {
			Type *r;
			va_list l;
			va_start(l, count);
			r = cppTemplateVa(e, id, count, l);
			va_end(l);
			return r;
		}

		// Get a type handle for 'type'.
		const Handle &typeHandle(Type *t);

		// Get the handle for 'void'.
		const Handle &voidHandle(Engine &e);

		// Get the handle for treating regular objects as reference types in hash maps.
		const Handle &refObjHandle(Engine &e);

		// Get the current type of an object. Note, this takes the current state of vtables
		// into account, and may not match the "allocation type" of the object.
		Type *typeOf(const RootObject *o);

		// Get the type used when allocating the object. Note that his may be more specific than
		// what "typeOf" would return while the object is being constructed. This is mostly useful
		// for cases where it is relevant to modify the object's current vtable.
		Type *allocTypeOf(const RootObject *o);

		// Get the GcType for an allocation.
		const GcType *gcTypeOf(const void *alloc);

		// Get the GcType for a particular Storm type.
		const GcType *typeGc(Type *t);

		// Get the name of a type (expected to be used for pretty-printing).
		Str *typeName(Type *t);

		// Get a (mangled) identifier of a type that is suitable for serialization.
		Str *typeIdentifier(Type *t);

		// Get the type with the mangled name 'name'.
		MAYBE(Type *) fromIdentifier(Str *name);

		// Is 't' a value type?
		bool isValue(Type *t);

		// Is type A an instance of type B?
		bool isA(const Type *a, const Type *b);

		// Is the object A an instance of type B?
		bool isA(const RootObject *a, const Type *b);

		// Get the engine object for an allocation.
		Engine &allocEngine(const RootObject *o);

		// Allocate some raw memory for some data.
		void *allocRaw(Engine &e, const GcType *type);

		template <size_t count>
		void *allocRaw(Engine &e, const StaticGcType<count> *type) {
			return allocRaw(e, (const GcType *)type);
		}

		// Allocate some non-moving raw memory for some data.
		void *allocStaticRaw(Engine &e, const GcType *type);

		template <size_t count>
		inline void *allocStaticRaw(Engine &e, const StaticGcType<count> *type) {
			return allocStaticRaw(e, (const GcType *)type);
		}

		// Allocate a buffer which is safe to use from any thread in the system (even threads not
		// registered with Storm).
		GcArray<Byte> *allocBuffer(Engine &e, size_t count);

		// Allocate an object of the given type (size used for sanity checking).
		void *allocObject(size_t size, Type *type);

		// Allocate an array of objects.
		void *allocArray(Engine &e, const GcType *type, size_t count);

		template <size_t sz>
		inline void *allocArray(Engine &e, const StaticGcType<sz> *type, size_t count) {
			return allocArray(e, (const GcType *)type, count);
		}

		template <class T>
		inline GcArray<T> *allocArray(Engine &e, const GcType *type, size_t count) {
			return (GcArray<T> *)allocArray(e, type, count);
		}

		template <class T, size_t sz>
		inline GcArray<T> *allocArray(Engine &e, const StaticGcType<sz> *type, size_t count) {
			return (GcArray<T> *)allocArray(e, type, count);
		}

		// Allocate an array of objects in response to a re-hash. Affects the behavior of the GC in
		// respect to scheduling collections.
		void *allocArrayRehash(Engine &e, const GcType *type, size_t count);

		template <class T>
		inline GcArray<T> *allocArrayRehash(Engine &e, const GcType *type, size_t count) {
			return (GcArray<T> *)allocArrayRehash(e, type, count);
		}

		// Allocate a weak array of pointers.
		void *allocWeakArray(Engine &e, size_t count);

		template <class T>
		inline GcWeakArray<T> *allocWeakArray(Engine &e, size_t count) {
			return (GcWeakArray<T> *)allocWeakArray(e, count);
		}

		// Allocate a weak array of pointers in response to a re-hash. Affects the behavior of the
		// GC in respect to scheduling collections.
		void *allocWeakArrayRehash(Engine &e, size_t count);

		template <class T>
		inline GcWeakArray<T> *allocWeakArrayRehash(Engine &e, size_t count) {
			return (GcWeakArray<T> *)allocWeakArrayRehash(e, count);
		}

		// Allocate a code segment with at least 'code' bytes of memory for the code, and 'refs'
		// entries for references.
		void *allocCode(Engine &e, size_t code, size_t refs);

		// Get the code size of a previous code allocation (references are not counted).
		size_t codeSize(const void *code);

		// Get the references for a block of code.
		GcCode *codeRefs(void *code);

		// Update all pointers in a code allocation. This copies all pointer values from the
		// 'codeRef' section into the data section.
		void codeUpdatePtrs(void *code);

		// Re-set the vtable of an object to what it should be.
		void setVTable(RootObject *object);

		// Check if the current TObject is a live object. Objects may be finalized by the GC before
		// they are collected, so we shall consider them as "nonexistent" during that time. This is
		// relevant in the implementation of containers like WeakSet.
		bool liveObject(RootObject *object);

		// Get the thread group to use for all threads.
		os::ThreadGroup &threadGroup(Engine &e);

		// Get the lock used to synchronize thread startup in the Thread class.
		util::Lock &threadLock(Engine &e);

		// Create a GcWatch object.
		GcWatch *createWatch(Engine &e);

		// Post an IO-request for standard in/out/error.
		void postStdRequest(Engine &e, StdRequest *request);

		// Clone any heap-allocated object from C++.
		RootObject *CODECALL cloneObject(RootObject *obj);
		RootObject *CODECALL cloneObjectEnv(RootObject *obj, CloneEnv *env);

		// Check consistency of an object. Only available when GC debugging is active. Not available
		// in shared libraries.
		void checkObject(Engine &e, const void *obj);

		// Get some engine. If a thread was created from a particular engine, that engine is
		// returned. This is intended to be used in cases where exceptions (rarely) need to be
		// thrown, not for general use.
		Engine &someEngine();

		// Get some engine, but may return null. The version above asserts on error.
		Engine *someEngineUnsafe();


	}
}