Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sun.misc.Unsafe;
- import java.lang.reflect.Field;
- public class TestPointers {
- public static void main(String[] args) throws Exception {
- Unsafe unsafe = getUnsafe();
- System.out.println("Unsafe = " + unsafe);
- System.out.println(" addressSize() = " + unsafe.addressSize());
- System.out.println(" pageSize() = " + unsafe.pageSize());
- System.out.println(" pageSize() = " + unsafe.pageSize());
- try {
- unsafe.putByte((long) 0xa000, (byte) 47);
- } catch(Throwable e) {
- System.out.println("IN THE CATCH BLOCK");
- e.printStackTrace();
- } finally {
- System.out.println("IN THE FINALLY BLOCK");
- }
- System.exit(0);
- }
- public static Unsafe getUnsafe() {
- Unsafe unsafe = null;
- try {
- Class uc = Unsafe.class;
- Field[] fields = uc.getDeclaredFields();
- for(int i = 0; i < fields.length; i++) {
- if(fields[i].getName().equals("theUnsafe")) {
- fields[i].setAccessible(true);
- unsafe = (Unsafe) fields[i].get(uc);
- break;
- }
- }
- } catch(Exception ignore) {
- }
- return unsafe;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement