Search in sources :

Example 11 with ByteOrder

use of java.nio.ByteOrder in project jdk8u_jdk by JetBrains.

the class MotifDnDConstants method getTargetListTable.

/**
     * DragBSI.h:
     *
     * typedef struct {
     *    BYTE          byte_order;
     *    BYTE          protocol_version;
     *    CARD16        num_target_lists B16;
     *    CARD32        heap_offset B32;
     * } xmMotifTargetsPropertyRec;
     */
private static long[][] getTargetListTable(long motifWindow) throws XException {
    WindowPropertyGetter wpg = new WindowPropertyGetter(motifWindow, XA_MOTIF_DRAG_TARGETS, 0, 100000L, false, XA_MOTIF_DRAG_TARGETS.getAtom());
    try {
        int status = wpg.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
        if (status != XConstants.Success || wpg.getActualType() != XA_MOTIF_DRAG_TARGETS.getAtom() || wpg.getData() == 0) {
            return null;
        }
        long data = wpg.getData();
        if (unsafe.getByte(data + 1) != MOTIF_DND_PROTOCOL_VERSION) {
            return null;
        }
        boolean swapNeeded = unsafe.getByte(data + 0) != getByteOrderByte();
        short numTargetLists = unsafe.getShort(data + 2);
        if (swapNeeded) {
            numTargetLists = Swapper.swap(numTargetLists);
        }
        long[][] table = new long[numTargetLists][];
        ByteOrder byteOrder = ByteOrder.nativeOrder();
        if (swapNeeded) {
            byteOrder = (byteOrder == ByteOrder.LITTLE_ENDIAN) ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
        }
        long bufptr = data + 8;
        for (short i = 0; i < numTargetLists; i++) {
            short numTargets = unsafe.getShort(bufptr);
            bufptr += 2;
            if (swapNeeded) {
                numTargets = Swapper.swap(numTargets);
            }
            table[i] = new long[numTargets];
            for (short j = 0; j < numTargets; j++) {
                // NOTE: cannot use Unsafe.getInt(), since it crashes on
                // Solaris/Sparc if the address is not a multiple of 4.
                int target = 0;
                if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
                    for (int idx = 0; idx < 4; idx++) {
                        target |= (unsafe.getByte(bufptr + idx) << 8 * idx) & (0xFF << 8 * idx);
                    }
                } else {
                    for (int idx = 0; idx < 4; idx++) {
                        target |= (unsafe.getByte(bufptr + idx) << 8 * (3 - idx)) & (0xFF << 8 * (3 - idx));
                    }
                }
                // NOTE: don't need to swap, since we read it in the proper
                // order already.
                table[i][j] = target;
                bufptr += 4;
            }
        }
        return table;
    } finally {
        wpg.dispose();
    }
}
Also used : ByteOrder(java.nio.ByteOrder)

Example 12 with ByteOrder

use of java.nio.ByteOrder in project jdk8u_jdk by JetBrains.

the class AbstractPerfDataBufferPrologue method getMagic.

/**
     * Get the magic number.
     *
     * @return int - the magic number
     */
public int getMagic() {
    // the magic number is always stored in big-endian format
    ByteOrder order = byteBuffer.order();
    byteBuffer.order(ByteOrder.BIG_ENDIAN);
    // get the magic number
    byteBuffer.position(PERFDATA_PROLOG_MAGIC_OFFSET);
    int magic = byteBuffer.getInt();
    // restore the byte order
    byteBuffer.order(order);
    return magic;
}
Also used : ByteOrder(java.nio.ByteOrder)

Example 13 with ByteOrder

use of java.nio.ByteOrder in project jdk8u_jdk by JetBrains.

the class AbstractPerfDataBufferPrologue method getByteOrder.

/**
     * Get the byte order for the given ByteBuffer.
     *
     * @return int - the byte order of the instrumentation buffer
     */
public static ByteOrder getByteOrder(ByteBuffer bb) {
    // save buffer state
    int position = bb.position();
    bb.position(PERFDATA_PROLOG_BYTEORDER_OFFSET);
    ByteOrder order = (bb.get() == PERFDATA_BIG_ENDIAN) ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
    // restore buffer state.
    bb.position(position);
    return order;
}
Also used : ByteOrder(java.nio.ByteOrder)

