RFR: 8225035: Thread stack size issue caused by large TLS size
Florian Weimer
fweimer at redhat.com
Wed Jun 12 14:32:02 UTC 2019
* Andrew Haley:
> On 6/12/19 2:42 PM, Thomas Stüfe wrote:
>> What is "static tls", __thread variables? As opposed to what, dynamic tls?
>> Would that be Posix TLS (pthread_setspecific and friends)? Are the
>> implementations different? If they are, which TLS does this patch address?
>
> Yes, this is __thread variables. It's nothing to do with
> pthread_key_create.
>
> The crucial distinction here is position-independent code. If an
> executable which uses __thread variables is compiled non-PIC a special
> (and fast) code sequence is generated. This means that the __thread
> variables are allocated at a simple offset from a base
> pointer. Dynamic TLS is more complicated, but much more flexible.
>
> So, there is "dynamic TLS" and "static TLS". Dynamic TLS is used by
> PIC-compiled libraries.
I would say that static TLS has a fixed offset from the thread pointer,
the same in all threads, while dynamic TLS can have varying offsets
depending on the thread because a more complicated lookup sequence is
used.
You can get fixed TLS offsets in DSOs, avoiding the indirection, by
using the initial-exec TLS model, either via __attribute__ ((tls_model
("initial-exec"))) in the source code, or via -ftls-model=initial-exec
on the command line.
On some targets, there is a static version of initial-exec TLS, where
the offset from the thread pointer is determined by the link editor and
put directly into the instruction stream. This only works for the main
program, of course, because there can be only one object in the entire
program which does that. In DSOs, you always have to load the offset of
a TLS variable at run time from a hidden global variable initialized by
the dynamic loader.
Thanks,
Florian
More information about the hotspot-runtime-dev
mailing list