[
https://issues.apache.org/jira/browse/HADOOP-12690?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15094653#comment-15094653
]
Colin Patrick McCabe commented on HADOOP-12690:
-----------------------------------------------
Thanks, [~djp]. This looks good overall.
{code}
protected static final int BYTES_PER_SLOT = 64;
- private static final Unsafe unsafe = safetyDance();
-
- private static Unsafe safetyDance() {
- try {
- Field f = Unsafe.class.getDeclaredField("theUnsafe");
- f.setAccessible(true);
- return (Unsafe)f.get(null);
- } catch (Throwable e) {
- LOG.error("failed to load misc.Unsafe", e);
- }
- return null;
- }
+ private static final Unsafe unsafe = UnsafeUtil.getUnsafe();
/**
* Calculate the usable size of a shared memory segment.
{code}
We should be setting the unsafe field to null if it can't be obtained, rather
than throwing an exception. Otherwise, people without this non-standard JVM
extension can't run the code at all.
> Consolidate access of sun.misc.Unsafe
> --------------------------------------
>
> Key: HADOOP-12690
> URL: https://issues.apache.org/jira/browse/HADOOP-12690
> Project: Hadoop Common
> Issue Type: Bug
> Reporter: Junping Du
> Assignee: Junping Du
> Attachments: HADOOP-12690-v2.1.patch, HADOOP-12690-v2.patch,
> HADOOP-12690.patch
>
>
> Per discussion in Hadoop-12630
> (https://issues.apache.org/jira/browse/HADOOP-12630?focusedCommentId=15082142&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-15082142),
> we found the access of sun.misc.Unsafe could be problematic for some JVMs in
> other platforms. Also, hints from other comments, it is better to consolidate
> it as a helper/utility method to shared with several places
> (FastByteComparisons, NativeIO, ShortCircuitShm).
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)