Example 14 with ByteOrder

use of java.nio.ByteOrder in project ignite by apache.

the class MurmurHash method hash.

/**
 * Hashes the bytes in a buffer from the current position to the limit.
 *
 * @param buf The bytes to hash.
 * @param seed The seed to start with.
 * @return The 32 bit murmur hash of the bytes in the buffer.
 */
public static int hash(ByteBuffer buf, int seed) {
    ByteOrder byteOrder = buf.order();
    buf.order(ByteOrder.LITTLE_ENDIAN);
    int m = 0x5bd1e995;
    int r = 24;
    int h = seed ^ buf.remaining();
    while (buf.remaining() >= 4) {
        int k = buf.getInt();
        k *= m;
        k ^= k >>> r;
        k *= m;
        h *= m;
        h ^= k;
    }
    if (buf.remaining() > 0) {
        ByteBuffer finish = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN);
        finish.put(buf).rewind();
        h ^= finish.getInt();
        h *= m;
    }
    h ^= h >>> 13;
    h *= m;
    h ^= h >>> 15;
    buf.order(byteOrder);
    return h;
}
Also used : ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer)

Example 15 with ByteOrder

use of java.nio.ByteOrder in project suite by stupidsing.

the class GpuTest method test.

@Test
public void test() {
    String openCl = // 
    "" + // 
    "__kernel void add_floats(__global float *a, __global float *b, __global float *o, int n) { \n" + // 
    "    int i = get_global_id(0); \n" + // 
    "    if (i < n) o[i] = a[i] * a[i] + b[i] * b[i]; \n" + // 
    "} \n";
    CLContext context = JavaCL.createBestContext();
    CLQueue queue = context.createDefaultQueue();
    ByteOrder byteOrder = context.getByteOrder();
    int n = 1024;
    Pointer<Float> inp0 = Pointer.allocateFloats(n).order(byteOrder);
    Pointer<Float> inp1 = Pointer.allocateFloats(n).order(byteOrder);
    for (int i = 0; i < n; i++) {
        inp0.set(i, (float) Math.cos(i));
        inp1.set(i, (float) Math.sin(i));
    }
    CLBuffer<Float> out = context.createBuffer(Usage.Output, Float.class, n);
    CLKernel kernel = context.createProgram(openCl).createKernel("add_floats");
    kernel.setArgs(context.createBuffer(Usage.Input, inp0), context.createBuffer(Usage.Input, inp1), out, n);
    Pointer<Float> outp = out.read(queue, kernel.enqueueNDRange(queue, new int[] { n }));
    for (CLDevice device : context.getDevices()) System.out.println(device);
    for (int i = 0; i < min(10, n); i++) System.out.println("out[" + i + "] = " + outp.get(i));
}
Also used : CLContext(com.nativelibs4java.opencl.CLContext) CLQueue(com.nativelibs4java.opencl.CLQueue) CLDevice(com.nativelibs4java.opencl.CLDevice) ByteOrder(java.nio.ByteOrder) CLKernel(com.nativelibs4java.opencl.CLKernel) Test(org.junit.Test)

Aggregations

ByteOrder (java.nio.ByteOrder)111 ByteBuffer (java.nio.ByteBuffer)39 IOException (java.io.IOException)8 Test (org.junit.Test)7 QuickTest (com.hazelcast.test.annotation.QuickTest)5 DataInputStream (java.io.DataInputStream)5 FileInputStream (java.io.FileInputStream)5 UUID (java.util.UUID)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 HKL (ffx.crystal.HKL)3 DataOutputStream (java.io.DataOutputStream)3 EOFException (java.io.EOFException)3 FileOutputStream (java.io.FileOutputStream)3 ShortBuffer (java.nio.ShortBuffer)3 ArrayList (java.util.ArrayList)3 Element (org.jdom.Element)3 InvalidDumpFormatException (com.ibm.j9ddr.corereaders.InvalidDumpFormatException)2 Point (com.revolsys.geometry.model.Point)2 Crystal (ffx.crystal.Crystal)2 BigInteger (java.math.BigInteger)2