diff options
author | bryce <bryce@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-10-26 02:25:42 +0000 |
---|---|---|
committer | bryce <bryce@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-10-26 02:25:42 +0000 |
commit | 6aa96c99a6339f2eb2e396d02113be16ddd55129 (patch) | |
tree | 904732224e65247ccdf90cd04bd9cd1ec4f63816 /libjava | |
parent | 9312400311fdf596564631e38e18a786e01dcb59 (diff) | |
download | gcc-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')
-rw-r--r-- | libjava/ChangeLog | 23 | ||||
-rw-r--r-- | libjava/include/jvm.h | 9 | ||||
-rw-r--r-- | libjava/java/lang/natClass.cc | 12 | ||||
-rw-r--r-- | libjava/java/lang/reflect/Constructor.java | 8 | ||||
-rw-r--r-- | libjava/java/lang/reflect/natConstructor.cc | 35 | ||||
-rw-r--r-- | libjava/java/lang/reflect/natMethod.cc | 44 | ||||
-rw-r--r-- | libjava/jni.cc | 16 |
7 files changed, 90 insertions, 57 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index b628831f1e3..54a900b4568 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -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. diff --git a/libjava/include/jvm.h b/libjava/include/jvm.h index b28f61a0e97..e1a5c33bbc6 100644 --- a/libjava/include/jvm.h +++ b/libjava/include/jvm.h @@ -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, diff --git a/libjava/java/lang/natClass.cc b/libjava/java/lang/natClass.cc index 2e1f9da74cb..ffac2c1ff53 100644 --- a/libjava/java/lang/natClass.cc +++ b/libjava/java/lang/natClass.cc @@ -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) 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); diff --git a/libjava/jni.cc b/libjava/jni.cc index 857ee4bc3dd..e2e10defd0a 100644 --- a/libjava/jni.cc +++ b/libjava/jni.cc @@ -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) |