Java-Unsafe类(一)
2017-06-04 11:13
316 查看
1、 sun.misc.Unsafe 提供了可随意查看及修改JVM中运行时的数据结构
2、
参考: 参考1
2、
import sun.misc.Unsafe; // Eclipse引入此行会出现错误提示, 解决方法: [方法](http://blog.csdn.net/fenglibing/article/details/17138079) public class Test { public static void main(String args[]) throws Exception{ Field f = Unsafe.class.getDeclaredField("theUnsafe"); f.settAccessible(true); Unsafe unsafe = (Unsafe)f.get(null); Player p = (Player)unsafe.allocateInstance(Player.class); p.setAge(45); unsafe.allocateMemory(0L); unsafe.freeMemory(0L)l unsafe.compareAndSwapInt(...); } } class Player { private int age = 12; private Player () { this.age = 50; } public int getAge() {return this.age;} public void setAge(int age) {this.age = age;} }
参考: 参考1
相关文章推荐
- java 中的Unsafe(转)
- 编译.java后出现:Note:checkUser.java uses unchecked or unsafe operations.Note:Recompile with -Xlint :unchecked for details.
- 危险代码:如何使用Unsafe操作内存中的Java类和对象—Part4
- Java源码剖析 sun.misc.Unsafe
- [Java 基础]sun.misc.Unsafe
- Error:scalac: bad option: -P:genjavadoc:out=D:\spark\unsafe\target\java
- How and Why Unsafe is Used in Java---reference
- java 中的Unsafe
- Java --- Unsafe
- 使用sun.misc.Unsafe获取java对象地址
- 出现Note: Test.java uses unchecked or unsafe operations.Note: Recompile
- Java Magic. Part 4: sun.misc.Unsafe
- 聊聊序列化(二)使用sun.misc.Unsafe绕过new机制来创建Java对象
- Java中的sun.misc.Unsafe
- 出现Note: XXX.java uses unchecked or unsafe operations.
- 使用sun.misc.Unsafe获取java对象地址
- 危险代码:如何使用Unsafe操作内存中的Java类和对象
- java Unsafe.java(二)
- java对象的内存布局(二):利用sun.misc.Unsafe获取类字段的偏移地址和读取字段的值
- java 中的Unsafe