[Sablevm-developer] reflection classes for constant pool and bytecode data
Brought to you by:
egagnon
From: Andrew P. <apu...@ac...> - 2000-08-11 03:58:55
|
Hi, SableVM developers! I've been looking over the SableVM sources and I think the first step toward creating a JIT should be the addition of a simple class hierarchy containing native methods for exposing SableVM's internal representations of the constant pool and (prepared) bytecodes to the Java environment. I've been working this week with some classes I've cobbled together for parsing class files directly from disk, but keeping the class data in memory solely for a JIT's use is wasteful. How does this look? public abstract class org.sablevm.vm.Constant { public int size() { return 1; } }; public class org.sablevm.vm.Constant_UTF8 extends org.sablevm.vm.Constant { public String value; }; public class org.sablevm.vm.Constant_Unicode extends org.sablevm.vm.Constant { public char[] value; }; public class org.sablevm.vm.Constant_Integer extends org.sablevm.vm.Constant { public int value; }; public class org.sablevm.vm.Constant_Float extends org.sablevm.vm.Constant { public float value; }; public class org.sablevm.vm.Constant_Long extends org.sablevm.vm.Constant { public long value; public int size() { return 2; } }; public class org.sablevm.vm.Constant_Double extends org.sablevm.vm.Constant { public double value; public int size() { return 2; } }; public class org.sablevm.vm.Constant_String extends org.sablevm.vm.Constant { public String value; }; public class org.sablevm.vm.Constant_Class extends org.sablevm.vm.Constant { public int class_index; }; public class org.sablevm.vm.Constant_Fieldref extends org.sablevm.vm.Constant { public int class_index; public int name_and_type_index; }; public class org.sablevm.vm.Constant_Methodref extends org.sablevm.vm.Constant { public int class_index; public int name_and_type_index; }; public class org.sablevm.vm.Constant_InterfaceMethodref extends org.sablevm.vm.Constant { public int class_index; public int name_and_type_index; }; public class org.sablevm.vm.Constant_NameAndType extends org.sablevm.vm.Constant { public int name_index; public int signature_index; }; public class org.sablevm.vm.Opcode { ... }; public class org.sablevm.vm.Code { public org.sablevm.vm.Class clazz; // class containing this method public int access_flags; public int max_stack; public int max_locals; public int exception_table[][]; public org.sablevm.vm.Opcode code[]; // method opcodes ... } public class org.sablevm.vm.Field { public int access_flags; public String name; public String signature; ... } public class org.sablevm.vm.Class { public org.sablevm.vm.Class superclass; // superclass, if any public int access_flags; public org.sablevm.vm.Field fields[]; // class fields public org.sablevm.vm.Field methods[]; // class/interface methods // constructs a Class object from the internal representation of // class or interface 'name' public native org.sablevm.vm.Class (String name); // retrieve a Constant object for the constant located at index 'i' // for Class 'name' public static native org.sablevm.vm.Constant getConstant (String name, int i); // returns a Code object encapsulating the given method's bytecodes, // exception table, max stack size, and max locals public static native org.sablevm.vm.Code getCode (String class, String name, String signature); // object method version of getConstant() public native org.sablevm.vm.Constant getConstant (int i); // object method version of getCode() public native org.sablevm.vm.Code getCode (String name, String signature); } I've only jotted down read-only methods so far. Eventually there will need to be an org.sablevm.vm.Class method for attaching prepared native code to a given method. Note that these are NOT clases I plan to keep JIT state in during translation. There's an "org.sablevm.vm.jit.*" hierarchy I'm thinking over at the moment. I was thinking the native methods implementing these classes could be added to libsablevm. The associated classes will need to be added to sablepath. Seeing how both are pulled in only if they are part of the transitive closure of referenced classes/functions/etc., they cost nothing if the "use JIT" configure option is not enabled. Andrew Purtell from home -- apu...@ac... |