summaryrefslogtreecommitdiff
path: root/libjava/java/lang/reflect
diff options
context:
space:
mode:
authorbryce <bryce@138bc75d-0d04-0410-961f-82ee72b054a4>2003-10-26 02:25:42 +0000
committerbryce <bryce@138bc75d-0d04-0410-961f-82ee72b054a4>2003-10-26 02:25:42 +0000
commit6aa96c99a6339f2eb2e396d02113be16ddd55129 (patch)
tree904732224e65247ccdf90cd04bd9cd1ec4f63816 /libjava/java/lang/reflect
parent9312400311fdf596564631e38e18a786e01dcb59 (diff)
downloadgcc-6aa96c99a6339f2eb2e396d02113be16ddd55129.tar.gz
2003-10-26 Bryce McKinlay <bryce@mckinlay.net.nz>
* java/lang/reflect/Constructor.java (toString): Avoid extra whitespace on constructor with no modifiers. * java/lang/reflect/natConstructor.java (newInstance): Look up caller and perform accessibility check only if constructor is non-public and accessible flag is not set. 2003-10-26 Bryce McKinlay <bryce@mckinlay.net.nz> * jni.cc (_Jv_JNI_CallAnyMethodV, _Jv_JNI_CallAnyMethodA, _Jv_JNI_CallAnyVoidMethodV, _Jv_JNI_CallAnyVoidMethodA): Don't use _Jv_LookupDeclaredMethod(). Call _Jv_CallAnyMethodA with is_virtual_call argument. * include/jvm.h (_Jv_isVirtualMethod): Moved and renamed from natClass.cc. * java/lang/natClass.cc (_Jv_LayoutVTableMethods): Use _Jv_isVirtualMethod. * java/lang/reflect/natMethod.cc (invoke): Don't use _Jv_LookupDeclaredMethod. (_Jv_CallAnyMethodA): New is_virtual_call argument. If specified, look up method in target object's vtable. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@72942 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/lang/reflect')
-rw-r--r--libjava/java/lang/reflect/Constructor.java8
-rw-r--r--libjava/java/lang/reflect/natConstructor.cc35
-rw-r--r--libjava/java/lang/reflect/natMethod.cc44
3 files changed, 53 insertions, 34 deletions
diff --git a/libjava/java/lang/reflect/Constructor.java b/libjava/java/lang/reflect/Constructor.java
index 53db35a6975..980ca2a41f2 100644
--- a/libjava/java/lang/reflect/Constructor.java
+++ b/libjava/java/lang/reflect/Constructor.java
@@ -151,8 +151,12 @@ public final class Constructor extends AccessibleObject implements Member
if (parameter_types == null)
getType ();
StringBuffer b = new StringBuffer ();
- Modifier.toString(getModifiers(), b);
- b.append(" ");
+ int mods = getModifiers();
+ if (mods != 0)
+ {
+ Modifier.toString(mods, b);
+ b.append(" ");
+ }
Method.appendClassName (b, declaringClass);
b.append("(");
for (int i = 0; i < parameter_types.length; ++i)
diff --git a/libjava/java/lang/reflect/natConstructor.cc b/libjava/java/lang/reflect/natConstructor.cc
index 466c7544112..3697332d1ef 100644
--- a/libjava/java/lang/reflect/natConstructor.cc
+++ b/libjava/java/lang/reflect/natConstructor.cc
@@ -45,34 +45,39 @@ java::lang::reflect::Constructor::getType ()
jobject
java::lang::reflect::Constructor::newInstance (jobjectArray args)
{
+ using namespace java::lang::reflect;
+
if (parameter_types == NULL)
getType ();
- gnu::gcj::runtime::StackTrace *t
- = new gnu::gcj::runtime::StackTrace(4);
- Class *caller = NULL;
- try
+ jmethodID meth = _Jv_FromReflectedConstructor (this);
+
+ // Check accessibility, if required.
+ if (! (Modifier::isPublic (meth->accflags) || this->isAccessible()))
{
- for (int i = 1; !caller; i++)
+ gnu::gcj::runtime::StackTrace *t
+ = new gnu::gcj::runtime::StackTrace(4);
+ Class *caller = NULL;
+ try
+ {
+ for (int i = 1; !caller; i++)
+ {
+ caller = t->classAt (i);
+ }
+ }
+ catch (::java::lang::ArrayIndexOutOfBoundsException *e)
{
- caller = t->classAt (i);
}
- }
- catch (::java::lang::ArrayIndexOutOfBoundsException *e)
- {
- }
- if (! isAccessible() && ! _Jv_CheckAccess(caller, declaringClass,
- declaringClass->getModifiers()))
- throw new java::lang::IllegalAccessException;
+ if (! _Jv_CheckAccess(caller, declaringClass, meth->accflags))
+ throw new IllegalAccessException;
+ }
- using namespace java::lang::reflect;
if (Modifier::isAbstract (declaringClass->getModifiers()))
throw new InstantiationException;
_Jv_InitClass (declaringClass);
- jmethodID meth = _Jv_FromReflectedConstructor (this);
// In the constructor case the return type is the type of the
// constructor.
return _Jv_CallAnyMethodA (NULL, declaringClass, meth, true,
diff --git a/libjava/java/lang/reflect/natMethod.cc b/libjava/java/lang/reflect/natMethod.cc
index b3413ce6880..525a4a0e9c9 100644
--- a/libjava/java/lang/reflect/natMethod.cc
+++ b/libjava/java/lang/reflect/natMethod.cc
@@ -149,26 +149,22 @@ java::lang::reflect::Method::invoke (jobject obj, jobjectArray args)
jmethodID meth = _Jv_FromReflectedMethod (this);
- jclass klass;
- if (! Modifier::isStatic(meth->accflags))
- {
- if (! obj)
- throw new java::lang::NullPointerException;
- klass = obj->getClass();
- if (! declaringClass->isAssignableFrom(klass))
- throw new java::lang::IllegalArgumentException;
-
- // Find the possibly overloaded method based on the runtime type
- // of the object.
- meth = _Jv_LookupDeclaredMethod (klass, meth->name, meth->signature);
- }
- else
+ jclass objClass;
+
+ if (Modifier::isStatic(meth->accflags))
{
// We have to initialize a static class. It is safe to do this
// here and not in _Jv_CallAnyMethodA because JNI initializes a
// class whenever a method lookup is done.
_Jv_InitClass (declaringClass);
- klass = declaringClass;
+ objClass = declaringClass;
+ }
+ else
+ {
+ objClass = JV_CLASS (obj);
+
+ if (! _Jv_IsAssignableFrom (declaringClass, objClass))
+ throw new java::lang::IllegalArgumentException;
}
// Check accessibility, if required.
@@ -188,7 +184,7 @@ java::lang::reflect::Method::invoke (jobject obj, jobjectArray args)
{
}
- if (! _Jv_CheckAccess(caller, klass, meth->accflags))
+ if (! _Jv_CheckAccess(caller, objClass, meth->accflags))
throw new IllegalAccessException;
}
@@ -341,6 +337,7 @@ _Jv_CallAnyMethodA (jobject obj,
jclass return_type,
jmethodID meth,
jboolean is_constructor,
+ jboolean is_virtual_call,
JArray<jclass> *parameter_types,
jvalue *args,
jvalue *result,
@@ -465,9 +462,21 @@ _Jv_CallAnyMethodA (jobject obj,
break;
}
+ void *ncode;
+
+ if (is_virtual_call)
+ {
+ _Jv_VTable *vtable = *(_Jv_VTable **) obj;
+ ncode = vtable->get_method (meth->index);
+ }
+ else
+ {
+ ncode = meth->ncode;
+ }
+
try
{
- ffi_call (&cif, (void (*)()) meth->ncode, &ffi_result, values);
+ ffi_call (&cif, (void (*)()) ncode, &ffi_result, values);
}
catch (Throwable *ex)
{
@@ -599,6 +608,7 @@ _Jv_CallAnyMethodA (jobject obj,
jvalue ret_value;
_Jv_CallAnyMethodA (obj, return_type, meth, is_constructor,
+ _Jv_isVirtualMethod (meth),
parameter_types, argvals, &ret_value,
false);