Github user felixcheung commented on a diff in the pull request: https://github.com/apache/spark/pull/22993#discussion_r232477875 --- Diff: common/unsafe/src/main/java/org/apache/spark/unsafe/Platform.java --- @@ -67,6 +67,59 @@ unaligned = _unaligned; } + // Access fields and constructors once and store them, for performance: + + private static final Constructor<?> DBB_CONSTRUCTOR; + private static final Field DBB_CLEANER_FIELD; + static { + try { + Class<?> cls = Class.forName("java.nio.DirectByteBuffer"); + Constructor<?> constructor = cls.getDeclaredConstructor(Long.TYPE, Integer.TYPE); + constructor.setAccessible(true); + Field cleanerField = cls.getDeclaredField("cleaner"); + cleanerField.setAccessible(true); + DBB_CONSTRUCTOR = constructor; + DBB_CLEANER_FIELD = cleanerField; + } catch (ClassNotFoundException | NoSuchMethodException | NoSuchFieldException e) { + throw new IllegalStateException(e); + } + } + + private static final Method CLEANER_CREATE_METHOD; + static { + // The implementation of Cleaner changed from JDK 8 to 9 + int majorVersion = Integer.parseInt(System.getProperty("java.version").split("\\.")[0]); --- End diff -- is there a defined fixed format for this? we are doing some java version check and found very different format from different JDK sources (Oracle vs OpenJDK vs IBM ...)
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org