[
https://issues.apache.org/jira/browse/AVRO-1282?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13638471#comment-13638471
]
Scott Carey commented on AVRO-1282:
-----------------------------------
-1
This appears to break some JVMs by assuming that Unsafe exists.
{code}
public class UnsafeUtil {
final static private Unsafe UNSAFE;
{code}
Is guaranteed to trigger class not found on say, IBM's JDK.
Other libraries that use Unsafe prevent this by attempting to load Unsafe in an
inner class. If it succeeds, they load the "unsafe variant" types, and
otherwise load the ordinary variant.
So for example, there would be two implementations of FieldAccess -- and only
one would ever be loaded by the classloader -- UnsafeFieldAccess if Unsafe is
reachable and ReflectFieldAccess otehrwise. This also helps performance
because if there is only one implementation of an abstract class encountered by
the JVM, it can inline all of the virtual call sites.
For example, see how this project does it:
https://github.com/dain/snappy/blob/master/src/main/java/org/iq80/snappy/Memory.java
https://github.com/dain/snappy/blob/master/src/main/java/org/iq80/snappy/SnappyInternalUtils.java
https://github.com/dain/snappy/blob/master/src/main/java/org/iq80/snappy/SlowMemory.java
https://github.com/dain/snappy/blob/master/src/main/java/org/iq80/snappy/UnsafeMemory.java
> Make use of the sun.misc.Unsafe class during serialization if a JDK supports
> it
> -------------------------------------------------------------------------------
>
> Key: AVRO-1282
> URL: https://issues.apache.org/jira/browse/AVRO-1282
> Project: Avro
> Issue Type: Improvement
> Components: java
> Affects Versions: 1.7.4
> Reporter: Leo Romanoff
> Priority: Minor
> Attachments: avro-1282-v1.patch, avro-1282-v2.patch,
> avro-1282-v3.patch, avro-1282-v4.patch, avro-1282-v5.patch, avro-1282-v6.patch
>
>
> Unsafe can be used to significantly speed up serialization process, if a JDK
> implementation supports java.misc.Unsafe properly. Most JDKs running on PCs
> support it. Some platforms like Android lack a proper support for Unsafe yet.
> There are two possibilities to use Unsafe for serialization:
> 1) Very quick access to the fields of objects. It is way faster than with the
> reflection-based approach using Field.get/set
> 2) Input and Output streams can be using Unsafe to perform very quick
> input/output.
>
> 3) More over, Unsafe makes it possible to serialize to/deserialize from
> off-heap memory directly and very quickly, without any intermediate buffers
> allocated on heap. There is virtually no overhead compared to the usual byte
> arrays.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira