[
https://issues.apache.org/jira/browse/IGNITE-6740?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16289293#comment-16289293
]
Evgenii Zhuravlev commented on IGNITE-6740:
-------------------------------------------
[~andrey-kuznetsov], I don't think that it's the best solution that we could
use here, what do you think about something like that:
add to the GridUnsafe:
{code:java}
/**
* @param buffer direct buffer.
*/
public static long getAddress(ByteBuffer buffer) {
return UNSAFE.getLong(buffer, fieldOffset(field(Buffer.class,
"address")));
}
/**
* Returns the offset of the provided field, or {@code -1} if {@code
sun.misc.Unsafe} is not
* available.
*/
private static long fieldOffset(Field field) {
return field == null ? -1 : UNSAFE.objectFieldOffset(field);
}
/**
* Gets the field with the given name within the class, or {@code null} if
not found. If found,
* the field is made accessible.
*/
private static Field field(Class<?> clazz, String fieldName) {
Field field;
try {
field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
} catch (Throwable t) {
// Failed to access the fields.
field = null;
}
return field;
}
{code}
and replace ((DirectBuffer)buf).address() with GridUnsafe.getAddress(buf) in
DirectByteBufferStreamImplV1 & DirectByteBufferStreamImplV2.
It should show better performance.
What do you think, can it work here?
> Java 9: rework DirectBuffer.address() usages
> --------------------------------------------
>
> Key: IGNITE-6740
> URL: https://issues.apache.org/jira/browse/IGNITE-6740
> Project: Ignite
> Issue Type: Task
> Components: general
> Reporter: Vladimir Ozerov
> Assignee: Andrey Kuznetsov
> Fix For: 2.4
>
>
> We have two usages of {{DirectBuffer.address()}} method which is no longer
> accessible in Java 9:
> 1) {{DirectByteBufferStreamImplV1}}
> 2) {{DirectByteBufferStreamImplV2}}
> Need to rework this code using reflection and/or {{Unsafe}}, so that it
> compiles and work on all Java versions.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)