add stronger typing to code.lineNumberTable

This commit is contained in:
Joshua Warner 2014-06-27 21:46:14 -06:00 committed by Joshua Warner
parent 194e3b2701
commit 083dc17810
5 changed files with 40 additions and 30 deletions

View File

@ -6340,7 +6340,7 @@ object translateExceptionHandlerTable(MyThread* t,
object object
translateLineNumberTable(MyThread* t, Context* context, intptr_t start) translateLineNumberTable(MyThread* t, Context* context, intptr_t start)
{ {
object oldTable = codeLineNumberTable(t, context->method->code()); object oldTable = reinterpret_cast<object>(codeLineNumberTable(t, context->method->code()));
if (oldTable) { if (oldTable) {
PROTECT(t, oldTable); PROTECT(t, oldTable);
@ -6844,7 +6844,7 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context)
object code = context->method->code(); object code = context->method->code();
code = reinterpret_cast<object>(makeCode code = reinterpret_cast<object>(makeCode
(t, 0, newExceptionHandlerTable, newLineNumberTable, (t, 0, newExceptionHandlerTable, cast<GcLineNumberTable>(t, newLineNumberTable),
reinterpret_cast<uintptr_t>(start), codeSize, codeMaxStack(t, code), reinterpret_cast<uintptr_t>(start), codeSize, codeMaxStack(t, code),
codeMaxLocals(t, code), 0)); codeMaxLocals(t, code), 0));

View File

@ -5498,7 +5498,7 @@ vmAddressFromLine(Thread* t, object m, unsigned line)
{ {
object code = methodCode(t, m); object code = methodCode(t, m);
printf("code: %p\n", code); printf("code: %p\n", code);
object lnt = codeLineNumberTable(t, code); object lnt = reinterpret_cast<object>(codeLineNumberTable(t, code));
printf("lnt: %p\n", lnt); printf("lnt: %p\n", lnt);
if (lnt) { if (lnt) {

View File

@ -267,7 +267,7 @@ findLineNumber(Thread* t, GcMethod* method, unsigned ip)
-- ip; -- ip;
object code = method->code(); object code = method->code();
object lnt = codeLineNumberTable(t, code); object lnt = reinterpret_cast<object>(codeLineNumberTable(t, code));
if (lnt) { if (lnt) {
unsigned bottom = 0; unsigned bottom = 0;
unsigned top = lineNumberTableLength(t, lnt); unsigned top = lineNumberTableLength(t, lnt);

View File

@ -205,11 +205,20 @@ endsWith(const std::string& b, const std::string& a)
return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin()); return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin());
} }
std::string enumName(std::string& type) { std::string enumName(Module& module, Field& f) {
std::string& type = f.typeName;
if (type == "void*") { if (type == "void*") {
return "word"; return "word";
}
if(f.javaSpec.size() != 0 && (f.javaSpec[0] == 'L' || f.javaSpec[0] == '[')) {
return "object";
}
std::map<std::string, Class*>::iterator it = module.classes.find(f.typeName);
assert(f.typeName.size() > 0);
if(it != module.classes.end()) {
return "object";
} else { } else {
return type; return f.typeName;
} }
} }
@ -1169,7 +1178,7 @@ writeConstructors(Output* out, Module& module)
bool hasObjectMask = cl->name == "singleton"; bool hasObjectMask = cl->name == "singleton";
for(std::vector<Field*>::iterator it = cl->fields.begin(); it != cl->fields.end(); it++) { for(std::vector<Field*>::iterator it = cl->fields.begin(); it != cl->fields.end(); it++) {
Field& f = **it; Field& f = **it;
if (f.typeName == "object" if (enumName(module, f) == "object"
and not f.nogc) and not f.nogc)
{ {
out->write(" PROTECT(t, "); out->write(" PROTECT(t, ");
@ -1240,7 +1249,7 @@ set(uint32_t* mask, unsigned index)
} }
uint32_t uint32_t
typeObjectMask(Class* cl) typeObjectMask(Module& module, Class* cl)
{ {
assert(cl->fixedSize + (cl->arrayField ? cl->arrayField->elementSize : 0) assert(cl->fixedSize + (cl->arrayField ? cl->arrayField->elementSize : 0)
< 32 * BytesPerWord); < 32 * BytesPerWord);
@ -1250,7 +1259,7 @@ typeObjectMask(Class* cl)
for(std::vector<Field*>::iterator it = cl->fields.begin(); it != cl->fields.end(); it++) { for(std::vector<Field*>::iterator it = cl->fields.begin(); it != cl->fields.end(); it++) {
Field& f = **it; Field& f = **it;
unsigned offset = f.offset / BytesPerWord; unsigned offset = f.offset / BytesPerWord;
if(f.typeName == "object" && !f.nogc) { if(enumName(module, f) == "object" && !f.nogc) {
set(&mask, offset); set(&mask, offset);
} }
} }
@ -1258,7 +1267,7 @@ typeObjectMask(Class* cl)
if(cl->arrayField) { if(cl->arrayField) {
Field& f = *cl->arrayField; Field& f = *cl->arrayField;
unsigned offset = f.offset / BytesPerWord; unsigned offset = f.offset / BytesPerWord;
if(f.typeName == "object" && !f.nogc) { if(enumName(module, f) == "object" && !f.nogc) {
set(&mask, offset); set(&mask, offset);
} }
} }
@ -1267,14 +1276,14 @@ typeObjectMask(Class* cl)
} }
void void
writeInitialization(Output* out, std::set<Class*>& alreadyInited, Class* cl) writeInitialization(Output* out, Module& module, std::set<Class*>& alreadyInited, Class* cl)
{ {
if(alreadyInited.find(cl) != alreadyInited.end()) { if(alreadyInited.find(cl) != alreadyInited.end()) {
return; return;
} }
alreadyInited.insert(cl); alreadyInited.insert(cl);
if(cl->super && cl->name != "intArray" && cl->name != "class") { if(cl->super && cl->name != "intArray" && cl->name != "class") {
writeInitialization(out, alreadyInited, cl->super); writeInitialization(out, module, alreadyInited, cl->super);
} }
out->write("bootClass(t, Gc::"); out->write("bootClass(t, Gc::");
out->write(capitalize(cl->name)); out->write(capitalize(cl->name));
@ -1289,8 +1298,8 @@ writeInitialization(Output* out, std::set<Class*>& alreadyInited, Class* cl)
} }
out->write(", "); out->write(", ");
if (typeObjectMask(cl) != 1) { if (typeObjectMask(module, cl) != 1) {
out->write(typeObjectMask(cl)); out->write(typeObjectMask(module, cl));
} else { } else {
out->write("0"); out->write("0");
} }
@ -1311,13 +1320,13 @@ writeInitializations(Output* out, Module& module)
{ {
std::set<Class*> alreadyInited; std::set<Class*> alreadyInited;
writeInitialization(out, alreadyInited, module.classes["intArray"]); writeInitialization(out, module, alreadyInited, module.classes["intArray"]);
writeInitialization(out, alreadyInited, module.classes["class"]); writeInitialization(out, module, alreadyInited, module.classes["class"]);
for(std::map<std::string, Class*>::iterator it = module.classes.begin(); it != module.classes.end(); ++it) { for(std::map<std::string, Class*>::iterator it = module.classes.begin(); it != module.classes.end(); ++it) {
Class* cl = it->second; Class* cl = it->second;
if(cl->name != "intArray" && cl->name != "class") { if(cl->name != "intArray" && cl->name != "class") {
writeInitialization(out, alreadyInited, cl); writeInitialization(out, module, alreadyInited, cl);
} }
} }
} }
@ -1396,7 +1405,7 @@ writeNameInitializations(Output* out, Module& module)
} }
void void
writeMap(Output* out, Class* cl) writeMap(Output* out, Module& module, Class* cl)
{ {
std::ostringstream ss; std::ostringstream ss;
uintptr_t ownerId = 0; uintptr_t ownerId = 0;
@ -1409,7 +1418,7 @@ writeMap(Output* out, Class* cl)
ownerId = f.ownerId; ownerId = f.ownerId;
ss << "Type_"; ss << "Type_";
ss << enumName(f.typeName); ss << enumName(module, f);
if (f.nogc) { if (f.nogc) {
ss << "_nogc"; ss << "_nogc";
} }
@ -1424,7 +1433,7 @@ writeMap(Output* out, Class* cl)
} }
ss << "Type_array, "; ss << "Type_array, ";
ss << "Type_"; ss << "Type_";
ss << enumName(f.typeName); ss << enumName(module, f);
ss << ", "; ss << ", ";
} }
@ -1451,7 +1460,7 @@ writeMaps(Output* out, Module& module)
out->write("// "); out->write("// ");
out->write(cl->name); out->write(cl->name);
out->write("\n{ "); out->write("\n{ ");
writeMap(out, cl); writeMap(out, module, cl);
out->write(" }"); out->write(" }");
} }
out->write("\n};"); out->write("\n};");

View File

@ -78,15 +78,6 @@
(type lineNumberTable (type lineNumberTable
(array uint64_t body)) (array uint64_t body))
(type code avian/Code
(object pool)
(object exceptionHandlerTable)
(object lineNumberTable)
(intptr_t compiled)
(uint32_t compiledSize)
(uint16_t maxStack)
(uint16_t maxLocals)
(array uint8_t body))
(type reference (type reference
(uint8_t kind) (uint8_t kind)
@ -335,6 +326,16 @@
(extends jobject) (extends jobject)
(array int32_t body)) (array int32_t body))
(type code avian/Code
(object pool)
(object exceptionHandlerTable)
(lineNumberTable lineNumberTable)
(intptr_t compiled)
(uint32_t compiledSize)
(uint16_t maxStack)
(uint16_t maxLocals)
(array uint8_t body))
(type longArray [J (type longArray [J
(extends jobject) (extends jobject)
(array int64_t body)) (array int64_t body))