-
Notifications
You must be signed in to change notification settings - Fork 0
/
sun.misc.Unsafe
33 lines (17 loc) · 1.01 KB
/
sun.misc.Unsafe
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
Understanding sun.misc.Unsafe
1. Native memory allocation
===========================
Was there a need in one of your projects to have more entries in an Array than Integer.MAX_VALUE offers ?
Yes, then have a look at the following tutorial.
This tutorial is a quick overview of sun.misc.Unsafe public API and few interesting cases of its usage.
Unsafe instantiation
We need to create instance of Unsafe object.
There is no simple way to do it like Unsafe unsafe = new Unsafe(), because Unsafe class has private constructor.
It also has static getUnsafe() method, but if you naively try to call Unsafe.getUnsafe() you, probably, get SecurityException.
Using this method available only from trusted code.
2. Try to do code reflection with sun.misc.Unsafe
=================================================
The goal is to show we can "weaver" in code like AspectJ is doing it with the sun.misc.Unsafe library.
DISCUSSION:
Oracle plans in JDK 9 to restrict access to sun.misc.Unsafe.
Do you think this is a good idea ?