blob: b49e29dc40db6f181c164cbc916e820383b9b898 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
package com.anthonyhilyard.iceberg.util;
import sun.misc.Unsafe;
import java.lang.reflect.Field;
public class UnsafeUtil
{
private static final Unsafe UNSAFE;
static
{
try
{
Field field = Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
UNSAFE = (Unsafe) field.get(null);
}
catch (NoSuchFieldException | IllegalAccessException e)
{
throw new RuntimeException("Couldn't obtain reference to sun.misc.Unsafe", e);
}
}
public static float readFloat(long address)
{
return UNSAFE.getFloat(address);
}
public static int readInt(long address)
{
return UNSAFE.getInt(address);
}
public static byte readByte(long address)
{
return UNSAFE.getByte(address);
}
}
|