Loading arguments for first-order functions calls

Maxim Kizub max at immsp.kiev.ua
Tue Jan 19 02:12:31 PST 1999


I have a question about better implementation of
first-order function calls.

In pizza/kiev we have

class A {
	void foo(int i1, int i2, int i3) {...}
	void foo(int i2, int i3) {...}
	void foo(int i3) {...}
	(int)->void fof = foo(1,2);
// or	(int)->void fof = foo(2);
// or	(int)->void fof = foo();

So, we can't at compiler time (and at jitting time)
predict number of arguments that 'fof' may require.
So, when adding opcode for first-order function
call, this opcode must insert unpredicted number
of arguments into stack.

Q1: Will it break some security check? I mean, java
require, that exact stack depth was known for method.
Does kaffe relay on this fact?

Q2: Java uses pascal call convention (first argument
is deeper in stack). Does kaffe uses C or pascal
call convention? Or it mixes it to have C-call conventions
for soft methods and pascal for java methods?

Q3: If kaffe uses pascal call convention for jitted
java methods, what is optimal way to _insert_
arguments? I mean - call for 'foo' in example above
will looks like:

int i;

That may be reflected in bytecode as:

op_aload_F	// load method ref for 'fof'
op_iload_I	// load value of 'i'
op_invokemethodref &(I)V  // invoke 'fof'

Since we do not know actual number of pre-specified
arguments of 'fof' first-order function,
we need the kaffe to insert some arguments
(for pascal call convention). I.e., if
'fof' was initialized as 'fof = foo(1,2)'
we need indert 2 integers and 'this' befor
value of 'i', so, call stack will be identical to:


What is the best way to do this?
One way is to allow invoke only those method
references, that do not have arguments,
i.e., fill all arguments of first-order function,
and invoke it. Like:

op_aload_F	// load method ref for 'fof'
op_iload_I	// load value of 'i'
op_addargs &(I)V 1  // clone 'fof' with adding 1 arg
		// this will leave &()V object in stack
op_invokemethodref &()V  // invoke

But this is not a good solution, since it requires
creation (cloning) of method reference, copying args
to memory and reading args from memory.
This approach may be selected, if kaffe relay on
bytecode specified method stack depth,
but if kaffe has no this limitation - it's better
to insert arguments. What is the best (optimal)
kaffe instruction (macro) to insert values
in stack (if any), or how it can be done in kaffe
in optimal way (if there is no such macro)?

  Maxim Kizub

More information about the kaffe mailing list