Commit a10fd356 by Bryce McKinlay Committed by Bryce McKinlay

re PR libgcj/11780 (Method.invoke() is slow)

	PR libgcj/11780:
	* java/lang/reflect/natMethod.cc (invoke): Look up caller and
	perform accessibility check only if target is non-public and
	accessible flag is not set.
	* java/lang/reflect/natField.cc (getAddr): Likewise.

From-SVN: r72918
parent b2398b49
2003-10-25 Bryce McKinlay <bryce@mckinlay.net.nz>
PR libgcj/11780:
* java/lang/reflect/natMethod.cc (invoke): Look up caller and perform
accessibility check only if target is non-public and accessible flag
is not set.
* java/lang/reflect/natField.cc (getAddr): Likewise.
2003-10-24 Thomas Fitzsimmons <fitzsim@redhat.com>
* gnu/java/awt/peer/gtk/GtkDialogPeer.java (handleEvent):
......
......@@ -58,27 +58,32 @@ getAddr (java::lang::reflect::Field* field, jclass caller, jobject obj)
// have the compiler insert the caller as a hidden argument in some
// calls. However, we never implemented that, so we have to find
// the caller by hand instead.
gnu::gcj::runtime::StackTrace *t
= new gnu::gcj::runtime::StackTrace(7);
try
{
// We want to skip all the frames on the stack from this class.
for (int i = 1;
!caller || caller == &java::lang::reflect::Field::class$;
i++)
caller = t->classAt (i);
}
catch (::java::lang::ArrayIndexOutOfBoundsException *e)
{
}
using namespace java::lang::reflect;
jfieldID fld = _Jv_FromReflectedField (field);
_Jv_ushort flags = fld->getModifiers();
if (! field->isAccessible ()
&& ! _Jv_CheckAccess (caller, field->getDeclaringClass(), flags))
throw new java::lang::IllegalAccessException;
// Check accessibility, if required.
if (! (Modifier::isPublic (flags) || field->isAccessible()))
{
gnu::gcj::runtime::StackTrace *t
= new gnu::gcj::runtime::StackTrace(7);
try
{
// We want to skip all the frames on the stack from this class.
for (int i = 1; !caller || caller == &Field::class$; i++)
caller = t->classAt (i);
}
catch (::java::lang::ArrayIndexOutOfBoundsException *e)
{
}
if (! _Jv_CheckAccess (caller, field->getDeclaringClass(), flags))
throw new java::lang::IllegalAccessException;
}
if (flags & java::lang::reflect::Modifier::STATIC)
if (flags & Modifier::STATIC)
{
jclass fldClass = field->getDeclaringClass ();
JvInitClass(fldClass);
......
......@@ -28,6 +28,7 @@ details. */
#include <java/lang/Long.h>
#include <java/lang/Float.h>
#include <java/lang/Double.h>
#include <java/lang/IllegalAccessException.h>
#include <java/lang/IllegalArgumentException.h>
#include <java/lang/NullPointerException.h>
#include <java/lang/ArrayIndexOutOfBoundsException.h>
......@@ -141,26 +142,15 @@ get_ffi_type (jclass klass)
jobject
java::lang::reflect::Method::invoke (jobject obj, 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
{
for (int i = 1; !caller; i++)
{
caller = t->classAt (i);
}
}
catch (::java::lang::ArrayIndexOutOfBoundsException *e)
{
}
jmethodID meth = _Jv_FromReflectedMethod (this);
jclass klass;
if (! java::lang::reflect::Modifier::isStatic(meth->accflags))
if (! Modifier::isStatic(meth->accflags))
{
if (! obj)
throw new java::lang::NullPointerException;
......@@ -181,8 +171,26 @@ java::lang::reflect::Method::invoke (jobject obj, jobjectArray args)
klass = declaringClass;
}
if (! isAccessible() && ! _Jv_CheckAccess(caller, klass, meth->accflags))
throw new IllegalArgumentException;
// Check accessibility, if required.
if (! (Modifier::isPublic (meth->accflags) || this->isAccessible()))
{
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)
{
}
if (! _Jv_CheckAccess(caller, klass, meth->accflags))
throw new IllegalAccessException;
}
return _Jv_CallAnyMethodA (obj, return_type, meth, false,
parameter_types, args);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment