_Jv_LookupInterfaceMethod
Per Bothner
per@bothner.com
Wed Dec 1 11:37:00 GMT 1999
Bryce McKinlay <bryce@albatross.co.nz> writes:
> I have mostly implemented (in the runtime) Per Bothner's constant-time
> dispatch and type checking algorithms, but it really needs this change
> to tie it all together. If someone do it (or give me explicit
> instructions on how ;-), then we'll get a *huge* performance increase on
> interface invocations.
Great. While these are not "explicit instructions", these may be enough
to point you in the right direction.
First, in decl.c do:
Index: decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/decl.c,v
retrieving revision 1.41
diff -u -r1.41 decl.c
--- decl.c 1999/10/26 08:34:46 1.41
+++ decl.c 1999/12/01 18:53:00
@@ -766,7 +766,7 @@
0, NOT_BUILT_IN, NULL_PTR);
t = tree_cons (NULL_TREE, ptr_type_node,
tree_cons (NULL_TREE, ptr_type_node,
- tree_cons (NULL_TREE, ptr_type_node, endlink)));
+ tree_cons (NULL_TREE, int_type_node, endlink)));
soft_lookupinterfacemethod_node
= builtin_function ("_Jv_LookupInterfaceMethod",
build_function_type (ptr_type_node, t),
This changes the "prototype" of _Jv_LookupInterfaceMethod, as
seen by the compiler.
Then you need to change the code that generates the actual call.
This is build_invokeinterface in expr.c. This is where the argument
list is constructed (right-to-left):
lookup_arg = build_tree_list (NULL_TREE,
(build_utf8_ref
(unmangle_classname
(IDENTIFIER_POINTER(method_signature),
IDENTIFIER_LENGTH(method_signature)))));
lookup_arg = tree_cons (NULL_TREE, dtable,
tree_cons (NULL_TREE, build_utf8_ref (method_name),
lookup_arg));
You can replace this by:
lookup_arg = tree_cons (NULL_TREE, dtable,
tree_cons (NULL_TREE, IFACE,
build_tree_list (NULL_TREE, IDX)));
Here IFACE and IDX are tree-nodes that evaluate to the iface and method_idx
parameters. And here is where the next problem comes in: Neither are
available in build_invokeinterface, so you have to change the parameter
list and *its* callers (in expr.c and parse.y). Instead of passing
the method name, I suggest passing the value of `method' (in both
callers). I *think* (i.e. I'm rusty and haven't tried it), then
back in build_invokeinterface you just replace IFACE by DECL_TYPE (method).
Figuring IDX is a litte trickier. Since I don't know your implementation
in depth, I don't know the current value. I'm guessing it's the index
in IFACE of the interface method we a trying to call. I think you
need to loop through TYPE_METHODS (IFACE):
tree meth; int i = 0;
for (meth = TYPE_METHODS (clas); ; meth = TREE_CHAIN (meth), i++)
{
if (meth == method)
{
IDX = build_int_2 (i, 0);
break;
}
if (meth == NULL_TREE)
fatal ("internal error");
}
--
--Per Bothner
per@bothner.com http://www.bothner.com/~per/
More information about the Java
mailing list