--- old/test/java/lang/invoke/LoopCombinatorTest.java 2016-03-02 20:51:58.000000000 +0100 +++ new/test/java/lang/invoke/LoopCombinatorTest.java 2016-03-02 20:51:58.000000000 +0100 @@ -234,6 +234,14 @@ } @Test + public static void testDoWhileNullInit() throws Throwable { + While w = new While(); + MethodHandle loop = MethodHandles.doWhileLoop(null, While.MH_voidBody.bindTo(w), While.MH_voidPred.bindTo(w)); + assertEquals(While.MT_void, loop.type()); + loop.invoke(5); + } + + @Test public static void testWhileZip() throws Throwable { MethodHandle loop = MethodHandles.doWhileLoop(While.MH_zipInitZip, While.MH_zipStep, While.MH_zipPred); assertEquals(While.MT_zip, loop.type()); @@ -244,6 +252,14 @@ } @Test + public static void testWhileNullInit() throws Throwable { + While w = new While(); + MethodHandle loop = MethodHandles.whileLoop(null, While.MH_voidPred.bindTo(w), While.MH_voidBody.bindTo(w)); + assertEquals(While.MT_void, loop.type()); + loop.invoke(5); + } + + @Test public static void testCountedLoop() throws Throwable { // String s = "Lambdaman!"; for (int i = 0; i < 13; ++i) { s = "na " + s; } return s; => a variation on a well known theme MethodHandle fit13 = MethodHandles.constant(int.class, 13); @@ -568,6 +584,16 @@ return zip; } + private int i = 0; + + void voidBody(int k) { + ++i; + } + + boolean voidPred(int k) { + return i < k; + } + static final Class WHILE = While.class; static final MethodType MT_zero = methodType(int.class, int.class); @@ -579,6 +605,8 @@ static final MethodType MT_zipInitZip = methodType(List.class, Iterator.class, Iterator.class); static final MethodType MT_zipPred = methodType(boolean.class, List.class, Iterator.class, Iterator.class); static final MethodType MT_zipStep = methodType(List.class, List.class, Iterator.class, Iterator.class); + static final MethodType MT_voidBody = methodType(void.class, int.class); + static final MethodType MT_voidPred = methodType(boolean.class, int.class); static final MethodHandle MH_zero; static final MethodHandle MH_pred; @@ -589,10 +617,13 @@ static final MethodHandle MH_zipInitZip; static final MethodHandle MH_zipPred; static final MethodHandle MH_zipStep; + static final MethodHandle MH_voidBody; + static final MethodHandle MH_voidPred; static final MethodType MT_while = methodType(int.class, int.class); static final MethodType MT_string = methodType(String.class); static final MethodType MT_zip = methodType(List.class, Iterator.class, Iterator.class); + static final MethodType MT_void = methodType(void.class, int.class); static { try { @@ -605,6 +636,8 @@ MH_zipInitZip = LOOKUP.findStatic(WHILE, "zipInitZip", MT_zipInitZip); MH_zipPred = LOOKUP.findStatic(WHILE, "zipPred", MT_zipPred); MH_zipStep = LOOKUP.findStatic(WHILE, "zipStep", MT_zipStep); + MH_voidBody = LOOKUP.findVirtual(WHILE, "voidBody", MT_voidBody); + MH_voidPred = LOOKUP.findVirtual(WHILE, "voidPred", MT_voidPred); } catch (Exception e) { throw new ExceptionInInitializerError(e); }