Constructor.java (toString): Avoid extra whitespace on constructor with no modifiers.

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.

From-SVN: r72942
This commit is contained in:
Bryce McKinlay 2003-10-26 02:25:42 +00:00 committed by Bryce McKinlay
parent 077a148bf5
commit b9b5672b49
7 changed files with 90 additions and 57 deletions

View file

@ -1779,16 +1779,6 @@ _Jv_linkExceptionClassTable (jclass self)
self->catch_classes->classname = (_Jv_Utf8Const *)-1;
}
// Returns true if METH should get an entry in a VTable.
static jboolean
isVirtualMethod (_Jv_Method *meth)
{
using namespace java::lang::reflect;
return (((meth->accflags & (Modifier::STATIC | Modifier::PRIVATE)) == 0)
&& meth->name->data[0] != '<');
}
// This is put in empty vtable slots.
static void
_Jv_abstractMethodError (void)
@ -1842,7 +1832,7 @@ _Jv_LayoutVTableMethods (jclass klass)
_Jv_Method *meth = &klass->methods[i];
_Jv_Method *super_meth = NULL;
if (! isVirtualMethod (meth))
if (! _Jv_isVirtualMethod (meth))
continue;
if (superclass != NULL)

View file

@ -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)

View file

@ -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
{
caller = t->classAt (i);
for (int i = 1; !caller; i++)
{
caller = t->classAt (i);
}
}
}
catch (::java::lang::ArrayIndexOutOfBoundsException *e)
{
catch (::java::lang::ArrayIndexOutOfBoundsException *e)
{
}
if (! _Jv_CheckAccess(caller, declaringClass, meth->accflags))
throw new IllegalAccessException;
}
if (! isAccessible() && ! _Jv_CheckAccess(caller, declaringClass,
declaringClass->getModifiers()))
throw new java::lang::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,

View file

@ -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);