public class UnsafeAccess extends Object
Modifier and Type | Field and Description |
---|---|
static sun.misc.Unsafe |
unsafe
An instance of
Unsafe for use within JVMCI. |
Constructor and Description |
---|
UnsafeAccess() |
Modifier and Type | Method and Description |
---|---|
static long |
createCString(String s)
Copies the contents of a
String to a native memory buffer as a '\0'
terminated C string. |
static String |
readCString(long address)
Reads a
'\0' terminated C string from native memory and converts it to a
String . |
static long |
writeCString(String s,
long buf)
Writes the contents of a
String to a native memory buffer as a '\0'
terminated C string. |
public static final sun.misc.Unsafe unsafe
Unsafe
for use within JVMCI.public UnsafeAccess()
public static long createCString(String s)
String
to a native memory buffer as a '\0'
terminated C string. The native memory buffer is allocated via
Unsafe.allocateMemory(long)
. The caller is responsible for releasing the buffer when
it is no longer needed via Unsafe.freeMemory(long)
.s
public static String readCString(long address)
'\0'
terminated C string from native memory and converts it to a
String
.public static long writeCString(String s, long buf)
String
to a native memory buffer as a '\0'
terminated C string. The caller is responsible for ensuring the buffer is at least
s.length() + 1
bytes long. The caller is also responsible for releasing the buffer
when it is no longer.buf