generate makeZeroed method, to return a zero-initialzed instance of a Gc* class

This commit is contained in:
Joshua Warner 2014-07-11 13:47:43 -06:00
parent 836cc41320
commit 8a4b043ee3
2 changed files with 38 additions and 40 deletions

View File

@ -9692,42 +9692,14 @@ void boot(MyThread* t, BootImage* image, uint8_t* code)
t->m->types = reinterpret_cast<GcArray*>(bootObject(heap, image->types)); t->m->types = reinterpret_cast<GcArray*>(bootObject(heap, image->types));
t->m->roots = makeRoots(t, t->m->roots = GcRoots::makeZeroed(t);
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0);
;
roots(t)->setBootLoader( roots(t)->setBootLoader(
t, cast<GcClassLoader>(t, bootObject(heap, image->bootLoader))); t, cast<GcClassLoader>(t, bootObject(heap, image->bootLoader)));
roots(t)->setAppLoader( roots(t)->setAppLoader(
t, cast<GcClassLoader>(t, bootObject(heap, image->appLoader))); t, cast<GcClassLoader>(t, bootObject(heap, image->appLoader)));
p->roots = makeCompileRoots(t, 0, 0, 0, 0, 0, 0, 0, 0, 0); p->roots = GcCompileRoots::makeZeroed(t);
compileRoots(t)->setMethodTree( compileRoots(t)->setMethodTree(
t, cast<GcTreeNode>(t, bootObject(heap, image->methodTree))); t, cast<GcTreeNode>(t, bootObject(heap, image->methodTree)));

View File

@ -1192,6 +1192,12 @@ void writeClasses(Output* out, Module& module)
out->write(capitalize(cl->name)); out->write(capitalize(cl->name));
out->write(";\n\n"); out->write(";\n\n");
out->write(" static Gc" + capitalize(cl->name) + "* makeZeroed(Thread* t");
if (cl->arrayField) {
out->write(", uintptr_t length");
}
out->write(");\n");
writeClassAccessors(out, module, cl); writeClassAccessors(out, module, cl);
out->write("};\n\n"); out->write("};\n\n");
@ -1269,17 +1275,40 @@ void writeConstructors(Output* out, Module& module)
it != module.classes.end(); it != module.classes.end();
++it) { ++it) {
Class* cl = it->second; Class* cl = it->second;
out->write("Gc");
out->write(capitalize(cl->name)); bool hasObjectMask = cl->name == "singleton";
out->write("* make");
std::string name = "Gc" + capitalize(cl->name);
out->write(name + "* " + name + "::makeZeroed(Thread* t");
if (cl->arrayField) {
out->write(", uintptr_t length");
}
out->write(")\n{\n");
out->write(" " + name + "* o = reinterpret_cast<" + name
+ "*>(allocate(t, ");
writeOffset(out, cl);
if (hasObjectMask) {
out->write(", true");
} else {
out->write(", false");
}
out->write("));\n");
out->write(" setObjectClass(t, reinterpret_cast<object>(o), ");
out->write(
"reinterpret_cast<GcClass*>(reinterpret_cast<GcArray*>(t->m->types)->"
"body()[Gc::");
out->write(capitalize(cl->name)); out->write(capitalize(cl->name));
out->write("Type]));\n");
out->write(" return o;\n");
out->write("}\n\n");
out->write(name + "* make" + capitalize(cl->name));
out->write("(Thread* t"); out->write("(Thread* t");
writeConstructorParameters(out, module, cl); writeConstructorParameters(out, module, cl);
out->write(")\n{\n"); out->write(")\n{\n");
bool hasObjectMask = cl->name == "singleton";
for (std::vector<Field*>::iterator it = cl->fields.begin(); for (std::vector<Field*>::iterator it = cl->fields.begin();
it != cl->fields.end(); it != cl->fields.end();
it++) { it++) {
@ -1299,11 +1328,8 @@ void writeConstructors(Output* out, Module& module)
} }
} }
out->write(" Gc"); out->write(" " + name + "* o = reinterpret_cast<" + name
out->write(capitalize(cl->name)); + "*>(allocate(t, ");
out->write("* o = reinterpret_cast<Gc");
out->write(capitalize(cl->name));
out->write("*>(allocate(t, ");
writeOffset(out, cl); writeOffset(out, cl);
if (hasObjectMask) { if (hasObjectMask) {
out->write(", true"); out->write(", true");