@GenerateMicroBenchmark public long testInvokeDynamic() throws Throwable { Container container = new Container(0,0,(short)0); mhsa.dynamicInvoker().invoke(container, 100L); mhsb.dynamicInvoker().invoke(container, 200); mhsc.dynamicInvoker().invoke(container, (short)300L); return (Long)mhga.dynamicInvoker().invoke(container) + (Integer)mhgb.dynamicInvoker().invoke(container) + (Short)mhgc.dynamicInvoker().invoke(container); }
private void setupInvokeDynamic(Class<?> generatedClass) throws NoSuchMethodException, IllegalAccessException{ MethodHandles.Lookup lookup = MethodHandles.lookup(); MethodType funType = MethodType.methodType(Object.class, Frame.class); MethodType rtType = MethodType.methodType(Object.class, RVMonJVM.class, Frame.class); for (Map.Entry<String, Integer> e : functionMap.entrySet()) { String fname = e.getKey(); Integer findex = e.getValue(); Function func = functionStore[findex]; String methodName = BytecodeGenerator.rvm2jvmName(fname); MethodHandle mh = lookup.findVirtual(generatedClass, methodName, funType); func.handle = new ConstantCallSite(mh.asType(rtType)).dynamicInvoker(); } }
/** * Reduce by functional support for int arrays. * @param array array of items to reduce by * @param object object that contains the reduce by function * @param <T> the type of object * @return the final reduction */ public static <T> long reduceBy( final long[] array, T object ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, object ); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object); MethodHandle methodHandle = callSite.dynamicInvoker(); try { long sum = 0; for ( long v : array ) { sum = (long) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, object); } }
/** * Reduce by functional support for int arrays. * @param array array of items to reduce by * @param object object that contains the reduce by function * @param <T> the type of object * @return the final reduction */ public static <T> double reduceBy( final double[] array, T object, String methodName ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, object, methodName); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object, methodName); MethodHandle methodHandle = callSite.dynamicInvoker(); try { double sum = 0; for ( double v : array ) { sum = (double) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, object, methodName); } }
/** * Reduce by functional support for int arrays. * @param array array of items to reduce by * @param object object that contains the reduce by function * @param <T> the type of object * @return the final reduction */ public static <T> long reduceBy( final long[] array, T object, String methodName ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, object, methodName); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object, methodName); MethodHandle methodHandle = callSite.dynamicInvoker(); try { long sum = 0; for ( long v : array ) { sum = (long) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, object, methodName); } }
/** * Reduce by functional support for int arrays. * @param array array of items to reduce by * @param object object that contains the reduce by function * @param <T> the type of object * @return the final reduction */ public static <T> long reduceBy( final long[] array, T object, String methodName ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, object, methodName); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object, methodName); MethodHandle methodHandle = callSite.dynamicInvoker(); try { long sum = 0; for ( long v : array ) { sum = (long) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, object, methodName); } }
/** * Reduce by functional support for int arrays. * @param array array of items to reduce by * @param object object that contains the reduce by function * @param <T> the type of object * @return the final reduction */ public static <T> double reduceBy( final double[] array, T object ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, object ); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object); MethodHandle methodHandle = callSite.dynamicInvoker(); try { double sum = 0; for ( double v : array ) { sum = (double) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, object); } }
/** * Reduce by functional support for int arrays. * @param array array of items to reduce by * @param object object that contains the reduce by function * @param <T> the type of object * @return the final reduction */ public static <T> double reduceBy( final float[] array, T object ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, object ); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object); MethodHandle methodHandle = callSite.dynamicInvoker(); try { double sum = 0; for ( float v : array ) { sum = (double) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, object); } }
/** * Reduce by functional support for int arrays. * @param array array of items to reduce by * @param object object that contains the reduce by function * @param <T> the type of object * @return the final reduction */ public static <T> long reduceBy( final int[] array, T object ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, object ); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object); MethodHandle methodHandle = callSite.dynamicInvoker(); try { long sum = 0; for ( int v : array ) { sum = (long) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, object); } }
/** * Reduce by functional support for int arrays. * @param array array of items to reduce by * @param object object that contains the reduce by function * @param <T> the type of object * @return the final reduction */ public static <T> double reduceBy( final double[] array, T object, String methodName ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, object, methodName); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object, methodName); MethodHandle methodHandle = callSite.dynamicInvoker(); try { double sum = 0; for ( double v : array ) { sum = (double) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, object, methodName); } }
/** * Reduce by functional support for int arrays. * @param array array of items to reduce by * @param object object that contains the reduce by function * @param <T> the type of object * @return the final reduction */ public static <T> double reduceBy( final float[] array, T object ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, object ); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object); MethodHandle methodHandle = callSite.dynamicInvoker(); try { double sum = 0; for ( float v : array ) { sum = (double) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, object); } }
/** * Reduce By * @param array array of items to reduce by * @param length where to end in the array * @param object function * @return reduction */ public static long reduceBy( final long[] array, int length, Object object ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, length, object ); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object ); MethodHandle methodHandle = callSite.dynamicInvoker(); try { long sum = 0; for (int index=0; index < length; index++) { long v = array[index]; sum = (long) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, length, object ); } }
/** * Reduce By * @param array array of items to reduce by * @param length where to end in the array * @param object function * @return reduction */ public static double reduceBy( final double[] array, int start, int length, Object object ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, object ); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object ); MethodHandle methodHandle = callSite.dynamicInvoker(); try { double sum = 0; for (int index=start; index < length; index++) { double v = array[index]; sum = (double) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, object ); } }
/** * Reduce By * @param array array of items to reduce by * @param length where to end in the array * @param object function * @return reduction */ public static long reduceBy( final int[] array, int start, int length, Object object ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, object ); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object ); MethodHandle methodHandle = callSite.dynamicInvoker(); try { long sum = 0; for (int index=start; index < length; index++) { int v = array[index]; sum = (long) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, object ); } }
/** * Reduce By * @param array array of items to reduce by * @param length where to end in the array * @param object function * @return reduction */ public static double reduceBy( final double[] array, int length, Object object ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, length, object ); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object ); MethodHandle methodHandle = callSite.dynamicInvoker(); try { double sum = 0; for (int index=0; index < length; index++) { double v = array[index]; sum = (double) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, length, object ); } }
/** * Reduce by functional support for int arrays. * @param array array of items to reduce by * @param object object that contains the reduce by function * @param <T> the type of object * @return the final reduction */ public static <T> double reduceBy( final double[] array, T object ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, object ); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object); MethodHandle methodHandle = callSite.dynamicInvoker(); try { double sum = 0; for ( double v : array ) { sum = (double) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, object); } }
/** * Reduce by functional support for int arrays. * @param array array of items to reduce by * @param object object that contains the reduce by function * @param <T> the type of object * @return the final reduction */ public static <T> double reduceBy( final float[] array, T object, String methodName ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, object, methodName); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object, methodName); MethodHandle methodHandle = callSite.dynamicInvoker(); try { double sum = 0; for ( float v : array ) { sum = (double) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, object, methodName); } }
/** * Reduce by functional support for int arrays. * @param array array of items to reduce by * @param object object that contains the reduce by function * @param <T> the type of object * @return the final reduction */ public static <T> long reduceBy( final int[] array, T object ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, object ); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object); MethodHandle methodHandle = callSite.dynamicInvoker(); try { long sum = 0; for ( int v : array ) { sum = (long) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, object); } }
/** * Reduce by functional support for int arrays. * @param array array of items to reduce by * @param object object that contains the reduce by function * @param <T> the type of object * @return the final reduction */ public static <T> long reduceBy( final int[] array, T object, String methodName ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, object, methodName); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object, methodName); MethodHandle methodHandle = callSite.dynamicInvoker(); try { long sum = 0; for ( int v : array ) { sum = (long) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, object, methodName); } }
/** * Reduce by functional support for int arrays. * @param array array of items to reduce by * @param object object that contains the reduce by function * @param <T> the type of object * @return the final reduction */ public static <T> long reduceBy( final long[] array, T object ) { if (object.getClass().isAnonymousClass()) { return reduceByR(array, object ); } try { ConstantCallSite callSite = Invoker.invokeReducerLongIntReturnLongMethodHandle(object); MethodHandle methodHandle = callSite.dynamicInvoker(); try { long sum = 0; for ( long v : array ) { sum = (long) methodHandle.invokeExact( sum, v ); } return sum; } catch (Throwable throwable) { return handle(Long.class, throwable, "Unable to perform reduceBy"); } } catch (Exception ex) { return reduceByR(array, object); } }