mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-27 02:30:06 +00:00
8141536: MethodType field offset calculation could be lazy
Reviewed-by: vlivanov
This commit is contained in:
parent
6f0997408a
commit
05e8afd0ef
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user