speed of invokeExact
Jochen Theodorou
blackdrag at gmx.org
Fri May 10 01:57:40 PDT 2013
Am 10.05.2013 02:40, schrieb Christian Thalinger:
[...]
> That's because your method handle is not constant and so the compiler cannot inline the call.
If I change the test to (using 1.8.0):
> Object[] os = {"str", 1, new ArrayList(), new Object()};
> MethodType invokeType = MethodType.methodType(String.class, Object.class);
> MethodHandle[] mhs = new MethodHandle[os.length];
> for (int i=0; i<os.length; i++) {
> MethodHandle mh = MethodHandles.lookup().findVirtual(os[i].getClass(), "toString", MethodType.methodType(String.class));
> mhs[i] = mh.asType(invokeType);
> }
> int tmax = 1_000_000;
> for (int k=0; k<20; k++) {
> long t1 = System.nanoTime();
> for (int i=0; i<tmax; i++) {
> for (int j=0; j<os.length; j++) {
> String s = (String) mhs[j].invokeExact(os[j]);
> }
> }
> long t2 = System.nanoTime();
> System.out.println((t2-t1)/tmax/os.length);
> }
then I doubt there is still any inlining happening. Here I get around 63
(case1). Since I have some probably complex toString action in here I
guess I cannot really compare that number with the test before. But it
is still under those 800. If I pull the asType into the loop (case2)
then I get something of 830-1000. And if I actually remove the
invokeExact and leave only the asType in the loop (case3), I get 730-840
For jdk 1.7.11 I get in
case 1: 70-100
case 2: 380-480
case 3: 300-400
bye Jochen
--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org
More information about the mlvm-dev
mailing list