[multiple changes]
2004-04-14 Andrew Haley <aph@redhat.com> Bryce McKinlay <mckinlay@redhat.com> * java/lang/reflect/natMethod.cc (_Jv_CallAnyMethodA): Use _Jv_LookupInterfaceMethodIdx for calls to interfaces. * include/jvm.h (_Jv_CallAnyMethodA): Add new face' arg. * testsuite/libjava.lang/InvokeInterface.java: New file. * testsuite/libjava.lang/InvokeInterface.out: New file. 2004-04-14 Bryce McKinlay <mckinlay@redhat.com> * class.c (get_interface_method_index): New function. Return dispatch index for interface method. (make_method_value): For interface methods, set index field to iface dispatch index, not DECL_VINDEX. * expr.c (build_invokeinterface): Use get_interface_method_index. From-SVN: r80684
This commit is contained in:
parent
cd2b7af029
commit
d7afe286b3
10 changed files with 126 additions and 24 deletions
|
@ -1,3 +1,11 @@
|
|||
2004-04-12 Bryce McKinlay <mckinlay@redhat.com>
|
||||
|
||||
* class.c (get_interface_method_index): New function. Return dispatch
|
||||
index for interface method.
|
||||
(make_method_value): For interface methods, set index field to
|
||||
iface dispatch index, not DECL_VINDEX.
|
||||
* expr.c (build_invokeinterface): Use get_interface_method_index.
|
||||
|
||||
2004-03-31 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
|
||||
|
||||
* jcf-write.c (generate_bytecode_insns): Use TYPE_UNSIGNED.
|
||||
|
|
|
@ -1246,10 +1246,15 @@ make_method_value (tree mdecl)
|
|||
tree minit;
|
||||
tree index;
|
||||
tree code;
|
||||
tree class_decl;
|
||||
#define ACC_TRANSLATED 0x4000
|
||||
int accflags = get_access_flags_from_decl (mdecl) | ACC_TRANSLATED;
|
||||
|
||||
if (!flag_indirect_dispatch && DECL_VINDEX (mdecl) != NULL_TREE)
|
||||
|
||||
class_decl = DECL_CONTEXT (mdecl);
|
||||
/* For interfaces, the index field contains the dispatch index. */
|
||||
if (CLASS_INTERFACE (TYPE_NAME (class_decl)))
|
||||
index = build_int_2 (get_interface_method_index (mdecl, class_decl), 0);
|
||||
else if (!flag_indirect_dispatch && DECL_VINDEX (mdecl) != NULL_TREE)
|
||||
index = DECL_VINDEX (mdecl);
|
||||
else
|
||||
index = integer_minus_one_node;
|
||||
|
@ -2133,6 +2138,23 @@ layout_class_methods (tree this_class)
|
|||
TYPE_NVIRTUALS (this_class) = dtable_count;
|
||||
}
|
||||
|
||||
/* Return the index of METHOD in INTERFACE. This index begins at 1 and is used as an
|
||||
argument for _Jv_LookupInterfaceMethodIdx(). */
|
||||
int
|
||||
get_interface_method_index (tree method, tree interface)
|
||||
{
|
||||
tree meth;
|
||||
int i = 1;
|
||||
|
||||
for (meth = TYPE_METHODS (interface); ; meth = TREE_CHAIN (meth), i++)
|
||||
{
|
||||
if (meth == method)
|
||||
return i;
|
||||
if (meth == NULL_TREE)
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
|
||||
/* Lay METHOD_DECL out, returning a possibly new value of
|
||||
DTABLE_COUNT. Also mangle the method's name. */
|
||||
|
||||
|
|
|
@ -1974,17 +1974,7 @@ build_invokeinterface (tree dtable, tree method)
|
|||
}
|
||||
else
|
||||
{
|
||||
i = 1;
|
||||
for (meth = TYPE_METHODS (interface); ; meth = TREE_CHAIN (meth), i++)
|
||||
{
|
||||
if (meth == method)
|
||||
{
|
||||
idx = build_int_2 (i, 0);
|
||||
break;
|
||||
}
|
||||
if (meth == NULL_TREE)
|
||||
abort ();
|
||||
}
|
||||
idx = build_int_2 (get_interface_method_index (method, interface), 0);
|
||||
}
|
||||
|
||||
lookup_arg = tree_cons (NULL_TREE, dtable,
|
||||
|
|
|
@ -1149,6 +1149,7 @@ extern tree unmangle_classname (const char *name, int name_length);
|
|||
extern tree parse_signature_string (const unsigned char *, int);
|
||||
extern tree get_type_from_signature (tree);
|
||||
extern void layout_class (tree);
|
||||
extern int get_interface_method_index (tree, tree);
|
||||
extern tree layout_class_method (tree, tree, tree, tree);
|
||||
extern void layout_class_methods (tree);
|
||||
extern tree build_class_ref (tree);
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
2004-04-14 Andrew Haley <aph@redhat.com>
|
||||
Bryce McKinlay <mckinlay@redhat.com>
|
||||
|
||||
* java/lang/reflect/natMethod.cc (_Jv_CallAnyMethodA): Use
|
||||
_Jv_LookupInterfaceMethodIdx for calls to interfaces.
|
||||
* include/jvm.h (_Jv_CallAnyMethodA): Add new `iface' arg.
|
||||
|
||||
* testsuite/libjava.lang/InvokeInterface.java: New file.
|
||||
* testsuite/libjava.lang/InvokeInterface.out: New file.
|
||||
|
||||
2004-04-09 Ranjit Mathew <rmathew@hotmail.com>
|
||||
|
||||
* java/lang/VMThrowable.java (getStackTrace): Pass trace as-is to
|
||||
|
|
|
@ -422,7 +422,8 @@ extern jboolean _Jv_CheckAccess (jclass self_klass, jclass other_klass,
|
|||
extern jobject _Jv_CallAnyMethodA (jobject obj, jclass return_type,
|
||||
jmethodID meth, jboolean is_constructor,
|
||||
JArray<jclass> *parameter_types,
|
||||
jobjectArray args);
|
||||
jobjectArray args,
|
||||
jclass iface = NULL);
|
||||
|
||||
union jvalue;
|
||||
extern void _Jv_CallAnyMethodA (jobject obj,
|
||||
|
@ -433,7 +434,8 @@ extern void _Jv_CallAnyMethodA (jobject obj,
|
|||
JArray<jclass> *parameter_types,
|
||||
jvalue *args,
|
||||
jvalue *result,
|
||||
jboolean is_jni_call = true);
|
||||
jboolean is_jni_call = true,
|
||||
jclass iface = NULL);
|
||||
|
||||
extern jobject _Jv_NewMultiArray (jclass, jint ndims, jint* dims)
|
||||
__attribute__((__malloc__));
|
||||
|
|
|
@ -143,14 +143,14 @@ jobject
|
|||
java::lang::reflect::Method::invoke (jobject obj, jobjectArray args)
|
||||
{
|
||||
using namespace java::lang::reflect;
|
||||
jclass iface = NULL;
|
||||
|
||||
if (parameter_types == NULL)
|
||||
getType ();
|
||||
|
||||
jmethodID meth = _Jv_FromReflectedMethod (this);
|
||||
|
||||
jclass objClass;
|
||||
|
||||
|
||||
if (Modifier::isStatic(meth->accflags))
|
||||
{
|
||||
// We have to initialize a static class. It is safe to do this
|
||||
|
@ -188,8 +188,11 @@ java::lang::reflect::Method::invoke (jobject obj, jobjectArray args)
|
|||
throw new IllegalAccessException;
|
||||
}
|
||||
|
||||
if (declaringClass->isInterface())
|
||||
iface = declaringClass;
|
||||
|
||||
return _Jv_CallAnyMethodA (obj, return_type, meth, false,
|
||||
parameter_types, args);
|
||||
parameter_types, args, iface);
|
||||
}
|
||||
|
||||
jint
|
||||
|
@ -341,7 +344,8 @@ _Jv_CallAnyMethodA (jobject obj,
|
|||
JArray<jclass> *parameter_types,
|
||||
jvalue *args,
|
||||
jvalue *result,
|
||||
jboolean is_jni_call)
|
||||
jboolean is_jni_call,
|
||||
jclass iface)
|
||||
{
|
||||
using namespace java::lang::reflect;
|
||||
|
||||
|
@ -478,7 +482,10 @@ _Jv_CallAnyMethodA (jobject obj,
|
|||
&& (_Jv_ushort)-1 != meth->index)
|
||||
{
|
||||
_Jv_VTable *vtable = *(_Jv_VTable **) obj;
|
||||
ncode = vtable->get_method (meth->index);
|
||||
if (iface == NULL)
|
||||
ncode = vtable->get_method (meth->index);
|
||||
else
|
||||
ncode = _Jv_LookupInterfaceMethodIdx (vtable->clas, iface, meth->index);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -553,7 +560,8 @@ _Jv_CallAnyMethodA (jobject obj,
|
|||
jmethodID meth,
|
||||
jboolean is_constructor,
|
||||
JArray<jclass> *parameter_types,
|
||||
jobjectArray args)
|
||||
jobjectArray args,
|
||||
jclass iface)
|
||||
{
|
||||
if (parameter_types->length == 0 && args == NULL)
|
||||
{
|
||||
|
@ -621,7 +629,7 @@ _Jv_CallAnyMethodA (jobject obj,
|
|||
_Jv_CallAnyMethodA (obj, return_type, meth, is_constructor,
|
||||
_Jv_isVirtualMethod (meth),
|
||||
parameter_types, argvals, &ret_value,
|
||||
false);
|
||||
false, iface);
|
||||
|
||||
jobject r;
|
||||
#define VAL(Wrapper, Field) (new Wrapper (ret_value.Field))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
|
||||
# Makefile.in generated automatically by automake 1.4 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
|
55
libjava/testsuite/libjava.lang/InvokeInterface.java
Normal file
55
libjava/testsuite/libjava.lang/InvokeInterface.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
import java.lang.reflect.*;
|
||||
|
||||
interface one
|
||||
{
|
||||
int n(int N);
|
||||
}
|
||||
|
||||
interface two
|
||||
{
|
||||
int nn(int N);
|
||||
}
|
||||
|
||||
interface three
|
||||
{
|
||||
int nnn(int N);
|
||||
}
|
||||
|
||||
class arse implements one, two
|
||||
{
|
||||
public int n(int N) { return N; }
|
||||
public int nn(int N) { return N*2; }
|
||||
}
|
||||
|
||||
class arsey implements two, one, three
|
||||
{
|
||||
public int n(int N) { return N*4; }
|
||||
public int nn(int N) { return N*8; }
|
||||
public int nnn(int N) { return N*16; }
|
||||
}
|
||||
|
||||
public class InvokeInterface extends arse
|
||||
{
|
||||
int f ()
|
||||
{
|
||||
return flunk.nn(1);
|
||||
}
|
||||
static two flunk = new arse();
|
||||
static three flunkey = new arsey();
|
||||
public static void main(String[] s) throws Throwable
|
||||
{
|
||||
Class[] argtypes = {Integer.TYPE};
|
||||
Method m = two.class.getMethod("nn", argtypes);
|
||||
Object[] args = {new Integer(1)};
|
||||
System.out.println(flunk.nn(1));
|
||||
System.out.println(m.invoke(new arse(), args));
|
||||
m = arse.class.getMethod("nn", argtypes);
|
||||
System.out.println(m.invoke(new arse(), args));
|
||||
m = two.class.getMethod("nn", argtypes);
|
||||
System.out.println(m.invoke(new arsey(), args));
|
||||
m = three.class.getMethod("nnn", argtypes);
|
||||
System.out.println(m.invoke(new arsey(), args));
|
||||
m = arsey.class.getMethod("nnn", argtypes);
|
||||
System.out.println(m.invoke(new arsey(), args));
|
||||
}
|
||||
}
|
6
libjava/testsuite/libjava.lang/InvokeInterface.out
Normal file
6
libjava/testsuite/libjava.lang/InvokeInterface.out
Normal file
|
@ -0,0 +1,6 @@
|
|||
2
|
||||
2
|
||||
2
|
||||
8
|
||||
16
|
||||
16
|
Loading…
Add table
Reference in a new issue