This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libgcj/11780] New: Method.invoke() is very slow and leaks memory
- From: "bryce at mckinlay dot net dot nz" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 3 Aug 2003 06:39:37 -0000
- Subject: [Bug libgcj/11780] New: Method.invoke() is very slow and leaks memory
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11780
Summary: Method.invoke() is very slow and leaks memory
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: libgcj
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bryce at mckinlay dot net dot nz
CC: gcc-bugs at gcc dot gnu dot org
Good performance from Method.invoke() is very important for many reflective applications.
In previous versions of libgcj security checks were not perfomed, and our performance was only a
little worse than the JRE. A recent patch added security checks and now:
- Method.invoke is now ~10 x slower than the JRE
- Method.invoke leaks memory every time it is called
Clearly there are some simple optimizations that can be made - security check is not needed if
method is public or accessibility flag is true. Ideally however the security check implementation
itself should be made much faster.
Test case w/ timers follows.
import java.lang.reflect.*;
public class RefTest2
{
static int i = 0;
public int increment(int value)
{
return ++i;
}
public static void main(String[] args)
throws Exception
{
Method method = RefTest2.class.getMethod ("increment",
new Class [] { int.class });
Object[] arg = new Object[1];
Object value = new Integer(0);
RefTest2 testObj = new RefTest2();
while (true)
{
long startTime = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++)
{
arg[0] = value;
value = method.invoke(testObj, arg);
}
System.out.println (System.currentTimeMillis() - startTime + " ms");
}
}
}