android-java.lang.Object中的“ shadow $ _klass_”和“ shadow $ _monitor_”变量是什么?

在最新的Android更新(SDK 21)中,似乎已经向shadow$_monitor_添加了两个新变量:

private transient Class<?> shadow$_klass_;
private transient int shadow$_monitor_;

我注意到hashCode()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指针。 我在这里找到了有关Brooks指针的一些信息:

这个想法是堆上的每个对象都有一个附加的引用字段。 该字段指向对象本身,或者指向对象复制到新位置后立即指向该新位置。 这将使我们能够与mutator线程同时撤离对象

原文:

They are indeed connected to GC. They seem to have been added in order to support Brooks pointers. I found some information on Brooks pointers 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

See especially these two commits:

libcore: a7c69f785f7d1b07b7da22cfb9150c584ee143f4

art: 9d04a20bde1b1855cefc64aebc1a44e253b1a13b