kaffe.def for method references

Maxim Kizub max at immsp.kiev.ua
Fri Jan 15 05:06:12 PST 1999


Can someone help me to add kaffe.def entry fro new
opcode? I've already patched kaffe to understand
method references, automatically create classes
and objects, it already passes code_analyze.c and
so on. Now, I need generate code!

Opcode is "op_newmethodref" - creating
method reference.

Method reference is an object of auto-generated
class. It has following bytecode syntax for stack:

op_newmethodref CONSTANT_Method nargs

I.e. for next code (pizza/kiev syntax):

class Test {

public void method(String s, long l, int i) {...}
public void foo() {
	(int)->void mr = this.method("hello",1L);

will be produced bytecode like

op_lcd "hello"
op_newmethodref Test.method(Ljava/lang/String;IJ)V 3

This will store an object of class with signature "&(I)V"
into slot 0. 

The opcode op_newmethodref has 2 arguments - two bytes for constant
pool reference to CONSTANR_Method or CONSTANT_InterfaceMethod,
and one byte for number of arguments (in slots, i.e. long/double
uses 2 slots).

The opcode must create an object with size enough to store
arguments (here "hello" string and 1L long value) and
pointer to... looks like Method structure. And the size
of object itself, i.e.

struct MethodRef {
	Hjava_lang_Object	base;
	Method			*ref;
	int			size;
	// variable-sized array of arguments
	double			align[0];

I think, it shold look like:
- push Method*;
- push size;
- call soft_newmethodref;
- copy arguments into the new object returned by
method soft_newmethodref

Last step may require a method like build_call_frame,
that will has method's signature (to know object's
types), and number of arguments to get from
method's signature (actually, number of slots used
by arguments). I think, I can write this
method myself, but I can't understand how to
code first 3 steps (push Method*, size, call soft_newmethodref).
Please, help me!

PS Other two opcodes, op_addargs for adding arguments to
method reference, and op_invokemethodref to call method
by reference - will have much the same syntax and
semantic in bytecode. I.e., to call method reference
in example above compiler may use:

op_aload_0	// load method ref &(I)V
op_bipush 10	// specify last argument - int 10
op_addargs &(I)V 1 // clone method ref and add new argument
op_astore_1	// store object of class &()V into slot 1
op_aload_1	// load method ref &()V
op_invokemethodref &()V 0 // call it

op_aload_0	// load method ref &(I)V
op_bipush 10	// specify last argument - int 10
op_invokemethodref &(I)V 1 // clone method ref, add new argument, call

So, implementing these opcodes with help of
template of op_newmethodref will be trivial.

  Maxim Kizub

More information about the kaffe mailing list