jf.setAccessible(true);
final Object val = jf.get(null);
final int fType = JvmType.SignatureToType(f.getSignature());
final int idx;
final VmStaticField sf = (VmStaticField) f;
final VmStatics statics;
if (sf.isShared()) {
idx = sf.getSharedStaticsIndex();
statics = sharedStatics;
} else {
idx = sf.getIsolatedStaticsIndex();
statics = isolatedStatics;
}
if (f.isPrimitive()) {
if (f.isWide()) {
final long lval;
switch (fType) {
case JvmType.LONG:
lval = ((Long) val).longValue();
break;
case JvmType.DOUBLE:
lval = Double.doubleToRawLongBits(((Double) val)
.doubleValue());
break;
default:
throw new IllegalArgumentException("Unknown wide type "
+ fType);
}
statics.setLong(idx, lval);
} else {
final int ival;
final Class<?> jfType = jf.getType();
if (jfType == boolean.class) {
ival = ((Boolean) val).booleanValue() ? 1 : 0;
} else if (jfType == byte.class) {
ival = ((Byte) val).byteValue();
} else if (jfType == char.class) {
ival = ((Character) val).charValue();
} else if (jfType == short.class) {
ival = ((Short) val).shortValue();
} else if (jfType == int.class) {
ival = ((Number) val).intValue();
} else if (jfType == float.class) {
ival = Float.floatToRawIntBits(((Float) val).floatValue());
} else {
throw new IllegalArgumentException("Unknown wide type "
+ fType);
}
statics.setInt(idx, ival);
}
} else if (f.isAddressType()) {
if (val == null) {
// Just do nothing
} else if (val instanceof UnboxedObject) {
final UnboxedObject uobj = (UnboxedObject) val;
statics.setAddress(idx, uobj);
} else if (val instanceof Label) {
final Label lbl = (Label) val;
statics.setAddress(idx, lbl);
} else {
throw new BuildException("Cannot handle magic type " + val.getClass().getName());
}
} else {
if (!Modifier.isAddressType(f.getSignature())) {
if (val != null) {
emitter.testForValidEmit(val, type.getName());
os.getObjectRef(val);
}
statics.setObject(idx, val);
}
}
}