aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/anthonyhilyard/iceberg/util/UnsafeUtil.java
blob: d8410cee84ee48b033ed423e2b26c23e69e858de (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
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);
	}
}