[Jamvm-general] The macro IS_OBJECT(ptr) is not reliable
Brought to you by:
rlougher
From: Lingyu Z. <lyn...@gm...> - 2017-07-13 14:57:14
|
Macro IS_OBJECT(ptr) is used during scaning C or java stack. However its implementation is not reliable. This macro only makes sure ptr is in range of (heapbase, heaplimit). When there's a long value happends to be in that range, jamvm will treat the value as a root reference and marks it. In my Linux configuration, the gc heap range is (0x7fffe7428000, 0x7fffe8428000), the following code verifies my point. public class TestOStack { public long a; public void setA(long i) { System.gc(); a = i; } public static void main(String args[]) { TestOStack o = new TestOStack(); o.setA(*0x7fffe7728000L*); } } During GC, 0x*7fffe7728000* will be marked. Though the false mark does not effect the correctness of the heap management, and only leads to only a 8-byte heap leak which is not permanent. I think IS_OBJECT should check the object's header, to ensure a alloc bit is set. Though the extra check is still not 100% reliable, it could reduce false mark posibility. |