This class may be removed in the future. Consider the replacements in JEP 193 'Variable Handles': http://openjdk.java.net/jeps/193
static int addressSize() { return UNSAFE.addressSize(); }
public VMOptions(String name) { this.name = name; this.sizeReference = U.addressSize(); this.objectAlignment = guessAlignment(this.sizeReference); this.compressedRef = false; this.compressRefShift = 1; }
static int addressSize() { return UNSAFE.addressSize(); }
static int addressSize() { return UNSAFE.addressSize(); }
/** * Returns 4 if this is a 32bit jvm; otherwise 8. Note it does not account for compressed oops. */ public int getAddressSize() { return this.unsafe.addressSize(); }
private static VMOptions getOptions() { // try Hotspot VMOptions hsOpts = getHotspotSpecifics(); if (hsOpts != null) return hsOpts; // try JRockit VMOptions jrOpts = getJRockitSpecifics(); if (jrOpts != null) return jrOpts; // When running with CompressedOops on 64-bit platform, the address size // reported by Unsafe is still 8, while the real reference fields are 4 bytes long. // Try to guess the reference field size with this naive trick. int oopSize; try { long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1")); long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2")); oopSize = (int) Math.abs(off2 - off1); } catch (NoSuchFieldException e) { throw new IllegalStateException("Infrastructure failure", e); } if (oopSize != U.addressSize()) { return new VMOptions("Auto-detected", 3); // assume compressed references have << 3 shift } else { return new VMOptions("Auto-detected"); } }
int addressSize = unsafe.addressSize(); long objectAddress; switch (addressSize)
static int addressSize() { return UNSAFE.addressSize(); }
public VMOptions(String name) { this.name = name; this.sizeReference = U.addressSize(); this.objectAlignment = guessAlignment(this.sizeReference); this.compressedRef = false; this.compressRefShift = 1; }
public VMOptions(String name) { this.name = name; this.sizeReference = U.addressSize(); this.objectAlignment = guessAlignment(this.sizeReference); this.compressedRef = false; this.compressRefShift = 1; }
/** * Returns 4 if this is a 32bit jvm; otherwise 8. Note it does not account for * compressed oops. */ public int getAddressSize() { return unsafe.addressSize(); }
public VMOptions(String name) { this.name = name; this.sizeReference = U.addressSize(); this.objectAlignment = guessAlignment(this.sizeReference); this.compressedRef = false; this.compressRefShift = 1; }
/** * Returns 4 if this is a 32bit jvm; otherwise 8. Note it does not account for compressed oops. */ public int getAddressSize() { return this.unsafe.addressSize(); }
static int addressSize() { return UNSAFE.addressSize(); }
static int addressSize() { return UNSAFE.addressSize(); }
import sun.misc.*; import java.lang.reflect.*; public class UnsafeTest { public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException { Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); unsafeField.setAccessible(true); Unsafe unsafe = (Unsafe) unsafeField.get(null); System.out.println(unsafe.addressSize()); } }
/** Returns the in-memory size of a field which has a given class */ private int fieldSizeOf (Class<?> clazz) { if (clazz == int.class || clazz == float.class) return 4; if (clazz == long.class || clazz == double.class) return 8; if (clazz == byte.class || clazz == boolean.class) return 1; if (clazz == short.class || clazz == char.class) return 2; // Everything else is a reference to an object, i.e. an address return unsafe().addressSize(); }
/** Returns the in-memory size of a field which has a given class */ private int fieldSizeOf (Class<?> clazz) { if (clazz == int.class || clazz == float.class) return 4; if (clazz == long.class || clazz == double.class) return 8; if (clazz == byte.class || clazz == boolean.class) return 1; if (clazz == short.class || clazz == char.class) return 2; // Everything else is a reference to an object, i.e. an address return unsafe().addressSize(); }
/** Returns the in-memory size of a field which has a given class */ private int fieldSizeOf (Class<?> clazz) { if (clazz == int.class || clazz == float.class) return 4; if (clazz == long.class || clazz == double.class) return 8; if (clazz == byte.class || clazz == boolean.class) return 1; if (clazz == short.class || clazz == char.class) return 2; // Everything else is a reference to an object, i.e. an address return unsafe().addressSize(); }
/** Returns the in-memory size of a field which has a given class */ private int fieldSizeOf (Class<?> clazz) { if (clazz == int.class || clazz == float.class) return 4; if (clazz == long.class || clazz == double.class) return 8; if (clazz == byte.class || clazz == boolean.class) return 1; if (clazz == short.class || clazz == char.class) return 2; // Everything else is a reference to an object, i.e. an address return unsafe().addressSize(); }