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

@ -1,3 +1,26 @@
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.
2003-10-25 Graydon Hoare <graydon@redhat.com>
* gnu/java/awt/ClasspathToolkit.java: New abstract class.

View File

@ -335,6 +335,14 @@ _Jv_VTable::new_vtable (int count)
return (_Jv_VTable *) _Jv_AllocBytes (size);
}
// Determine if METH gets an entry in a VTable.
static inline jboolean _Jv_isVirtualMethod (_Jv_Method *meth)
{
using namespace java::lang::reflect;
return (((meth->accflags & (Modifier::STATIC | Modifier::PRIVATE)) == 0)
&& meth->name->data[0] != '<');
}
// This function is used to determine the hash code of an object.
inline jint
_Jv_HashCode (jobject obj)
@ -418,6 +426,7 @@ extern void _Jv_CallAnyMethodA (jobject obj,
jclass return_type,
jmethodID meth,
jboolean is_constructor,
jboolean is_virtual_call,
JArray<jclass> *parameter_types,
jvalue *args,
jvalue *result,

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

View File

@ -767,9 +767,6 @@ static T
obj = unwrap (obj);
klass = unwrap (klass);
if (style == normal)
id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
jclass decl_class = klass ? klass : obj->getClass ();
JvAssert (decl_class != NULL);
@ -791,6 +788,7 @@ static T
jvalue result;
_Jv_CallAnyMethodA (obj, return_type, id,
style == constructor,
style == normal,
arg_types, args, &result);
return wrap_value (env, extract_from_jvalue<T>(result));
@ -826,9 +824,6 @@ static T
obj = unwrap (obj);
klass = unwrap (klass);
if (style == normal)
id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
jclass decl_class = klass ? klass : obj->getClass ();
JvAssert (decl_class != NULL);
@ -857,6 +852,7 @@ static T
jvalue result;
_Jv_CallAnyMethodA (obj, return_type, id,
style == constructor,
style == normal,
arg_types, arg_copy, &result);
return wrap_value (env, extract_from_jvalue<T>(result));
@ -877,9 +873,6 @@ static void
obj = unwrap (obj);
klass = unwrap (klass);
if (style == normal)
id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
jclass decl_class = klass ? klass : obj->getClass ();
JvAssert (decl_class != NULL);
@ -899,6 +892,7 @@ static void
_Jv_CallAnyMethodA (obj, return_type, id,
style == constructor,
style == normal,
arg_types, args, NULL);
}
catch (jthrowable t)
@ -924,9 +918,6 @@ static void
(JNICALL _Jv_JNI_CallAnyVoidMethodA) (JNIEnv *env, jobject obj, jclass klass,
jmethodID id, jvalue *args)
{
if (style == normal)
id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
jclass decl_class = klass ? klass : obj->getClass ();
JvAssert (decl_class != NULL);
@ -950,6 +941,7 @@ static void
_Jv_CallAnyMethodA (obj, return_type, id,
style == constructor,
style == normal,
arg_types, args, NULL);
}
catch (jthrowable t)