在最新的 Android 更新 (SDK 21) 中,似乎向 java.lang.Object
添加了两个新变量:
private transient Class<?> shadow$_klass_;
private transient int shadow$_monitor_;
我注意到 shadow$_monitor_
在 hashCode()
中有简短的使用:
public int hashCode() {
int lockWord = shadow$_monitor_;
final int lockWordMask = 0xC0000000; // Top 2 bits.
final int lockWordStateHash = 0x80000000; // Top 2 bits are value 2 (kStateHash).
if ((lockWord & lockWordMask) == lockWordStateHash) {
return lockWord & ~lockWordMask;
}
return System.identityHashCode(this);
}
但除此之外没有对它们的引用。它们在某种程度上与 ART 中的 GC 有关吗?还是某种原生的东西?
最佳答案
它们确实连接到 GC。它们似乎是为了支持布鲁克斯的指针而添加的。我找到了一些关于 Brooks 指针的信息 here :
The idea is that each object on the heap has one additional reference field. This field either points to the object itself, or, as soon as the object gets copied to a new location, to that new location. This will enable us to evacuate objects concurrently with mutator threads
尤其是这两个提交:
关于java - java.lang.Object 中的 'shadow$_klass_' 和 'shadow$_monitor_' 变量是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26933888/