srowen commented on a change in pull request #33947:
URL: https://github.com/apache/spark/pull/33947#discussion_r705553639
##########
File path: common/unsafe/src/main/java/org/apache/spark/unsafe/Platform.java
##########
@@ -77,28 +67,52 @@
cleanerClassName = "jdk.internal.ref.Cleaner";
}
try {
- Class<?> cleanerClass = Class.forName(cleanerClassName);
- Method createMethod = cleanerClass.getMethod("create", Object.class,
Runnable.class);
- // Accessing jdk.internal.ref.Cleaner should actually fail by default in
JDK 9+,
- // unfortunately, unless the user has allowed access with something like
- // --add-opens java.base/java.lang=ALL-UNNAMED If not, we can't really
use the Cleaner
- // hack below. It doesn't break, just means the user might run into the
default JVM limit
- // on off-heap memory and increase it or set the flag above. This tests
whether it's
- // available:
+ Class<?> cls = Class.forName("java.nio.DirectByteBuffer");
Review comment:
This was simply moved from above to further unify handling of exceptions
during init
##########
File path: common/unsafe/src/main/java/org/apache/spark/unsafe/Platform.java
##########
@@ -77,28 +67,52 @@
cleanerClassName = "jdk.internal.ref.Cleaner";
}
try {
- Class<?> cleanerClass = Class.forName(cleanerClassName);
- Method createMethod = cleanerClass.getMethod("create", Object.class,
Runnable.class);
- // Accessing jdk.internal.ref.Cleaner should actually fail by default in
JDK 9+,
- // unfortunately, unless the user has allowed access with something like
- // --add-opens java.base/java.lang=ALL-UNNAMED If not, we can't really
use the Cleaner
- // hack below. It doesn't break, just means the user might run into the
default JVM limit
- // on off-heap memory and increase it or set the flag above. This tests
whether it's
- // available:
+ Class<?> cls = Class.forName("java.nio.DirectByteBuffer");
+ Constructor<?> constructor = cls.getDeclaredConstructor(Long.TYPE,
Integer.TYPE);
+ Field cleanerField = cls.getDeclaredField("cleaner");
try {
- createMethod.invoke(null, null, null);
- } catch (IllegalAccessException e) {
- // Don't throw an exception, but can't log here?
- createMethod = null;
- } catch (InvocationTargetException ite) {
- // shouldn't happen; report it
- throw new IllegalStateException(ite);
+ constructor.setAccessible(true);
+ cleanerField.setAccessible(true);
+ } catch (RuntimeException re) {
+ // This is a Java 9+ exception, so needs to be handled without
importing it
+ if
("InaccessibleObjectException".equals(re.getClass().getSimpleName())) {
Review comment:
This is really the new exception handling; now have to catch this and
also handle the case where DBB_CONSTRUCTOR and DBB_CLEANER_FIELD aren't
available.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]