8141536: MethodType field offset calculation could be lazy

Reviewed-by: vlivanov
This commit is contained in:
Claes Redestad 2015-11-05 16:36:55 +01:00
parent 6f0997408a
commit 05e8afd0ef

View File

@ -1187,20 +1187,23 @@ s.writeObject(this.parameterArray());
// store them into the implementation-specific final fields.
checkRtype(rtype);
checkPtypes(ptypes);
UNSAFE.putObject(this, rtypeOffset, rtype);
UNSAFE.putObject(this, ptypesOffset, ptypes);
UNSAFE.putObject(this, OffsetHolder.rtypeOffset, rtype);
UNSAFE.putObject(this, OffsetHolder.ptypesOffset, ptypes);
}
// Support for resetting final fields while deserializing
private static final long rtypeOffset, ptypesOffset;
static {
try {
rtypeOffset = UNSAFE.objectFieldOffset
(MethodType.class.getDeclaredField("rtype"));
ptypesOffset = UNSAFE.objectFieldOffset
(MethodType.class.getDeclaredField("ptypes"));
} catch (Exception ex) {
throw new Error(ex);
// Support for resetting final fields while deserializing. Implement Holder
// pattern to make the rarely needed offset calculation lazy.
private static class OffsetHolder {
private static final long rtypeOffset, ptypesOffset;
static {
try {
rtypeOffset = UNSAFE.objectFieldOffset
(MethodType.class.getDeclaredField("rtype"));
ptypesOffset = UNSAFE.objectFieldOffset
(MethodType.class.getDeclaredField("ptypes"));
} catch (Exception ex) {
throw new Error(ex);
}
}
}