本文整理了Java中sun.misc.Unsafe.addressSize()
方法的一些代码示例,展示了Unsafe.addressSize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Unsafe.addressSize()
方法的具体详情如下:
包路径:sun.misc.Unsafe
类名称:Unsafe
方法名:addressSize
[英]Report the size in bytes of a native pointer, as stored via #putAddress. This value will be either 4 or 8. Note that the sizes of other primitive types (as stored in native memory blocks) is determined fully by their information content.
[中]报告通过#putAddress存储的本机指针的字节大小。该值将为4或8。请注意,其他基本类型(存储在本机内存块中)的大小完全由其信息内容决定。
代码示例来源:origin: netty/netty
static int addressSize() {
return UNSAFE.addressSize();
}
代码示例来源:origin: prestodb/presto
public VMOptions(String name) {
this.name = name;
this.sizeReference = U.addressSize();
this.objectAlignment = guessAlignment(this.sizeReference);
this.compressedRef = false;
this.compressRefShift = 1;
}
代码示例来源:origin: redisson/redisson
static int addressSize() {
return UNSAFE.addressSize();
}
代码示例来源:origin: wildfly/wildfly
static int addressSize() {
return UNSAFE.addressSize();
}
代码示例来源:origin: apache/geode
/**
* 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();
}
代码示例来源:origin: prestodb/presto
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");
}
}
代码示例来源:origin: stackoverflow.com
int addressSize = unsafe.addressSize();
long objectAddress;
switch (addressSize)
代码示例来源:origin: io.netty/netty-common
static int addressSize() {
return UNSAFE.addressSize();
}
代码示例来源:origin: io.prestosql/presto-jdbc
public VMOptions(String name) {
this.name = name;
this.sizeReference = U.addressSize();
this.objectAlignment = guessAlignment(this.sizeReference);
this.compressedRef = false;
this.compressRefShift = 1;
}
代码示例来源:origin: com.facebook.presto/presto-jdbc
public VMOptions(String name) {
this.name = name;
this.sizeReference = U.addressSize();
this.objectAlignment = guessAlignment(this.sizeReference);
this.compressedRef = false;
this.compressRefShift = 1;
}
代码示例来源:origin: io.snappydata/gemfire-core
/**
* Returns 4 if this is a 32bit jvm; otherwise 8. Note it does not account for
* compressed oops.
*/
public int getAddressSize() {
return unsafe.addressSize();
}
代码示例来源:origin: prestosql/presto
public VMOptions(String name) {
this.name = name;
this.sizeReference = U.addressSize();
this.objectAlignment = guessAlignment(this.sizeReference);
this.compressedRef = false;
this.compressRefShift = 1;
}
代码示例来源:origin: org.apache.geode/gemfire-core
/**
* 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();
}
代码示例来源:origin: org.apache.activemq/artemis-jms-client-all
static int addressSize() {
return UNSAFE.addressSize();
}
代码示例来源:origin: com.couchbase.client/core-io
static int addressSize() {
return UNSAFE.addressSize();
}
代码示例来源:origin: stackoverflow.com
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());
}
}
代码示例来源:origin: com.esotericsoftware.kryo/kryo
/** 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();
}
代码示例来源:origin: com.esotericsoftware/kryo
/** 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();
}
代码示例来源:origin: svn2github/kryo
/** 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();
}
代码示例来源:origin: com.esotericsoftware/kryo-shaded
/** 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();
}
内容来源于网络,如有侵权,请联系作者删除!