Path: blob/master/test/functional/Jsr292/src/com/ibm/j9/jsr292/FoldArgumentsTest.java
6007 views
/*******************************************************************************1* Copyright (c) 2014, 2019 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/21package com.ibm.j9.jsr292;2223import org.testng.annotations.Test;24import org.testng.AssertJUnit;25import static java.lang.invoke.MethodType.methodType;2627import java.lang.invoke.MethodHandle;28import java.lang.invoke.MethodHandles;29import java.lang.invoke.MethodType;30import java.lang.invoke.WrongMethodTypeException;3132/*33* Tests MethodHandles.foldArguments() with the following FieldTypes for (Parameter/Return Descriptors): Z, B, S, C, I, F, J, D, Ljava/lang/Double;34*35* For each FieldType, MethodHandles.foldArguments() is tested for boundary and intermediate conditions.36*37* Example:38*39* Let FieldType = D40*41* Tests MethodHandles.foldArguments() with the following FoldHandle.next method descriptor:42* (DDDDD)D43*44* Tests MethodHandles.foldArguments() with the following FoldHandle.combiner method descriptor variants:45* ()D46* (D)D47* (DD)D48* (DDD)D49* (DDDD)D50* (DDDD)V51*/52public class FoldArgumentsTest {53private final static byte constByte1 = (byte) -111;54private final static byte constByte2 = (byte) -61;55private final static byte constByte3 = (byte) -83;56private final static byte constByte4 = (byte) 84;57private final static short constShort1 = (short) -12096;58private final static short constShort2 = (short) -21510;59private final static short constShort3 = (short) -1622;60private final static short constShort4 = (short) -19784;61private final static char constCharacter1 = (char) 3763;62private final static char constCharacter2 = (char) 31911;63private final static char constCharacter3 = (char) 58509;64private final static char constCharacter4 = (char) 55609;65private final static int constInteger1 = (int) -491651072;66private final static int constInteger2 = (int) -1993736192;67private final static int constInteger3 = (int) 1213988863;68private final static int constInteger4 = (int) 326893567;69private final static long constLong1 = (long) 1.26663739519795e+018;70private final static long constLong2 = (long) 4.21368040135852e+018;71private final static long constLong3 = (long) 8.94696360972491e+018;72private final static long constLong4 = (long) 1.20527585027503e+018;73private final static float constFloat1 = (float) 2.29572201887512e+038F;74private final static float constFloat2 = (float) 6.12483306976318e+037F;75private final static float constFloat3 = (float) 1.53640056404114e+038F;76private final static float constFloat4 = (float) 6.22037132720947e+036F;77private final static double constDouble1 = (double) 1.10819706189633e+307;78private final static double constDouble2 = (double) 1.78024726032355e+307;79private final static double constDouble3 = (double) 6.78194657384276e+307;80private final static double constDouble4 = (double) 7.33110759312901e+307;81private final static boolean constBoolMax = true;82private final static boolean constBoolMin = false;8384/* Test foldArguments: Combiner's data-type -> byte */85@Test(groups = { "level.extended" })86public void test_foldArguments_Byte() throws WrongMethodTypeException, Throwable {87MethodType nextMT = methodType(byte.class, byte.class, byte.class, byte.class, byte.class, byte.class);88MethodHandle mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "nextByte", nextMT);8990MethodType combinerMT = methodType(byte.class);91MethodHandle mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerByte", combinerMT);9293/* Verify Byte.Max_VALUE Boundary Condition */94MethodHandle foldMH = MethodHandles.foldArguments(mh1, mh2);95AssertJUnit.assertEquals(Byte.MAX_VALUE, (byte) foldMH.invokeExact(constByte1, constByte2, constByte3, constByte4));9697combinerMT = methodType(byte.class, byte.class);98mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerByte", combinerMT);99foldMH = MethodHandles.foldArguments(mh1, mh2);100AssertJUnit.assertEquals(Byte.MAX_VALUE, (byte) foldMH.invokeExact(Byte.MAX_VALUE, constByte2, constByte3, constByte4));101102combinerMT = methodType(byte.class, byte.class, byte.class);103mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerByte", combinerMT);104foldMH = MethodHandles.foldArguments(mh1, mh2);105AssertJUnit.assertEquals(Byte.MAX_VALUE, (byte) foldMH.invokeExact(constByte1, Byte.MAX_VALUE, constByte3, constByte4));106107combinerMT = methodType(byte.class, byte.class, byte.class, byte.class);108mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerByte", combinerMT);109foldMH = MethodHandles.foldArguments(mh1, mh2);110AssertJUnit.assertEquals(Byte.MAX_VALUE, (byte) foldMH.invokeExact(constByte1, constByte2, Byte.MAX_VALUE, constByte4));111112combinerMT = methodType(byte.class, byte.class, byte.class, byte.class, byte.class);113mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerByte", combinerMT);114foldMH = MethodHandles.foldArguments(mh1, mh2);115AssertJUnit.assertEquals(Byte.MAX_VALUE, (byte) foldMH.invokeExact(constByte1, constByte2, constByte3, Byte.MAX_VALUE));116117/* Verify Byte.MIN_VALUE boundary condition */118combinerMT = methodType(byte.class, byte.class);119mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerByte", combinerMT);120foldMH = MethodHandles.foldArguments(mh1, mh2);121AssertJUnit.assertEquals(Byte.MIN_VALUE, (byte) foldMH.invokeExact(Byte.MIN_VALUE, constByte2, constByte3, constByte4));122123combinerMT = methodType(byte.class, byte.class, byte.class);124mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerByte", combinerMT);125foldMH = MethodHandles.foldArguments(mh1, mh2);126AssertJUnit.assertEquals(constByte1, (byte) foldMH.invokeExact(constByte1, Byte.MIN_VALUE, constByte3, constByte4));127128combinerMT = methodType(byte.class, byte.class, byte.class, byte.class);129mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerByte", combinerMT);130foldMH = MethodHandles.foldArguments(mh1, mh2);131AssertJUnit.assertEquals(constByte2, (byte) foldMH.invokeExact(constByte1, constByte2, Byte.MIN_VALUE, constByte4));132133combinerMT = methodType(byte.class, byte.class, byte.class, byte.class, byte.class);134mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerByte", combinerMT);135foldMH = MethodHandles.foldArguments(mh1, mh2);136AssertJUnit.assertEquals(constByte2, (byte) foldMH.invokeExact(constByte1, constByte2, constByte3, Byte.MIN_VALUE));137138/* Verify intermediate condition */139combinerMT = methodType(byte.class, byte.class);140mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerByte", combinerMT);141foldMH = MethodHandles.foldArguments(mh1, mh2);142AssertJUnit.assertEquals(constByte1, (byte) foldMH.invokeExact(constByte1, constByte2, constByte3, constByte4));143144combinerMT = methodType(byte.class, byte.class, byte.class);145mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerByte", combinerMT);146foldMH = MethodHandles.foldArguments(mh1, mh2);147AssertJUnit.assertEquals(constByte2, (byte) foldMH.invokeExact(constByte1, constByte2, constByte3, constByte4));148149combinerMT = methodType(byte.class, byte.class, byte.class, byte.class);150mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerByte", combinerMT);151foldMH = MethodHandles.foldArguments(mh1, mh2);152AssertJUnit.assertEquals(constByte2, (byte) foldMH.invokeExact(constByte1, constByte2, constByte3, constByte4));153154combinerMT = methodType(byte.class, byte.class, byte.class, byte.class, byte.class);155mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerByte", combinerMT);156foldMH = MethodHandles.foldArguments(mh1, mh2);157AssertJUnit.assertEquals(constByte4, (byte) foldMH.invokeExact(constByte1, constByte2, constByte3, constByte4));158159/* void return case */160combinerMT = methodType(void.class, byte.class, byte.class, byte.class, byte.class);161mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerByteVoid", combinerMT);162foldMH = MethodHandles.foldArguments(mh1, mh2);163AssertJUnit.assertEquals(constByte1, (byte) foldMH.invokeExact(constByte1, constByte2, constByte3, constByte4, Byte.MIN_VALUE));164165/* no paramters case */166nextMT = methodType(byte.class);167combinerMT = methodType(void.class);168mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "minByteNoArgs", nextMT);169mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerVoidNoArgs", combinerMT);170foldMH = MethodHandles.foldArguments(mh1, mh2);171AssertJUnit.assertEquals(Byte.MIN_VALUE, (byte) foldMH.invokeExact());172}173174public static byte combinerByte () {175return Byte.MAX_VALUE;176}177178public static byte combinerByte (byte a) {179return largestByte (a);180}181182public static byte combinerByte (byte a, byte b) {183return largestByte (a, b);184}185186public static byte combinerByte (byte a, byte b, byte c) {187return largestByte (a, b, c);188}189190public static byte combinerByte (byte a, byte b, byte c, byte d) {191return largestByte (a, b, c, d);192}193194public static void combinerByteVoid (byte a, byte b, byte c, byte d) {195byte largest = largestByte (a, b, c, d);196}197198public static byte nextByte (byte a, byte b, byte c, byte d, byte e) {199return a;200}201202public static byte largestByte (byte... args) {203byte largest = Byte.MIN_VALUE;204for(byte arg : args) {205if (largest < arg) {206largest = arg;207}208}209return largest;210}211212public static byte minByteNoArgs() {213return Byte.MIN_VALUE;214}215216/* Test foldArguments: Combiner's data-type -> short */217@Test(groups = { "level.extended" })218public void test_foldArguments_Short() throws WrongMethodTypeException, Throwable {219MethodType nextMT = methodType(short.class, short.class, short.class, short.class, short.class, short.class);220MethodHandle mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "nextShort", nextMT);221222MethodType combinerMT = methodType(short.class);223MethodHandle mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerShort", combinerMT);224225/* Verify Short.Max_VALUE Boundary Condition */226MethodHandle foldMH = MethodHandles.foldArguments(mh1, mh2);227AssertJUnit.assertEquals(Short.MAX_VALUE, (short) foldMH.invokeExact(constShort1, constShort2, constShort3, constShort4));228229combinerMT = methodType(short.class, short.class);230mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerShort", combinerMT);231foldMH = MethodHandles.foldArguments(mh1, mh2);232AssertJUnit.assertEquals(Short.MAX_VALUE, (short) foldMH.invokeExact(Short.MAX_VALUE, constShort2, constShort3, constShort4));233234combinerMT = methodType(short.class, short.class, short.class);235mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerShort", combinerMT);236foldMH = MethodHandles.foldArguments(mh1, mh2);237AssertJUnit.assertEquals(Short.MAX_VALUE, (short) foldMH.invokeExact(constShort1, Short.MAX_VALUE, constShort3, constShort4));238239combinerMT = methodType(short.class, short.class, short.class, short.class);240mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerShort", combinerMT);241foldMH = MethodHandles.foldArguments(mh1, mh2);242AssertJUnit.assertEquals(Short.MAX_VALUE, (short) foldMH.invokeExact(constShort1, constShort2, Short.MAX_VALUE, constShort4));243244combinerMT = methodType(short.class, short.class, short.class, short.class, short.class);245mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerShort", combinerMT);246foldMH = MethodHandles.foldArguments(mh1, mh2);247AssertJUnit.assertEquals(Short.MAX_VALUE, (short) foldMH.invokeExact(constShort1, constShort2, constShort3, Short.MAX_VALUE));248249/* Verify Short.MIN_VALUE boundary condition */250combinerMT = methodType(short.class, short.class);251mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerShort", combinerMT);252foldMH = MethodHandles.foldArguments(mh1, mh2);253AssertJUnit.assertEquals(Short.MIN_VALUE, (short) foldMH.invokeExact(Short.MIN_VALUE, constShort2, constShort3, constShort4));254255combinerMT = methodType(short.class, short.class, short.class);256mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerShort", combinerMT);257foldMH = MethodHandles.foldArguments(mh1, mh2);258AssertJUnit.assertEquals(constShort1, (short) foldMH.invokeExact(constShort1, Short.MIN_VALUE, constShort3, constShort4));259260combinerMT = methodType(short.class, short.class, short.class, short.class);261mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerShort", combinerMT);262foldMH = MethodHandles.foldArguments(mh1, mh2);263AssertJUnit.assertEquals(constShort1, (short) foldMH.invokeExact(constShort1, constShort2, Short.MIN_VALUE, constShort4));264265combinerMT = methodType(short.class, short.class, short.class, short.class, short.class);266mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerShort", combinerMT);267foldMH = MethodHandles.foldArguments(mh1, mh2);268AssertJUnit.assertEquals(constShort3, (short) foldMH.invokeExact(constShort1, constShort2, constShort3, Short.MIN_VALUE));269270/* Verify intermediate condition */271combinerMT = methodType(short.class, short.class);272mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerShort", combinerMT);273foldMH = MethodHandles.foldArguments(mh1, mh2);274AssertJUnit.assertEquals(constShort1, (short) foldMH.invokeExact(constShort1, constShort2, constShort3, constShort4));275276combinerMT = methodType(short.class, short.class, short.class);277mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerShort", combinerMT);278foldMH = MethodHandles.foldArguments(mh1, mh2);279AssertJUnit.assertEquals(constShort1, (short) foldMH.invokeExact(constShort1, constShort2, constShort3, constShort4));280281combinerMT = methodType(short.class, short.class, short.class, short.class);282mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerShort", combinerMT);283foldMH = MethodHandles.foldArguments(mh1, mh2);284AssertJUnit.assertEquals(constShort3, (short) foldMH.invokeExact(constShort1, constShort2, constShort3, constShort4));285286combinerMT = methodType(short.class, short.class, short.class, short.class, short.class);287mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerShort", combinerMT);288foldMH = MethodHandles.foldArguments(mh1, mh2);289AssertJUnit.assertEquals(constShort3, (short) foldMH.invokeExact(constShort1, constShort2, constShort3, constShort4));290291/* void return case */292combinerMT = methodType(void.class, short.class, short.class, short.class, short.class);293mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerShortVoid", combinerMT);294foldMH = MethodHandles.foldArguments(mh1, mh2);295AssertJUnit.assertEquals(constShort1, (short) foldMH.invokeExact(constShort1, constShort2, constShort3, constShort4, Short.MIN_VALUE));296297/* no paramters case */298nextMT = methodType(short.class);299combinerMT = methodType(void.class);300mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "minShortNoArgs", nextMT);301mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerVoidNoArgs", combinerMT);302foldMH = MethodHandles.foldArguments(mh1, mh2);303AssertJUnit.assertEquals(Short.MIN_VALUE, (short) foldMH.invokeExact());304}305306public static short combinerShort () {307return Short.MAX_VALUE;308}309310public static short combinerShort (short a) {311return largestShort (a);312}313314public static short combinerShort (short a, short b) {315return largestShort (a, b);316}317318public static short combinerShort (short a, short b, short c) {319return largestShort (a, b, c);320}321322public static short combinerShort (short a, short b, short c, short d) {323return largestShort (a, b, c, d);324}325326public static void combinerShortVoid (short a, short b, short c, short d) {327short largest = largestShort (a, b, c, d);328}329330public static short nextShort (short a, short b, short c, short d, short e) {331return a;332}333334public static short largestShort (short... args) {335short largest = Short.MIN_VALUE;336for(short arg : args) {337if (largest < arg) {338largest = arg;339}340}341return largest;342}343344public static short minShortNoArgs() {345return Short.MIN_VALUE;346}347348/* Test foldArguments: Combiner's data-type -> char */349@Test(groups = { "level.extended" })350public void test_foldArguments_Character() throws WrongMethodTypeException, Throwable {351MethodType nextMT = methodType(char.class, char.class, char.class, char.class, char.class, char.class);352MethodHandle mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "nextCharacter", nextMT);353354MethodType combinerMT = methodType(char.class);355MethodHandle mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerCharacter", combinerMT);356357/* Verify Character.Max_VALUE Boundary Condition */358MethodHandle foldMH = MethodHandles.foldArguments(mh1, mh2);359AssertJUnit.assertEquals(Character.MAX_VALUE, (char) foldMH.invokeExact(constCharacter1, constCharacter2, constCharacter3, constCharacter4));360361combinerMT = methodType(char.class, char.class);362mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerCharacter", combinerMT);363foldMH = MethodHandles.foldArguments(mh1, mh2);364AssertJUnit.assertEquals(Character.MAX_VALUE, (char) foldMH.invokeExact(Character.MAX_VALUE, constCharacter2, constCharacter3, constCharacter4));365366combinerMT = methodType(char.class, char.class, char.class);367mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerCharacter", combinerMT);368foldMH = MethodHandles.foldArguments(mh1, mh2);369AssertJUnit.assertEquals(Character.MAX_VALUE, (char) foldMH.invokeExact(constCharacter1, Character.MAX_VALUE, constCharacter3, constCharacter4));370371combinerMT = methodType(char.class, char.class, char.class, char.class);372mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerCharacter", combinerMT);373foldMH = MethodHandles.foldArguments(mh1, mh2);374AssertJUnit.assertEquals(Character.MAX_VALUE, (char) foldMH.invokeExact(constCharacter1, constCharacter2, Character.MAX_VALUE, constCharacter4));375376combinerMT = methodType(char.class, char.class, char.class, char.class, char.class);377mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerCharacter", combinerMT);378foldMH = MethodHandles.foldArguments(mh1, mh2);379AssertJUnit.assertEquals(Character.MAX_VALUE, (char) foldMH.invokeExact(constCharacter1, constCharacter2, constCharacter3, Character.MAX_VALUE));380381/* Verify Character.MIN_VALUE boundary condition */382combinerMT = methodType(char.class, char.class);383mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerCharacter", combinerMT);384foldMH = MethodHandles.foldArguments(mh1, mh2);385AssertJUnit.assertEquals(Character.MIN_VALUE, (char) foldMH.invokeExact(Character.MIN_VALUE, constCharacter2, constCharacter3, constCharacter4));386387combinerMT = methodType(char.class, char.class, char.class);388mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerCharacter", combinerMT);389foldMH = MethodHandles.foldArguments(mh1, mh2);390AssertJUnit.assertEquals(constCharacter1, (char) foldMH.invokeExact(constCharacter1, Character.MIN_VALUE, constCharacter3, constCharacter4));391392combinerMT = methodType(char.class, char.class, char.class, char.class);393mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerCharacter", combinerMT);394foldMH = MethodHandles.foldArguments(mh1, mh2);395AssertJUnit.assertEquals(constCharacter2, (char) foldMH.invokeExact(constCharacter1, constCharacter2, Character.MIN_VALUE, constCharacter4));396397combinerMT = methodType(char.class, char.class, char.class, char.class, char.class);398mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerCharacter", combinerMT);399foldMH = MethodHandles.foldArguments(mh1, mh2);400AssertJUnit.assertEquals(constCharacter3, (char) foldMH.invokeExact(constCharacter1, constCharacter2, constCharacter3, Character.MIN_VALUE));401402/* Verify intermediate condition */403combinerMT = methodType(char.class, char.class);404mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerCharacter", combinerMT);405foldMH = MethodHandles.foldArguments(mh1, mh2);406AssertJUnit.assertEquals(constCharacter1, (char) foldMH.invokeExact(constCharacter1, constCharacter2, constCharacter3, constCharacter4));407408combinerMT = methodType(char.class, char.class, char.class);409mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerCharacter", combinerMT);410foldMH = MethodHandles.foldArguments(mh1, mh2);411AssertJUnit.assertEquals(constCharacter2, (char) foldMH.invokeExact(constCharacter1, constCharacter2, constCharacter3, constCharacter4));412413combinerMT = methodType(char.class, char.class, char.class, char.class);414mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerCharacter", combinerMT);415foldMH = MethodHandles.foldArguments(mh1, mh2);416AssertJUnit.assertEquals(constCharacter3, (char) foldMH.invokeExact(constCharacter1, constCharacter2, constCharacter3, constCharacter4));417418combinerMT = methodType(char.class, char.class, char.class, char.class, char.class);419mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerCharacter", combinerMT);420foldMH = MethodHandles.foldArguments(mh1, mh2);421AssertJUnit.assertEquals(constCharacter3, (char) foldMH.invokeExact(constCharacter1, constCharacter2, constCharacter3, constCharacter4));422423/* void return case */424combinerMT = methodType(void.class, char.class, char.class, char.class, char.class);425mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerCharacterVoid", combinerMT);426foldMH = MethodHandles.foldArguments(mh1, mh2);427AssertJUnit.assertEquals(constCharacter1, (char) foldMH.invokeExact(constCharacter1, constCharacter2, constCharacter3, constCharacter4, Character.MIN_VALUE));428429/* no paramters case */430nextMT = methodType(char.class);431combinerMT = methodType(void.class);432mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "minCharNoArgs", nextMT);433mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerVoidNoArgs", combinerMT);434foldMH = MethodHandles.foldArguments(mh1, mh2);435AssertJUnit.assertEquals(Character.MIN_VALUE, (char) foldMH.invokeExact());436}437438public static char combinerCharacter () {439return Character.MAX_VALUE;440}441442public static char combinerCharacter (char a) {443return largestCharacter (a);444}445446public static char combinerCharacter (char a, char b) {447return largestCharacter (a, b);448}449450public static char combinerCharacter (char a, char b, char c) {451return largestCharacter (a, b, c);452}453454public static char combinerCharacter (char a, char b, char c, char d) {455return largestCharacter (a, b, c, d);456}457458public static void combinerCharacterVoid (char a, char b, char c, char d) {459char largest = largestCharacter (a, b, c, d);460}461462public static char nextCharacter (char a, char b, char c, char d, char e) {463return a;464}465466public static char largestCharacter (char... args) {467char largest = Character.MIN_VALUE;468for(char arg : args) {469if (largest < arg) {470largest = arg;471}472}473return largest;474}475476public static char minCharNoArgs() {477return Character.MIN_VALUE;478}479480/* Test foldArguments: Combiner's data-type -> int */481@Test(groups = { "level.extended" })482public void test_foldArguments_Integer() throws WrongMethodTypeException, Throwable {483MethodType nextMT = methodType(int.class, int.class, int.class, int.class, int.class, int.class);484MethodHandle mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "nextInteger", nextMT);485486MethodType combinerMT = methodType(int.class);487MethodHandle mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerInteger", combinerMT);488489/* Verify Integer.Max_VALUE Boundary Condition */490MethodHandle foldMH = MethodHandles.foldArguments(mh1, mh2);491AssertJUnit.assertEquals(Integer.MAX_VALUE, (int) foldMH.invokeExact(constInteger1, constInteger2, constInteger3, constInteger4));492493combinerMT = methodType(int.class, int.class);494mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerInteger", combinerMT);495foldMH = MethodHandles.foldArguments(mh1, mh2);496AssertJUnit.assertEquals(Integer.MAX_VALUE, (int) foldMH.invokeExact(Integer.MAX_VALUE, constInteger2, constInteger3, constInteger4));497498combinerMT = methodType(int.class, int.class, int.class);499mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerInteger", combinerMT);500foldMH = MethodHandles.foldArguments(mh1, mh2);501AssertJUnit.assertEquals(Integer.MAX_VALUE, (int) foldMH.invokeExact(constInteger1, Integer.MAX_VALUE, constInteger3, constInteger4));502503combinerMT = methodType(int.class, int.class, int.class, int.class);504mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerInteger", combinerMT);505foldMH = MethodHandles.foldArguments(mh1, mh2);506AssertJUnit.assertEquals(Integer.MAX_VALUE, (int) foldMH.invokeExact(constInteger1, constInteger2, Integer.MAX_VALUE, constInteger4));507508combinerMT = methodType(int.class, int.class, int.class, int.class, int.class);509mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerInteger", combinerMT);510foldMH = MethodHandles.foldArguments(mh1, mh2);511AssertJUnit.assertEquals(Integer.MAX_VALUE, (int) foldMH.invokeExact(constInteger1, constInteger2, constInteger3, Integer.MAX_VALUE));512513/* Verify Integer.MIN_VALUE boundary condition */514combinerMT = methodType(int.class, int.class);515mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerInteger", combinerMT);516foldMH = MethodHandles.foldArguments(mh1, mh2);517AssertJUnit.assertEquals(Integer.MIN_VALUE, (int) foldMH.invokeExact(Integer.MIN_VALUE, constInteger2, constInteger3, constInteger4));518519combinerMT = methodType(int.class, int.class, int.class);520mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerInteger", combinerMT);521foldMH = MethodHandles.foldArguments(mh1, mh2);522AssertJUnit.assertEquals(constInteger1, (int) foldMH.invokeExact(constInteger1, Integer.MIN_VALUE, constInteger3, constInteger4));523524combinerMT = methodType(int.class, int.class, int.class, int.class);525mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerInteger", combinerMT);526foldMH = MethodHandles.foldArguments(mh1, mh2);527AssertJUnit.assertEquals(constInteger1, (int) foldMH.invokeExact(constInteger1, constInteger2, Integer.MIN_VALUE, constInteger4));528529combinerMT = methodType(int.class, int.class, int.class, int.class, int.class);530mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerInteger", combinerMT);531foldMH = MethodHandles.foldArguments(mh1, mh2);532AssertJUnit.assertEquals(constInteger3, (int) foldMH.invokeExact(constInteger1, constInteger2, constInteger3, Integer.MIN_VALUE));533534/* Verify intermediate condition */535combinerMT = methodType(int.class, int.class);536mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerInteger", combinerMT);537foldMH = MethodHandles.foldArguments(mh1, mh2);538AssertJUnit.assertEquals(constInteger1, (int) foldMH.invokeExact(constInteger1, constInteger2, constInteger3, constInteger4));539540combinerMT = methodType(int.class, int.class, int.class);541mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerInteger", combinerMT);542foldMH = MethodHandles.foldArguments(mh1, mh2);543AssertJUnit.assertEquals(constInteger1, (int) foldMH.invokeExact(constInteger1, constInteger2, constInteger3, constInteger4));544545combinerMT = methodType(int.class, int.class, int.class, int.class);546mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerInteger", combinerMT);547foldMH = MethodHandles.foldArguments(mh1, mh2);548AssertJUnit.assertEquals(constInteger3, (int) foldMH.invokeExact(constInteger1, constInteger2, constInteger3, constInteger4));549550combinerMT = methodType(int.class, int.class, int.class, int.class, int.class);551mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerInteger", combinerMT);552foldMH = MethodHandles.foldArguments(mh1, mh2);553AssertJUnit.assertEquals(constInteger3, (int) foldMH.invokeExact(constInteger1, constInteger2, constInteger3, constInteger4));554555/* void return case */556combinerMT = methodType(void.class, int.class, int.class, int.class, int.class);557mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerIntegerVoid", combinerMT);558foldMH = MethodHandles.foldArguments(mh1, mh2);559AssertJUnit.assertEquals(constInteger1, (int) foldMH.invokeExact(constInteger1, constInteger2, constInteger3, constInteger4, Integer.MIN_VALUE));560561/* no paramters case */562nextMT = methodType(int.class);563combinerMT = methodType(void.class);564mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "minIntNoArgs", nextMT);565mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerVoidNoArgs", combinerMT);566foldMH = MethodHandles.foldArguments(mh1, mh2);567AssertJUnit.assertEquals(Integer.MIN_VALUE, (int) foldMH.invokeExact());568}569570public static int combinerInteger () {571return Integer.MAX_VALUE;572}573574public static int combinerInteger (int a) {575return largestInteger (a);576}577578public static int combinerInteger (int a, int b) {579return largestInteger (a, b);580}581582public static int combinerInteger (int a, int b, int c) {583return largestInteger (a, b, c);584}585586public static int combinerInteger (int a, int b, int c, int d) {587return largestInteger (a, b, c, d);588}589590public static void combinerIntegerVoid (int a, int b, int c, int d) {591int largest = largestInteger (a, b, c, d);592}593594public static int nextInteger (int a, int b, int c, int d, int e) {595return a;596}597598public static int largestInteger (int... args) {599int largest = Integer.MIN_VALUE;600for(int arg : args) {601if (largest < arg) {602largest = arg;603}604}605return largest;606}607608public static int minIntNoArgs() {609return Integer.MIN_VALUE;610}611612/* Test foldArguments: Combiner's data-type -> long */613@Test(groups = { "level.extended" })614public void test_foldArguments_Long() throws WrongMethodTypeException, Throwable {615MethodType nextMT = methodType(long.class, long.class, long.class, long.class, long.class, long.class);616MethodHandle mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "nextLong", nextMT);617618MethodType combinerMT = methodType(long.class);619MethodHandle mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerLong", combinerMT);620621/* Verify Long.Max_VALUE Boundary Condition */622MethodHandle foldMH = MethodHandles.foldArguments(mh1, mh2);623AssertJUnit.assertEquals(Long.MAX_VALUE, (long) foldMH.invokeExact(constLong1, constLong2, constLong3, constLong4));624625combinerMT = methodType(long.class, long.class);626mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerLong", combinerMT);627foldMH = MethodHandles.foldArguments(mh1, mh2);628AssertJUnit.assertEquals(Long.MAX_VALUE, (long) foldMH.invokeExact(Long.MAX_VALUE, constLong2, constLong3, constLong4));629630combinerMT = methodType(long.class, long.class, long.class);631mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerLong", combinerMT);632foldMH = MethodHandles.foldArguments(mh1, mh2);633AssertJUnit.assertEquals(Long.MAX_VALUE, (long) foldMH.invokeExact(constLong1, Long.MAX_VALUE, constLong3, constLong4));634635combinerMT = methodType(long.class, long.class, long.class, long.class);636mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerLong", combinerMT);637foldMH = MethodHandles.foldArguments(mh1, mh2);638AssertJUnit.assertEquals(Long.MAX_VALUE, (long) foldMH.invokeExact(constLong1, constLong2, Long.MAX_VALUE, constLong4));639640combinerMT = methodType(long.class, long.class, long.class, long.class, long.class);641mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerLong", combinerMT);642foldMH = MethodHandles.foldArguments(mh1, mh2);643AssertJUnit.assertEquals(Long.MAX_VALUE, (long) foldMH.invokeExact(constLong1, constLong2, constLong3, Long.MAX_VALUE));644645/* Verify Long.MIN_VALUE boundary condition */646combinerMT = methodType(long.class, long.class);647mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerLong", combinerMT);648foldMH = MethodHandles.foldArguments(mh1, mh2);649AssertJUnit.assertEquals(Long.MIN_VALUE, (long) foldMH.invokeExact(Long.MIN_VALUE, constLong2, constLong3, constLong4));650651combinerMT = methodType(long.class, long.class, long.class);652mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerLong", combinerMT);653foldMH = MethodHandles.foldArguments(mh1, mh2);654AssertJUnit.assertEquals(constLong1, (long) foldMH.invokeExact(constLong1, Long.MIN_VALUE, constLong3, constLong4));655656combinerMT = methodType(long.class, long.class, long.class, long.class);657mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerLong", combinerMT);658foldMH = MethodHandles.foldArguments(mh1, mh2);659AssertJUnit.assertEquals(constLong2, (long) foldMH.invokeExact(constLong1, constLong2, Long.MIN_VALUE, constLong4));660661combinerMT = methodType(long.class, long.class, long.class, long.class, long.class);662mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerLong", combinerMT);663foldMH = MethodHandles.foldArguments(mh1, mh2);664AssertJUnit.assertEquals(constLong3, (long) foldMH.invokeExact(constLong1, constLong2, constLong3, Long.MIN_VALUE));665666/* Verify intermediate condition */667combinerMT = methodType(long.class, long.class);668mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerLong", combinerMT);669foldMH = MethodHandles.foldArguments(mh1, mh2);670AssertJUnit.assertEquals(constLong1, (long) foldMH.invokeExact(constLong1, constLong2, constLong3, constLong4));671672combinerMT = methodType(long.class, long.class, long.class);673mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerLong", combinerMT);674foldMH = MethodHandles.foldArguments(mh1, mh2);675AssertJUnit.assertEquals(constLong2, (long) foldMH.invokeExact(constLong1, constLong2, constLong3, constLong4));676677combinerMT = methodType(long.class, long.class, long.class, long.class);678mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerLong", combinerMT);679foldMH = MethodHandles.foldArguments(mh1, mh2);680AssertJUnit.assertEquals(constLong3, (long) foldMH.invokeExact(constLong1, constLong2, constLong3, constLong4));681682combinerMT = methodType(long.class, long.class, long.class, long.class, long.class);683mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerLong", combinerMT);684foldMH = MethodHandles.foldArguments(mh1, mh2);685AssertJUnit.assertEquals(constLong3, (long) foldMH.invokeExact(constLong1, constLong2, constLong3, constLong4));686687/* void return case */688combinerMT = methodType(void.class, long.class, long.class, long.class, long.class);689mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerLongVoid", combinerMT);690foldMH = MethodHandles.foldArguments(mh1, mh2);691AssertJUnit.assertEquals(constLong1, (long) foldMH.invokeExact(constLong1, constLong2, constLong3, constLong4, Long.MIN_VALUE));692693/* no paramters case */694nextMT = methodType(long.class);695combinerMT = methodType(void.class);696mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "minLongNoArgs", nextMT);697mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerVoidNoArgs", combinerMT);698foldMH = MethodHandles.foldArguments(mh1, mh2);699AssertJUnit.assertEquals(Long.MIN_VALUE, (long) foldMH.invokeExact());700}701702public static long combinerLong () {703return Long.MAX_VALUE;704}705706public static long combinerLong (long a) {707return largestLong (a);708}709710public static long combinerLong (long a, long b) {711return largestLong (a, b);712}713714public static long combinerLong (long a, long b, long c) {715return largestLong (a, b, c);716}717718public static long combinerLong (long a, long b, long c, long d) {719return largestLong (a, b, c, d);720}721722public static void combinerLongVoid (long a, long b, long c, long d) {723long largest = largestLong (a, b, c, d);724}725726public static long nextLong (long a, long b, long c, long d, long e) {727return a;728}729730public static long largestLong (long... args) {731long largest = Long.MIN_VALUE;732for(long arg : args) {733if (largest < arg) {734largest = arg;735}736}737return largest;738}739740public static long minLongNoArgs() {741return Long.MIN_VALUE;742}743744/* Test foldArguments: Combiner's data-type -> float */745@Test(groups = { "level.extended" })746public void test_foldArguments_Float() throws WrongMethodTypeException, Throwable {747MethodType nextMT = methodType(float.class, float.class, float.class, float.class, float.class, float.class);748MethodHandle mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "nextFloat", nextMT);749750MethodType combinerMT = methodType(float.class);751MethodHandle mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerFloat", combinerMT);752753/* Verify Float.Max_VALUE Boundary Condition */754MethodHandle foldMH = MethodHandles.foldArguments(mh1, mh2);755AssertJUnit.assertEquals(Float.MAX_VALUE, (float) foldMH.invokeExact(constFloat1, constFloat2, constFloat3, constFloat4));756757combinerMT = methodType(float.class, float.class);758mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerFloat", combinerMT);759foldMH = MethodHandles.foldArguments(mh1, mh2);760AssertJUnit.assertEquals(Float.MAX_VALUE, (float) foldMH.invokeExact(Float.MAX_VALUE, constFloat2, constFloat3, constFloat4));761762combinerMT = methodType(float.class, float.class, float.class);763mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerFloat", combinerMT);764foldMH = MethodHandles.foldArguments(mh1, mh2);765AssertJUnit.assertEquals(Float.MAX_VALUE, (float) foldMH.invokeExact(constFloat1, Float.MAX_VALUE, constFloat3, constFloat4));766767combinerMT = methodType(float.class, float.class, float.class, float.class);768mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerFloat", combinerMT);769foldMH = MethodHandles.foldArguments(mh1, mh2);770AssertJUnit.assertEquals(Float.MAX_VALUE, (float) foldMH.invokeExact(constFloat1, constFloat2, Float.MAX_VALUE, constFloat4));771772combinerMT = methodType(float.class, float.class, float.class, float.class, float.class);773mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerFloat", combinerMT);774foldMH = MethodHandles.foldArguments(mh1, mh2);775AssertJUnit.assertEquals(Float.MAX_VALUE, (float) foldMH.invokeExact(constFloat1, constFloat2, constFloat3, Float.MAX_VALUE));776777/* Verify Float.MIN_VALUE boundary condition */778combinerMT = methodType(float.class, float.class);779mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerFloat", combinerMT);780foldMH = MethodHandles.foldArguments(mh1, mh2);781AssertJUnit.assertEquals(Float.MIN_VALUE, (float) foldMH.invokeExact(Float.MIN_VALUE, constFloat2, constFloat3, constFloat4));782783combinerMT = methodType(float.class, float.class, float.class);784mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerFloat", combinerMT);785foldMH = MethodHandles.foldArguments(mh1, mh2);786AssertJUnit.assertEquals(constFloat1, (float) foldMH.invokeExact(constFloat1, Float.MIN_VALUE, constFloat3, constFloat4));787788combinerMT = methodType(float.class, float.class, float.class, float.class);789mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerFloat", combinerMT);790foldMH = MethodHandles.foldArguments(mh1, mh2);791AssertJUnit.assertEquals(constFloat1, (float) foldMH.invokeExact(constFloat1, constFloat2, Float.MIN_VALUE, constFloat4));792793combinerMT = methodType(float.class, float.class, float.class, float.class, float.class);794mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerFloat", combinerMT);795foldMH = MethodHandles.foldArguments(mh1, mh2);796AssertJUnit.assertEquals(constFloat1, (float) foldMH.invokeExact(constFloat1, constFloat2, constFloat3, Float.MIN_VALUE));797798/* Verify intermediate condition */799combinerMT = methodType(float.class, float.class);800mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerFloat", combinerMT);801foldMH = MethodHandles.foldArguments(mh1, mh2);802AssertJUnit.assertEquals(constFloat1, (float) foldMH.invokeExact(constFloat1, constFloat2, constFloat3, constFloat4));803804combinerMT = methodType(float.class, float.class, float.class);805mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerFloat", combinerMT);806foldMH = MethodHandles.foldArguments(mh1, mh2);807AssertJUnit.assertEquals(constFloat1, (float) foldMH.invokeExact(constFloat1, constFloat2, constFloat3, constFloat4));808809combinerMT = methodType(float.class, float.class, float.class, float.class);810mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerFloat", combinerMT);811foldMH = MethodHandles.foldArguments(mh1, mh2);812AssertJUnit.assertEquals(constFloat1, (float) foldMH.invokeExact(constFloat1, constFloat2, constFloat3, constFloat4));813814combinerMT = methodType(float.class, float.class, float.class, float.class, float.class);815mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerFloat", combinerMT);816foldMH = MethodHandles.foldArguments(mh1, mh2);817AssertJUnit.assertEquals(constFloat1, (float) foldMH.invokeExact(constFloat1, constFloat2, constFloat3, constFloat4));818819/* void return case */820combinerMT = methodType(void.class, float.class, float.class, float.class, float.class);821mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerFloatVoid", combinerMT);822foldMH = MethodHandles.foldArguments(mh1, mh2);823AssertJUnit.assertEquals(constFloat1, (float) foldMH.invokeExact(constFloat1, constFloat2, constFloat3, constFloat4, Float.MIN_VALUE));824825/* no paramters case */826nextMT = methodType(float.class);827combinerMT = methodType(void.class);828mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "minFloatNoArgs", nextMT);829mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerVoidNoArgs", combinerMT);830foldMH = MethodHandles.foldArguments(mh1, mh2);831AssertJUnit.assertEquals(Float.MIN_VALUE, (float) foldMH.invokeExact());832}833834public static float combinerFloat () {835return Float.MAX_VALUE;836}837838public static float combinerFloat (float a) {839return largestFloat (a);840}841842public static float combinerFloat (float a, float b) {843return largestFloat (a, b);844}845846public static float combinerFloat (float a, float b, float c) {847return largestFloat (a, b, c);848}849850public static float combinerFloat (float a, float b, float c, float d) {851return largestFloat (a, b, c, d);852}853854public static void combinerFloatVoid (float a, float b, float c, float d) {855float largest = largestFloat (a, b, c, d);856}857858public static float nextFloat (float a, float b, float c, float d, float e) {859return a;860}861862public static float largestFloat (float... args) {863float largest = Float.MIN_VALUE;864for(float arg : args) {865if (largest < arg) {866largest = arg;867}868}869return largest;870}871872public static float minFloatNoArgs() {873return Float.MIN_VALUE;874}875876/* Test foldArguments: Combiner's data-type -> double */877@Test(groups = { "level.extended" })878public void test_foldArguments_Double() throws WrongMethodTypeException, Throwable {879MethodType nextMT = methodType(double.class, double.class, double.class, double.class, double.class, double.class);880MethodHandle mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "nextDouble", nextMT);881882MethodType combinerMT = methodType(double.class);883MethodHandle mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDouble", combinerMT);884885/* Verify Double.Max_VALUE Boundary Condition */886MethodHandle foldMH = MethodHandles.foldArguments(mh1, mh2);887AssertJUnit.assertEquals(Double.MAX_VALUE, (double) foldMH.invokeExact(constDouble1, constDouble2, constDouble3, constDouble4));888889combinerMT = methodType(double.class, double.class);890mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDouble", combinerMT);891foldMH = MethodHandles.foldArguments(mh1, mh2);892AssertJUnit.assertEquals(Double.MAX_VALUE, (double) foldMH.invokeExact(Double.MAX_VALUE, constDouble2, constDouble3, constDouble4));893894combinerMT = methodType(double.class, double.class, double.class);895mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDouble", combinerMT);896foldMH = MethodHandles.foldArguments(mh1, mh2);897AssertJUnit.assertEquals(Double.MAX_VALUE, (double) foldMH.invokeExact(constDouble1, Double.MAX_VALUE, constDouble3, constDouble4));898899combinerMT = methodType(double.class, double.class, double.class, double.class);900mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDouble", combinerMT);901foldMH = MethodHandles.foldArguments(mh1, mh2);902AssertJUnit.assertEquals(Double.MAX_VALUE, (double) foldMH.invokeExact(constDouble1, constDouble2, Double.MAX_VALUE, constDouble4));903904combinerMT = methodType(double.class, double.class, double.class, double.class, double.class);905mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDouble", combinerMT);906foldMH = MethodHandles.foldArguments(mh1, mh2);907AssertJUnit.assertEquals(Double.MAX_VALUE, (double) foldMH.invokeExact(constDouble1, constDouble2, constDouble3, Double.MAX_VALUE));908909/* Verify Double.MIN_VALUE boundary condition */910combinerMT = methodType(double.class, double.class);911mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDouble", combinerMT);912foldMH = MethodHandles.foldArguments(mh1, mh2);913AssertJUnit.assertEquals(Double.MIN_VALUE, (double) foldMH.invokeExact(Double.MIN_VALUE, constDouble2, constDouble3, constDouble4));914915combinerMT = methodType(double.class, double.class, double.class);916mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDouble", combinerMT);917foldMH = MethodHandles.foldArguments(mh1, mh2);918AssertJUnit.assertEquals(constDouble1, (double) foldMH.invokeExact(constDouble1, Double.MIN_VALUE, constDouble3, constDouble4));919920combinerMT = methodType(double.class, double.class, double.class, double.class);921mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDouble", combinerMT);922foldMH = MethodHandles.foldArguments(mh1, mh2);923AssertJUnit.assertEquals(constDouble2, (double) foldMH.invokeExact(constDouble1, constDouble2, Double.MIN_VALUE, constDouble4));924925combinerMT = methodType(double.class, double.class, double.class, double.class, double.class);926mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDouble", combinerMT);927foldMH = MethodHandles.foldArguments(mh1, mh2);928AssertJUnit.assertEquals(constDouble3, (double) foldMH.invokeExact(constDouble1, constDouble2, constDouble3, Double.MIN_VALUE));929930/* Verify intermediate condition */931combinerMT = methodType(double.class, double.class);932mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDouble", combinerMT);933foldMH = MethodHandles.foldArguments(mh1, mh2);934AssertJUnit.assertEquals(constDouble1, (double) foldMH.invokeExact(constDouble1, constDouble2, constDouble3, constDouble4));935936combinerMT = methodType(double.class, double.class, double.class);937mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDouble", combinerMT);938foldMH = MethodHandles.foldArguments(mh1, mh2);939AssertJUnit.assertEquals(constDouble2, (double) foldMH.invokeExact(constDouble1, constDouble2, constDouble3, constDouble4));940941combinerMT = methodType(double.class, double.class, double.class, double.class);942mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDouble", combinerMT);943foldMH = MethodHandles.foldArguments(mh1, mh2);944AssertJUnit.assertEquals(constDouble3, (double) foldMH.invokeExact(constDouble1, constDouble2, constDouble3, constDouble4));945946combinerMT = methodType(double.class, double.class, double.class, double.class, double.class);947mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDouble", combinerMT);948foldMH = MethodHandles.foldArguments(mh1, mh2);949AssertJUnit.assertEquals(constDouble4, (double) foldMH.invokeExact(constDouble1, constDouble2, constDouble3, constDouble4));950951/* void return case */952combinerMT = methodType(void.class, double.class, double.class, double.class, double.class);953mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDoubleVoid", combinerMT);954foldMH = MethodHandles.foldArguments(mh1, mh2);955AssertJUnit.assertEquals(constDouble1, (double) foldMH.invokeExact(constDouble1, constDouble2, constDouble3, constDouble4, Double.MIN_VALUE));956957/* no paramters case */958nextMT = methodType(double.class);959combinerMT = methodType(void.class);960mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "minDoubleNoArgs", nextMT);961mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerVoidNoArgs", combinerMT);962foldMH = MethodHandles.foldArguments(mh1, mh2);963AssertJUnit.assertEquals(Double.MIN_VALUE, (double) foldMH.invokeExact());964}965966public static double combinerDouble () {967return Double.MAX_VALUE;968}969970public static double combinerDouble (double a) {971return largestDouble (a);972}973974public static double combinerDouble (double a, double b) {975return largestDouble (a, b);976}977978public static double combinerDouble (double a, double b, double c) {979return largestDouble (a, b, c);980}981982public static double combinerDouble (double a, double b, double c, double d) {983return largestDouble (a, b, c, d);984}985986public static void combinerDoubleVoid (double a, double b, double c, double d) {987double largest = largestDouble (a, b, c, d);988}989990public static double nextDouble (double a, double b, double c, double d, double e) {991return a;992}993994public static double largestDouble (double... args) {995double largest = Double.MIN_VALUE;996for(double arg : args) {997if (largest < arg) {998largest = arg;999}1000}1001return largest;1002}10031004public static double minDoubleNoArgs() {1005return Double.MIN_VALUE;1006}10071008/* Test foldArguments: Combiner's data-type -> Double (Object) */1009@Test(groups = { "level.extended" })1010public void test_foldArguments_DoubleObject() throws WrongMethodTypeException, Throwable {1011MethodType nextMT = methodType(Double.class, Double.class, Double.class, Double.class, Double.class, Double.class);1012MethodHandle mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "nextDoubleObject", nextMT);10131014MethodType combinerMT = methodType(Double.class);1015MethodHandle mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDoubleObject", combinerMT);10161017Double d1 = new Double (constDouble1);1018Double d2 = new Double (constDouble2);1019Double d3 = new Double (constDouble3);1020Double d4 = new Double (constDouble4);1021Double dMax = new Double (Double.MAX_VALUE);1022Double dMin = new Double (Double.MIN_VALUE);10231024/* Verify Double.Max_VALUE Boundary Condition */1025MethodHandle foldMH = MethodHandles.foldArguments(mh1, mh2);1026AssertJUnit.assertEquals(dMax, (Double) foldMH.invokeExact(d1, d2, d3, d4));10271028combinerMT = methodType(Double.class, Double.class);1029mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDoubleObject", combinerMT);1030foldMH = MethodHandles.foldArguments(mh1, mh2);1031AssertJUnit.assertEquals(dMax, (Double) foldMH.invokeExact(dMax, d2, d3, d4));10321033combinerMT = methodType(Double.class, Double.class, Double.class);1034mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDoubleObject", combinerMT);1035foldMH = MethodHandles.foldArguments(mh1, mh2);1036AssertJUnit.assertEquals(dMax, (Double) foldMH.invokeExact(d1, dMax, d3, d4));10371038combinerMT = methodType(Double.class, Double.class, Double.class, Double.class);1039mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDoubleObject", combinerMT);1040foldMH = MethodHandles.foldArguments(mh1, mh2);1041AssertJUnit.assertEquals(dMax, (Double) foldMH.invokeExact(d1, d2, dMax, d4));10421043combinerMT = methodType(Double.class, Double.class, Double.class, Double.class, Double.class);1044mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDoubleObject", combinerMT);1045foldMH = MethodHandles.foldArguments(mh1, mh2);1046AssertJUnit.assertEquals(dMax, (Double) foldMH.invokeExact(d1, d2, d3, dMax));10471048/* Verify dMin boundary condition */1049combinerMT = methodType(Double.class, Double.class);1050mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDoubleObject", combinerMT);1051foldMH = MethodHandles.foldArguments(mh1, mh2);1052AssertJUnit.assertEquals(dMin, (Double) foldMH.invokeExact(dMin, d2, d3, d4));10531054combinerMT = methodType(Double.class, Double.class, Double.class);1055mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDoubleObject", combinerMT);1056foldMH = MethodHandles.foldArguments(mh1, mh2);1057AssertJUnit.assertEquals(d1, (Double) foldMH.invokeExact(d1, dMin, d3, d4));10581059combinerMT = methodType(Double.class, Double.class, Double.class, Double.class);1060mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDoubleObject", combinerMT);1061foldMH = MethodHandles.foldArguments(mh1, mh2);1062AssertJUnit.assertEquals(d2, (Double) foldMH.invokeExact(d1, d2, dMin, d4));10631064combinerMT = methodType(Double.class, Double.class, Double.class, Double.class, Double.class);1065mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDoubleObject", combinerMT);1066foldMH = MethodHandles.foldArguments(mh1, mh2);1067AssertJUnit.assertEquals(d3, (Double) foldMH.invokeExact(d1, d2, d3, dMin));10681069/* Verify intermediate condition */1070combinerMT = methodType(Double.class, Double.class);1071mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDoubleObject", combinerMT);1072foldMH = MethodHandles.foldArguments(mh1, mh2);1073AssertJUnit.assertEquals(d1, (Double) foldMH.invokeExact(d1, d2, d3, d4));10741075combinerMT = methodType(Double.class, Double.class, Double.class);1076mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDoubleObject", combinerMT);1077foldMH = MethodHandles.foldArguments(mh1, mh2);1078AssertJUnit.assertEquals(d2, (Double) foldMH.invokeExact(d1, d2, d3, d4));10791080combinerMT = methodType(Double.class, Double.class, Double.class, Double.class);1081mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDoubleObject", combinerMT);1082foldMH = MethodHandles.foldArguments(mh1, mh2);1083AssertJUnit.assertEquals(d3, (Double) foldMH.invokeExact(d1, d2, d3, d4));10841085combinerMT = methodType(Double.class, Double.class, Double.class, Double.class, Double.class);1086mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDoubleObject", combinerMT);1087foldMH = MethodHandles.foldArguments(mh1, mh2);1088AssertJUnit.assertEquals(d4, (Double) foldMH.invokeExact(d1, d2, d3, d4));10891090/* void return case */1091combinerMT = methodType(void.class, Double.class, Double.class, Double.class, Double.class);1092mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerDoubleObjectVoid", combinerMT);1093foldMH = MethodHandles.foldArguments(mh1, mh2);1094AssertJUnit.assertEquals(d1, (Double) foldMH.invokeExact(d1, d2, d3, d4, dMin));10951096/* no paramters case */1097nextMT = methodType(Double.class);1098combinerMT = methodType(void.class);1099mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "minDoubleObjNoArgs", nextMT);1100mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerVoidNoArgs", combinerMT);1101foldMH = MethodHandles.foldArguments(mh1, mh2);1102AssertJUnit.assertEquals(dMin, (Double) foldMH.invokeExact());1103}11041105public static Double combinerDoubleObject () {1106Double ret = new Double (Double.MAX_VALUE);1107return ret;1108}11091110public static Double combinerDoubleObject (Double a) {1111return largestDoubleObject (a);1112}11131114public static Double combinerDoubleObject (Double a, Double b) {1115return largestDoubleObject (a, b);1116}11171118public static Double combinerDoubleObject (Double a, Double b, Double c) {1119return largestDoubleObject (a, b, c);1120}11211122public static Double combinerDoubleObject (Double a, Double b, Double c, Double d) {1123return largestDoubleObject (a, b, c, d);1124}11251126public static void combinerDoubleObjectVoid (Double a, Double b, Double c, Double d) {1127Double largest = largestDoubleObject (a, b, c, d);1128}11291130public static Double nextDoubleObject (Double a, Double b, Double c, Double d, Double e) {1131return a;1132}11331134public static Double largestDoubleObject (Double... args) {1135Double largest = Double.MIN_VALUE;1136for(Double arg : args) {1137if (largest.doubleValue() < arg.doubleValue()) {1138largest = arg;1139}1140}1141return largest;1142}11431144public static Double minDoubleObjNoArgs() {1145Double ret = new Double (Double.MIN_VALUE);1146return ret;1147}11481149/* Test foldArguments: Combiner's data-type -> boolean */1150@Test(groups = { "level.extended" })1151public void test_foldArguments_Boolean() throws WrongMethodTypeException, Throwable {1152MethodType nextMT = methodType(boolean.class, boolean.class, boolean.class, boolean.class);1153MethodHandle mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "nextBoolean", nextMT);11541155MethodType combinerMT = methodType(boolean.class);1156MethodHandle mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerBoolean", combinerMT);11571158MethodHandle foldMH = MethodHandles.foldArguments(mh1, mh2);1159AssertJUnit.assertEquals(constBoolMax, (boolean) foldMH.invokeExact(constBoolMax, constBoolMin));11601161combinerMT = methodType(boolean.class, boolean.class);1162mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerBoolean", combinerMT);1163foldMH = MethodHandles.foldArguments(mh1, mh2);1164AssertJUnit.assertEquals(constBoolMax, (boolean) foldMH.invokeExact(constBoolMax, constBoolMin));11651166combinerMT = methodType(boolean.class, boolean.class, boolean.class);1167mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerBoolean", combinerMT);1168foldMH = MethodHandles.foldArguments(mh1, mh2);1169AssertJUnit.assertEquals(constBoolMin, (boolean) foldMH.invokeExact(constBoolMax, constBoolMin));11701171/* void return case */1172combinerMT = methodType(void.class, boolean.class, boolean.class);1173mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerBooleanVoid", combinerMT);1174foldMH = MethodHandles.foldArguments(mh1, mh2);1175AssertJUnit.assertEquals(constBoolMin, (boolean) foldMH.invokeExact(constBoolMin, constBoolMax, constBoolMin));11761177/* no paramters case */1178nextMT = methodType(boolean.class);1179combinerMT = methodType(void.class);1180mh1 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "minBooleanNoArgs", nextMT);1181mh2 = MethodHandles.publicLookup().findStatic(FoldArgumentsTest.class, "combinerVoidNoArgs", combinerMT);1182foldMH = MethodHandles.foldArguments(mh1, mh2);1183AssertJUnit.assertEquals(constBoolMin, (boolean) foldMH.invokeExact());1184}11851186public static boolean combinerBoolean () {1187return constBoolMax;1188}11891190public static boolean combinerBoolean (boolean a) {1191return lastBoolean (a);1192}11931194public static boolean combinerBoolean (boolean a, boolean b) {1195return lastBoolean (a, b);1196}11971198public static void combinerBooleanVoid (boolean a, boolean b) {1199boolean last = lastBoolean (a, b);1200}12011202public static boolean nextBoolean (boolean a, boolean b, boolean c) {1203return a;1204}12051206public static boolean lastBoolean (boolean... args) {1207boolean last = constBoolMin;1208for(boolean arg: args) {1209last = arg;1210}1211return last;1212}12131214public static boolean minBooleanNoArgs() {1215return constBoolMin;1216}12171218/* if target MH takes no args, then return type of combiner needs to be void */1219public static void combinerVoidNoArgs() {}1220}122112221223