question about reflection

Per Bothner per@bothner.com
Wed Nov 24 16:11:00 GMT 1999


Godmar Back <gback@cs.utah.edu> writes:

> From looking at class.c:make_class_data, it appears that private methods 
> are omitted from the method table if inlining or optimization is 
> turned on.
> 
> As a result, they won't be available for reflection in such
> functions as Class.getDeclaredMethod(s).
> 
> Is this intended?

There should probably be some flag to control this.  But, yes, it seems
reasonable to me that private methods may disappear if inlining or
optimization is turned on.  After all, we may not have a non-inlined
version of the method, and there seems to be little reason to generate one.

Yes, valid programs can notice the difference through reflection,
so strictly speaking we violate the "as-if rule".  But I can't think
of any real need for keeping the methods around, except debugging or
introspection, in which case optimization may break a number of things.

> ps: I tried to test it myself, but I couldn't get gcj's reflection
> to work at all:  getDeclaredMethod is unimplemented, and getDeclaredMethods
> gives me [a null pointer crash]

Looking at the code (I wrote a good chunk of it, but it was quite
a while ago), it looks like Method.getType needs to be called
by toString().
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/


More information about the Java mailing list