Thread: [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... |
From: Etienne M. G. <eg...@j-...> - 2000-08-11 19:35:18
|
Hi Andrew. I have to give this a careful look. I'll get back tomorrow about it. Anybody else has comments? (I think we should CC John Leuner, which I am doing now). Maybe he'll be interested to being added as a developer, too? (This last question is directed to John;-) Etienne Andrew Purtell wrote: > > 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... > > _______________________________________________ > Sablevm-developer mailing list > Sab...@li... > http://lists.sourceforge.net/mailman/listinfo/sablevm-developer -- ---------------------------------------------------------------------- Etienne M. Gagnon, M.Sc. e-mail: eg...@j-... Author of SableVM: http://www.sablevm.org/ ---------------------------------------------------------------------- |
From: Etienne M. G. <eg...@j-...> - 2000-08-15 11:19:05
|
Andrew Purtell wrote: > > 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. It's like you want... It would be easy to keep the raw code attribute around, if necessary. > How does this look? > public class org.sablevm.vm.Constant_UTF8 > public class org.sablevm.vm.Constant_Unicode I am unsure about these two... Why not keep a single "org.sablevm.vm.Constant_String", as the interpreter has presumably already a native global reference to the string? You can use "java.lang.String" methods to get the length and characters. Unless I missed the point competely?... > public class org.sablevm.vm.Constant_Long > extends org.sablevm.vm.Constant > { > public long value; > public int size() { return 2; } > }; Why the "size"? Don't you assume a long is 64 bits, as per specification? On a 64 bit processor, this would be a single word. We shouldn't make the JIT interface specific to an architecture. > public class org.sablevm.vm.Opcode { ... }; As I said earlier, it would be possible to keep the original code array around, to shield the JIT from SableVM specific internal codes,as much as possible. SableVM encodes the destination of branches using absolute addresses. You certainly don't want to reverse engineer those addresses! > 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. Yes. > The associated classes will need to be added to sablepath. Yes. > 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. True. (Exception of keeping the code array around, but we could "#ifdef" this section of the class loader pretty easily). Etienne -- ---------------------------------------------------------------------- Etienne M. Gagnon, M.Sc. e-mail: eg...@j-... Author of SableVM: http://www.sablevm.org/ ---------------------------------------------------------------------- |