Skip to content

V07 Android Support - #180

Merged
xerial merged 5 commits into
v07-universal-bufferfrom
v07-android
Jan 19, 2015
Merged

xerial merged 5 commits into
v07-universal-bufferfrom
v07-android

Conversation

@xerial

@xerial xerial commented Jan 18, 2015

Copy link
Copy Markdown
Member

For fixing #101, added several workarounds that include:

  • Added a switch for finding Unsafe and DirectByteBuffer classes.
  • Use putLong to detect the endian (unsafe.getByte is unavailable in Android)
  • Use the unversal MessageBufferU since some unsafe.getXXX methods are missing.

This PR is basd on v07-universal-buffer branch.

@xerial

xerial commented Jan 19, 2015

Copy link
Copy Markdown
Member Author

@komamitsu Could you review these changes?

Although the following warnings will be shown in Android, these instance methods (getXXX, putXXX, etc.) will be replaced with MessageBufferU's implementation.

01-18 21:42:17.497    1485-1498/msgpack.org.messagepackandroid I/dalvikvm﹕ Could not find method sun.misc.Unsafe.allocateMemory, referenced from method org.msgpack.core.buffer.MessageBuffer.newOffHeapBuffer
01-18 21:42:17.497    1485-1498/msgpack.org.messagepackandroid W/dalvikvm﹕ VFY: unable to resolve virtual method 13516: Lsun/misc/Unsafe;.allocateMemory (J)J
01-18 21:42:17.497    1485-1498/msgpack.org.messagepackandroid D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0003
01-18 21:42:17.507    1485-1498/msgpack.org.messagepackandroid I/dalvikvm﹕ Could not find method sun.misc.Unsafe.freeMemory, referenced from method org.msgpack.core.buffer.MessageBuffer.releaseBuffer
01-18 21:42:17.507    1485-1498/msgpack.org.messagepackandroid W/dalvikvm﹕ VFY: unable to resolve virtual method 13520: Lsun/misc/Unsafe;.freeMemory (J)V
01-18 21:42:17.507    1485-1498/msgpack.org.messagepackandroid D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x001b
01-18 21:42:17.507    1485-1498/msgpack.org.messagepackandroid I/dalvikvm﹕ Could not find method sun.misc.Unsafe.copyMemory, referenced from method org.msgpack.core.buffer.MessageBuffer.copyTo
01-18 21:42:17.507    1485-1498/msgpack.org.messagepackandroid W/dalvikvm﹕ VFY: unable to resolve virtual method 13519: Lsun/misc/Unsafe;.copyMemory (Ljava/lang/Object;JLjava/lang/Object;JJ)V
01-18 21:42:17.507    1485-1498/msgpack.org.messagepackandroid D/dalvikvm﹕ VFY: replacing opcode 0x74 at 0x0010
01-18 21:42:17.517    1485-1498/msgpack.org.messagepackandroid I/dalvikvm﹕ Could not find method sun.misc.Unsafe.getBoolean, referenced from method org.msgpack.core.buffer.MessageBuffer.getBoolean
01-18 21:42:17.517    1485-1498/msgpack.org.messagepackandroid W/dalvikvm﹕ VFY: unable to resolve virtual method 13521: Lsun/misc/Unsafe;.getBoolean (Ljava/lang/Object;J)Z
01-18 21:42:17.517    1485-1498/msgpack.org.messagepackandroid D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0008
01-18 21:42:17.517    1485-1498/msgpack.org.messagepackandroid I/dalvikvm﹕ Could not find method sun.misc.Unsafe.getByte, referenced from method org.msgpack.core.buffer.MessageBuffer.getByte
01-18 21:42:17.527    1485-1498/msgpack.org.messagepackandroid W/dalvikvm﹕ VFY: unable to resolve virtual method 13522: Lsun/misc/Unsafe;.getByte (Ljava/lang/Object;J)B
01-18 21:42:17.527    1485-1498/msgpack.org.messagepackandroid D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0008
01-18 21:42:17.527    1485-1498/msgpack.org.messagepackandroid I/dalvikvm﹕ Could not find method sun.misc.Unsafe.copyMemory, referenced from method org.msgpack.core.buffer.MessageBuffer.getBytes
01-18 21:42:17.527    1485-1498/msgpack.org.messagepackandroid W/dalvikvm﹕ VFY: unable to resolve virtual method 13519: Lsun/misc/Unsafe;.copyMemory (Ljava/lang/Object;JLjava/lang/Object;JJ)V
01-18 21:42:17.527    1485-1498/msgpack.org.messagepackandroid D/dalvikvm﹕ VFY: replacing opcode 0x74 at 0x000f
01-18 21:42:17.527    1485-1498/msgpack.org.messagepackandroid I/dalvikvm﹕ Could not find method sun.misc.Unsafe.getShort, referenced from method org.msgpack.core.buffer.MessageBuffer.getShort
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid W/dalvikvm﹕ VFY: unable to resolve virtual method 13527: Lsun/misc/Unsafe;.getShort (Ljava/lang/Object;J)S
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0008
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid I/dalvikvm﹕ Could not find method sun.misc.Unsafe.putBoolean, referenced from method org.msgpack.core.buffer.MessageBuffer.putBoolean
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid W/dalvikvm﹕ VFY: unable to resolve virtual method 13528: Lsun/misc/Unsafe;.putBoolean (Ljava/lang/Object;JZ)V
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0008
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid I/dalvikvm﹕ Could not find method sun.misc.Unsafe.putByte, referenced from method org.msgpack.core.buffer.MessageBuffer.putByte
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid W/dalvikvm﹕ VFY: unable to resolve virtual method 13529: Lsun/misc/Unsafe;.putByte (Ljava/lang/Object;JB)V
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0008
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid I/dalvikvm﹕ Could not find method sun.misc.Unsafe.copyMemory, referenced from method org.msgpack.core.buffer.MessageBuffer.putByteBuffer
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid W/dalvikvm﹕ VFY: unable to resolve virtual method 13519: Lsun/misc/Unsafe;.copyMemory (Ljava/lang/Object;JLjava/lang/Object;JJ)V
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid D/dalvikvm﹕ VFY: replacing opcode 0x74 at 0x002b
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid I/dalvikvm﹕ Could not find method sun.misc.Unsafe.copyMemory, referenced from method org.msgpack.core.buffer.MessageBuffer.putByteBuffer
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid W/dalvikvm﹕ VFY: unable to resolve virtual method 13519: Lsun/misc/Unsafe;.copyMemory (Ljava/lang/Object;JLjava/lang/Object;JJ)V
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid D/dalvikvm﹕ VFY: replacing opcode 0x74 at 0x0052
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid I/dalvikvm﹕ Could not find method sun.misc.Unsafe.putByte, referenced from method org.msgpack.core.buffer.MessageBuffer.putByteBuffer
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid W/dalvikvm﹕ VFY: unable to resolve virtual method 13529: Lsun/misc/Unsafe;.putByte (Ljava/lang/Object;JB)V
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0073
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid I/dalvikvm﹕ Could not find method sun.misc.Unsafe.copyMemory, referenced from method org.msgpack.core.buffer.MessageBuffer.putBytes
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid W/dalvikvm﹕ VFY: unable to resolve virtual method 13519: Lsun/misc/Unsafe;.copyMemory (Ljava/lang/Object;JLjava/lang/Object;JJ)V
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid D/dalvikvm﹕ VFY: replacing opcode 0x74 at 0x000e
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid I/dalvikvm﹕ Could not find method sun.misc.Unsafe.putShort, referenced from method org.msgpack.core.buffer.MessageBuffer.putShort
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid W/dalvikvm﹕ VFY: unable to resolve virtual method 13533: Lsun/misc/Unsafe;.putShort (Ljava/lang/Object;JS)V
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000c
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid I/dalvikvm﹕ Could not find method sun.misc.Unsafe.copyMemory, referenced from method org.msgpack.core.buffer.MessageBuffer.toByteArray
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid W/dalvikvm﹕ VFY: unable to resolve virtual method 13519: Lsun/misc/Unsafe;.copyMemory (Ljava/lang/Object;JLjava/lang/Object;JJ)V
01-18 21:42:17.537    1485-1498/msgpack.org.messagepackandroid D/dalvikvm﹕ VFY: replacing opcode 0x74 at 0x0014
01-18 21:42:18.367    1485-1498/msgpack.org.messagepackandroid D/dalvikvm﹕ threadid=11: still suspended after undo (sc=1 dc=1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Can we replace these lines with java.nio.ByteOrder#nativeOrder?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. ByteOrder.nativeOrder is doing almost the same thing:

    static ByteOrder byteOrder() {
    if (byteOrder != null)
        return byteOrder;
    long a = unsafe.allocateMemory(8);
    try {
        unsafe.putLong(a, 0x0102030405060708L);
        byte b = unsafe.getByte(a);
        switch (b) {
        case 0x01: byteOrder = ByteOrder.BIG_ENDIAN;     break;
        case 0x08: byteOrder = ByteOrder.LITTLE_ENDIAN;  break;
        default:
        throw new Error("Unknown byte order");
        }
    } finally {
        unsafe.freeMemory(a);
    }
    return byteOrder;
    }

But I'm not sure this method is properly implemented for all platforms.

@komamitsu

Copy link
Copy Markdown
Member

Looks good.

@xerial
xerial merged commit 629f0b3 into v07-universal-buffer Jan 19, 2015
@xerial
xerial deleted the v07-android branch May 28, 2015 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants