本文整理了Java中sun.misc.Unsafe.staticFieldBase()
方法的一些代码示例,展示了Unsafe.staticFieldBase()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Unsafe.staticFieldBase()
方法的具体详情如下:
包路径:sun.misc.Unsafe
类名称:Unsafe
方法名:staticFieldBase
[英]Returns the base address for accessing some static field in the given class. This method is implemented as follows:
public Object staticFieldBase(Class c) {
Field[] fields = c.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
if (Modifier.isStatic(fields[i].getModifiers())) {
return staticFieldBase(fields[i]);
}
}
return null;
}
[中]返回访问给定类中某个静态字段的基址。此方法的实现如下:
public Object staticFieldBase(Class c) {
Field[] fields = c.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
if (Modifier.isStatic(fields[i].getModifiers())) {
return staticFieldBase(fields[i]);
}
}
return null;
}
代码示例来源:origin: apache/ignite
/**
* Returns static field base.
*
* @param field Field.
* @return Static field base.
*/
public static Object staticFieldBase(Field field) {
return UNSAFE.staticFieldBase(field);
}
代码示例来源:origin: wildfly/wildfly
private static ObjectStreamField[] getDeclaredSerialPersistentFields(Class<?> clazz) {
final Field field;
try {
field = clazz.getDeclaredField("serialPersistentFields");
} catch (NoSuchFieldException e) {
return null;
}
if (field == null) {
return null;
}
final int requiredModifiers = Modifier.STATIC | Modifier.PRIVATE | Modifier.FINAL;
if ((field.getModifiers() & requiredModifiers) != requiredModifiers) {
return null;
}
try {
return (ObjectStreamField[]) unsafe.getObject(unsafe.staticFieldBase(field), unsafe.staticFieldOffset(field));
} catch (ClassCastException e) {
return null;
}
}
代码示例来源:origin: com.google.protobuf/protobuf-java
@Override
public Object getStaticObject(Field field) {
return getObject(unsafe.staticFieldBase(field), unsafe.staticFieldOffset(field));
}
}
代码示例来源:origin: org.apache.ignite/ignite-core
/**
* Returns static field base.
*
* @param field Field.
* @return Static field base.
*/
public static Object staticFieldBase(Field field) {
return UNSAFE.staticFieldBase(field);
}
代码示例来源:origin: com.tomitribe.tribestream/tribestream-metrics-bytecode
public static Object staticFieldBase(final Field f) {
return UNSAFE.staticFieldBase(f);
}
代码示例来源:origin: com.tomitribe.tribestream/tribestream-metrics-bytecode
@Deprecated
public static Object staticFieldBase(final Class<?> aClass) {
return UNSAFE.staticFieldBase(aClass);
}
代码示例来源:origin: jboss-remoting/jboss-marshalling
private static ObjectStreamField[] getDeclaredSerialPersistentFields(Class<?> clazz) {
final Field field;
try {
field = clazz.getDeclaredField("serialPersistentFields");
} catch (NoSuchFieldException e) {
return null;
}
if (field == null) {
return null;
}
final int requiredModifiers = Modifier.STATIC | Modifier.PRIVATE | Modifier.FINAL;
if ((field.getModifiers() & requiredModifiers) != requiredModifiers) {
return null;
}
try {
return (ObjectStreamField[]) unsafe.getObject(unsafe.staticFieldBase(field), unsafe.staticFieldOffset(field));
} catch (ClassCastException e) {
return null;
}
}
代码示例来源:origin: net.openhft/chronicle-core
private static long maxDirectMemory0() {
try {
Class<?> clz;
if (IS_JAVA_9_PLUS) {
clz = Class.forName("jdk.internal.misc.VM");
} else {
clz = Class.forName("sun.misc.VM");
}
final Field f = clz.getDeclaredField("directMemory");
long offset = UNSAFE.staticFieldOffset(f);
Object base = UNSAFE.staticFieldBase(f);
return UNSAFE.getLong(base, offset);
} catch (Exception e) {
// ignore
}
System.err.println(Jvm.class.getName() + ": Unable to determine max direct memory");
return 0L;
}
代码示例来源:origin: OpenHFT/Chronicle-Core
private static long maxDirectMemory0() {
try {
Class<?> clz;
if (IS_JAVA_9_PLUS) {
clz = Class.forName("jdk.internal.misc.VM");
} else {
clz = Class.forName("sun.misc.VM");
}
final Field f = clz.getDeclaredField("directMemory");
long offset = UNSAFE.staticFieldOffset(f);
Object base = UNSAFE.staticFieldBase(f);
return UNSAFE.getLong(base, offset);
} catch (Exception e) {
// ignore
}
System.err.println(Jvm.class.getName() + ": Unable to determine max direct memory");
return 0L;
}
代码示例来源:origin: org.jboss.marshalling/jboss-marshalling
private static ObjectStreamField[] getDeclaredSerialPersistentFields(Class<?> clazz) {
final Field field;
try {
field = clazz.getDeclaredField("serialPersistentFields");
} catch (NoSuchFieldException e) {
return null;
}
if (field == null) {
return null;
}
final int requiredModifiers = Modifier.STATIC | Modifier.PRIVATE | Modifier.FINAL;
if ((field.getModifiers() & requiredModifiers) != requiredModifiers) {
return null;
}
try {
return (ObjectStreamField[]) unsafe.getObject(unsafe.staticFieldBase(field), unsafe.staticFieldOffset(field));
} catch (ClassCastException e) {
return null;
}
}
代码示例来源:origin: io.fastjson/boon
protected UnsafeField ( Field field ) {
super(field);
if ( super.isStatic() ) {
base = unsafe.staticFieldBase( field );
offset = unsafe.staticFieldOffset( field );
} else {
offset = unsafe.objectFieldOffset( field );
base = null;
}
this.field = field;
}
代码示例来源:origin: org.jboss.marshalling/jboss-marshalling-osgi
private static ObjectStreamField[] getDeclaredSerialPersistentFields(Class<?> clazz) {
final Field field;
try {
field = clazz.getDeclaredField("serialPersistentFields");
} catch (NoSuchFieldException e) {
return null;
}
if (field == null) {
return null;
}
final int requiredModifiers = Modifier.STATIC | Modifier.PRIVATE | Modifier.FINAL;
if ((field.getModifiers() & requiredModifiers) != requiredModifiers) {
return null;
}
try {
return (ObjectStreamField[]) unsafe.getObject(unsafe.staticFieldBase(field), unsafe.staticFieldOffset(field));
} catch (ClassCastException e) {
return null;
}
}
代码示例来源:origin: boonproject/boon
protected UnsafeField ( Field field ) {
super(field);
if ( super.isStatic() ) {
base = unsafe.staticFieldBase( field );
offset = unsafe.staticFieldOffset( field );
} else {
offset = unsafe.objectFieldOffset( field );
base = null;
}
this.field = field;
}
代码示例来源:origin: boonproject/boon
protected UnsafeField ( Field field ) {
super(field);
if ( super.isStatic() ) {
base = unsafe.staticFieldBase( field );
offset = unsafe.staticFieldOffset( field );
} else {
offset = unsafe.objectFieldOffset( field );
base = null;
}
this.field = field;
}
代码示例来源:origin: io.advantageous.boon/boon-reflekt
protected UnsafeField ( Field field ) {
super(field);
if ( super.isStatic() ) {
base = unsafe.staticFieldBase( field );
offset = unsafe.staticFieldOffset( field );
} else {
offset = unsafe.objectFieldOffset( field );
base = null;
}
this.field = field;
}
代码示例来源:origin: com.github.advantageous/boon-reflekt
protected UnsafeField ( Field field ) {
super(field);
if ( super.isStatic() ) {
base = unsafe.staticFieldBase( field );
offset = unsafe.staticFieldOffset( field );
} else {
offset = unsafe.objectFieldOffset( field );
base = null;
}
this.field = field;
}
代码示例来源:origin: peter-lawrey/Performance-Examples
public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException, IOException, InstantiationException {
System.out.println("Starting");
Object o = UNSAFE.staticFieldBase(Unsafe4Demo.class);
Field _x = Unsafe4Demo.class.getDeclaredField("x");
_x.setAccessible(true);
long xOff = UNSAFE.staticFieldOffset(_x);
UNSAFE.compareAndSwapInt(o, xOff, 5, 42);
System.out.println("x=" + UNSAFE.getInt(o, xOff) + " x is now " + _x.get(null));
/*
MyEnum mt = (MyEnum) UNSAFE.allocateInstance(MyEnum.class);
Field name = Enum.class.getDeclaredField("name");
name.setAccessible(true);
name.set(mt, "A");
System.out.println("Done " + mt);
System.out.println(mt.equals(MyEnum.A));
*/
}
代码示例来源:origin: com.github.os72/protobuf-java-shaded-351
@Override
public Object getStaticObject(Field field) {
return getObject(unsafe.staticFieldBase(field), unsafe.staticFieldOffset(field));
}
}
代码示例来源:origin: org.apache.ratis/ratis-proto-shaded
@Override
public Object getStaticObject(Field field) {
return getObject(unsafe.staticFieldBase(field), unsafe.staticFieldOffset(field));
}
}
代码示例来源:origin: io.bitsensor/proto
@Override
public Object getStaticObject(Field field) {
return getObject(unsafe.staticFieldBase(field), unsafe.staticFieldOffset(field));
}
}
内容来源于网络,如有侵权,请联系作者删除!