natDirectByteBufferImpl.cc 1.72 KB
Newer Older
1 2
// natDirectByteBufferImpl.cc

3
/* Copyright (C) 2003, 2004  Free Software Foundation
4 5 6 7 8 9 10 11 12 13 14 15

   This file is part of libgcj.

This software is copyrighted work licensed under the terms of the
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
details.  */

#include <config.h>

#include <gcj/cni.h>
#include <jvm.h>

16 17
#include <stdlib.h>

18
#include <gnu/gcj/RawData.h>
19
#include <java/nio/VMDirectByteBuffer.h>
20

21 22 23
using gnu::gcj::RawData;

RawData*
24
java::nio::VMDirectByteBuffer::allocate (jint capacity)
25
{
26
  return reinterpret_cast<gnu::gcj::RawData*> (::malloc (capacity));
27 28 29
}

void
30
java::nio::VMDirectByteBuffer::free (gnu::gcj::RawData* address)
31
{
32
  ::free (reinterpret_cast<void*> (address));
33 34 35
}

jbyte
36
java::nio::VMDirectByteBuffer::get (RawData* address, jint index)
37
{
38
  jbyte* pointer = reinterpret_cast<jbyte*> (address) + index;
39
  return *pointer;
40 41 42
}

void
43 44
java::nio::VMDirectByteBuffer::get (RawData* address, jint index,
				    jbyteArray dst, jint offset, jint length)
45 46 47 48 49 50
{
  jbyte* src = reinterpret_cast<jbyte*> (address) + index;
  memcpy (elements (dst) + offset, src, length);
}

void
51 52
java::nio::VMDirectByteBuffer::put (gnu::gcj::RawData* address,
				    jint index, jbyte value)
53
{
54
  jbyte* pointer = reinterpret_cast<jbyte*> (address) + index;
55
  *pointer = value;
56
}
57

58
RawData*
59
java::nio::VMDirectByteBuffer::adjustAddress (RawData* address, jint offset)
60 61 62 63 64
{
  jbyte* start = reinterpret_cast<jbyte*> (address) + offset;
  return reinterpret_cast<RawData*>(start);
}

65
void
66 67
java::nio::VMDirectByteBuffer::shiftDown (RawData* address, jint dst_offset,
					  jint src_offset, jint count)
68
{
69 70
  jbyte* dst = reinterpret_cast<jbyte*> (address) + dst_offset;
  jbyte* src = reinterpret_cast<jbyte*> (address) + src_offset;
71 72
  ::memmove(dst, src, count);
}