RFR: 8256732: Zero: broken +ZeroTLAB exposes badly initialized memory

David Holmes dholmes at openjdk.java.net
Sun Nov 22 23:06:44 UTC 2020


On Fri, 20 Nov 2020 10:07:39 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

> Looks like memory is badly initialized when `-XX:+ZeroTLAB` is specified.
> 
> Manifests like this:
> 
> $ CONF=linux-x86_64-zero-fastdebug make exploded-test TEST=compiler/memoryinitialization/ZeroTLABTest.java
> 
> command: main -Xcomp -XX:+UseTLAB -XX:+ZeroTLAB compiler.memoryinitialization.ZeroTLABTest
> reason: User specified action: run main/othervm -Xcomp -XX:+UseTLAB -XX:+ZeroTLAB compiler.memoryinitialization.ZeroTLABTest
> Mode: othervm [/othervm specified]
> elapsed time (seconds): 0.098
> configuration:
> STDOUT:
> Error occurred during initialization of VM
> java.lang.NullPointerException
> at java.lang.System.getProperty(java.base/System.java:836)
> 
> The cause is simple: Zero calls this method:
> 
> if (UseTLAB) {
>   result = (oop) THREAD->tlab().allocate(obj_size);
> }
> 
> ...which says:
> 
> // Allocate size HeapWords. The memory is NOT initialized to zero.
> inline HeapWord* allocate(size_t size);
> So if we do `+ZeroTLAB`, then Zero skips zeroing the object body, and gets bad uninitialized memory for non-zeroed TLAB. Since `ZeroTLAB` is "false" by default, I believe just doing the object body initialization unconditionally is fine.

But isn't the memory returned by  ThreadLocalAllocBuffer::allocate implicitly already zeroed when ZeroTLAB is specified?

-------------

PR: https://git.openjdk.java.net/jdk/pull/1343


More information about the hotspot-runtime-dev mailing list