public static void unmap(String resourceDescription, MappedByteBuffer buffer) throws IOException { if (!buffer.isDirect()) throw new IllegalArgumentException("Unmapping only works with direct buffers"); if (UNMAP == null) throw UNMAP_NOT_SUPPORTED_EXCEPTION; try { UNMAP.invokeExact((ByteBuffer) buffer); } catch (Throwable throwable) { throw new IOException("Unable to unmap the mapped buffer: " + resourceDescription, throwable); } }
private Object positionLock( FileChannel channel ) { sun.nio.ch.FileChannelImpl impl = (FileChannelImpl) channel; try { return (Object) positionLockGetter.invokeExact( impl ); } catch ( Throwable th ) { throw new LinkageError( "No getter for FileChannel.positionLock", th ); } }
/** * Parse a string (optionally containing a zone) as a value of TIMESTAMP type. * If the string specifies a zone, the zone is discarded. * <p> * For example: {@code "2000-01-01 01:23:00"} is parsed to TIMESTAMP {@code 2000-01-01T01:23:00} * and {@code "2000-01-01 01:23:00 +01:23"} is also parsed to TIMESTAMP {@code 2000-01-01T01:23:00.000}. * * @return stack representation of TIMESTAMP type */ public static long parseTimestampWithoutTimeZone(String value) { LocalDateTime localDateTime = TIMESTAMP_WITH_OR_WITHOUT_TIME_ZONE_FORMATTER.parseLocalDateTime(value); try { return (long) getLocalMillis.invokeExact(localDateTime); } catch (Throwable e) { throw new RuntimeException(e); } }
private static int getHashPosition(Block keyBlock, int position, MethodHandle keyBlockHashCode, int hashTableSize) { if (keyBlock.isNull(position)) { throw new IllegalArgumentException("map keys cannot be null"); } long hashCode; try { hashCode = (long) keyBlockHashCode.invokeExact(keyBlock, position); } catch (RuntimeException e) { throw e; } catch (Throwable throwable) { throw new RuntimeException(throwable); } return computePosition(hashCode, hashTableSize); }
private static int getHashPosition(Block keyBlock, int position, MethodHandle keyBlockHashCode, int hashTableSize) { if (keyBlock.isNull(position)) { throw new IllegalArgumentException("map keys cannot be null"); } long hashCode; try { hashCode = (long) keyBlockHashCode.invokeExact(keyBlock, position); } catch (RuntimeException e) { throw e; } catch (Throwable throwable) { throw new RuntimeException(throwable); } return computePosition(hashCode, hashTableSize); }
@Override public int hashCode(Object value) { try { return toIntExact(Long.hashCode((long) hashCodeHandle.invokeExact(value))); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } }
@Override public int hashCode(long value) { try { return Long.hashCode((long) hashCodeHandle.invokeExact(value)); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } }
@Override public int hashCode(double value) { try { return Long.hashCode((long) hashCodeHandle.invokeExact(value)); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } }
private static boolean invokeGetResult(MethodHandle getResultMethodHandle, int comparisonResult) { try { return (boolean) getResultMethodHandle.invokeExact(comparisonResult); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } }
@Override public boolean equals(double a, double b) { try { Boolean result = (Boolean) equalsHandle.invokeExact(a, b); // FastutilHashSet is not intended be used for indeterminate values lookup verify(result != null, "result is null"); return TRUE.equals(result); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } } }
@Override public boolean equals(Object a, Object b) { try { Boolean result = (Boolean) equalsHandle.invokeExact(a, b); // FastutilHashSet is not intended be used for indeterminate values lookup verify(result != null, "result is null"); return TRUE.equals(result); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } } }
@Override public boolean equals(long a, long b) { try { Boolean result = (Boolean) equalsHandle.invokeExact(a, b); // FastutilHashSet is not intended be used for indeterminate values lookup verify(result != null, "result is null"); return TRUE.equals(result); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } } }
private static void compareAndUpdateState(MethodHandle methodHandle, NullableLongState state, long value) { if (state.isNull()) { state.setNull(false); state.setLong(value); return; } try { if ((boolean) methodHandle.invokeExact(value, state.getLong())) { state.setLong(value); } } catch (Throwable t) { throw internalError(t); } }
private static void compareAndUpdateState(MethodHandle methodHandle, NullableDoubleState state, double value) { if (state.isNull()) { state.setNull(false); state.setDouble(value); return; } try { if ((boolean) methodHandle.invokeExact(value, state.getDouble())) { state.setDouble(value); } } catch (Throwable t) { throw internalError(t); } }
private static void compareAndUpdateState(MethodHandle methodHandle, NullableBooleanState state, boolean value) { if (state.isNull()) { state.setNull(false); state.setBoolean(value); return; } try { if ((boolean) methodHandle.invokeExact(value, state.getBoolean())) { state.setBoolean(value); } } catch (Throwable t) { throw internalError(t); } } }
@Test public void testCompose2withoutS() throws Throwable { MethodHandle fU2R = methodHandle(TestMethodHandleUtil.class, "fU2R", U.class); MethodHandle fT2U = methodHandle(TestMethodHandleUtil.class, "fT2U", T1.class, T2.class); MethodHandle composed = compose(fU2R, fT2U); assertEquals((R) composed.invokeExact(new T1(2), new T2(3)), new R(6)); }
@Test public void testCompose2() throws Throwable { MethodHandle fUS2R = methodHandle(TestMethodHandleUtil.class, "fUS2R", U.class, S1.class, S2.class); MethodHandle fT2U = methodHandle(TestMethodHandleUtil.class, "fT2U", T1.class, T2.class); MethodHandle composed = compose(fUS2R, fT2U); assertEquals((R) composed.invokeExact(new T1(2), new T2(3), new S1(5), new S2(7)), new R(210)); }
@Test public void testCompose3() throws Throwable { MethodHandle fUV2R = methodHandle(TestMethodHandleUtil.class, "fUV2R", U.class, V.class); MethodHandle fS2U = methodHandle(TestMethodHandleUtil.class, "fS2U", S1.class, S2.class); MethodHandle fT2V = methodHandle(TestMethodHandleUtil.class, "fT2V", T1.class, T2.class); MethodHandle composed = compose(fUV2R, fS2U, fT2V); assertEquals((R) composed.invokeExact(new S1(2), new S2(3), new T1(5), new T2(7)), new R(210)); }
@TypeParameter("T") @TypeParameterSpecialization(name = "T", nativeContainerType = long.class) @SqlType(StandardTypes.BIGINT) public static long hashLong( @OperatorDependency(operator = HASH_CODE, returnType = StandardTypes.BIGINT, argumentTypes = {"T"}) MethodHandle hashFunction, @TypeParameter("T") Type type, @SqlType("array(T)") Block block) { try { long hash = 0; for (int i = 0; i < block.getPositionCount(); i++) { hash = CombineHashFunction.getHash(hash, block.isNull(i) ? NULL_HASH_CODE : (long) hashFunction.invokeExact(type.getLong(block, i))); } return hash; } catch (Throwable t) { throw internalError(t); } }
@SqlType(StandardTypes.INTEGER) public static long testRegularConvention( @FunctionDependency(name = "add", returnType = StandardTypes.INTEGER, argumentTypes = {StandardTypes.INTEGER, StandardTypes.INTEGER}, convention = @Convention(arguments = {NEVER_NULL, NEVER_NULL}, result = FAIL_ON_NULL)) MethodHandle function, @SqlType(StandardTypes.INTEGER) long left, @SqlType(StandardTypes.INTEGER) long right) { try { return (long) function.invokeExact(left, right); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } } }