test/lib/testlibrary/jsr292/com/oracle/testlibrary/jsr292/Helper.java

Print this page
rev 10362 : 8057707: TEST library enhancement: copy sun.hotspot.whitebox classes from hotspot repo and enhance lib/testlibrary/jsr292/com/oracle/testlibrary/jsr292/Helper.java
Reviewed-by: iignatyev

*** 50,60 **** } public static final long TEST_LIMIT; static { String str = System.getProperty("testLimit"); ! TEST_LIMIT = str != null ? Long.parseUnsignedLong(str) : 2_000L; System.out.printf("-DtestLimit=%d%n", TEST_LIMIT); } public static final int MAX_ARITY = 254; public static final String MISSING_ARG = "missingArg"; --- 50,60 ---- } public static final long TEST_LIMIT; static { String str = System.getProperty("testLimit"); ! TEST_LIMIT = str != null ? Long.parseUnsignedLong(str) : 2000L; System.out.printf("-DtestLimit=%d%n", TEST_LIMIT); } public static final int MAX_ARITY = 254; public static final String MISSING_ARG = "missingArg";
*** 114,123 **** --- 114,165 ---- public static List<Object> getCalled(int lag) { int size = calledLog.size(); return size <= lag ? null : calledLog.get(size - lag - 1); } + public static List<Class<?>> randomClasses(Class<?>[] classes, int size) { + List<Class<?>> result = new ArrayList<>(size); + for (int i = 0; i < size; ++i) { + result.add(classes[RNG.nextInt(classes.length)]); + } + return result; + } + + public static List<Class<?>> getParams(List<Class<?>> classes, + boolean isVararg, int argsCount) { + boolean unmodifiable = true; + List<Class<?>> result = classes.subList(0, + Math.min(argsCount, (MAX_ARITY / 2) - 1)); + int extra = 0; + if (argsCount >= MAX_ARITY / 2) { + result = new ArrayList<>(result); + unmodifiable = false; + extra = (int) result.stream().filter(Helper::isDoubleCost).count(); + int i = result.size(); + while (result.size() + extra < argsCount) { + Class<?> aClass = classes.get(i); + if (Helper.isDoubleCost(aClass)) { + ++extra; + if (result.size() + extra >= argsCount) { + break; + } + } + result.add(aClass); + } + } + if (isVararg && result.size() > 0) { + if (unmodifiable) { + result = new ArrayList<>(result); + } + int last = result.size() - 1; + Class<?> aClass = result.get(last); + aClass = Array.newInstance(aClass, 2).getClass(); + result.set(last, aClass); + } + return result; + } + public static MethodHandle addTrailingArgs(MethodHandle target, int nargs, List<Class<?>> classes) { int targetLen = target.type().parameterCount(); int extra = (nargs - targetLen); if (extra <= 0) {
*** 228,238 **** public static Object[] randomArgs(List<Class<?>> params) { return randomArgs(params.toArray(new Class<?>[params.size()])); } ! private static Object castToWrapper(Object value, Class<?> dst) { Object wrap = null; if (value instanceof Number) { wrap = castToWrapperOrNull(((Number) value).longValue(), dst); } if (value instanceof Character) { --- 270,280 ---- public static Object[] randomArgs(List<Class<?>> params) { return randomArgs(params.toArray(new Class<?>[params.size()])); } ! public static Object castToWrapper(Object value, Class<?> dst) { Object wrap = null; if (value instanceof Number) { wrap = castToWrapperOrNull(((Number) value).longValue(), dst); } if (value instanceof Character) {
*** 266,276 **** return (double) (value); } if (dst == byte.class || dst == Byte.class) { return (byte) (value); } ! if (dst == boolean.class || dst == boolean.class) { return ((value % 29) & 1) == 0; } return null; } } --- 308,318 ---- return (double) (value); } if (dst == byte.class || dst == Byte.class) { return (byte) (value); } ! if (dst == boolean.class || dst == Boolean.class) { return ((value % 29) & 1) == 0; } return null; } }