Stable Translations
While a translator provides the ability to convert information into a stable
data structure, it does not necessarily resolve all stability issues that can
arise in translating data. For example, if the input expression for an
xlate operation itself references Unstable data, the resulting D program is also
Unstable because program stability is always computed as the minimum stability of
the accumulated D program statements and expressions. Therefore, it is sometimes necessary
to define a specific stable input expression for a translator in order
to permit stable programs to be constructed. The D inline mechanism can
be used to facilitate such stable translations.
The DTrace procfs.d library provides the curlwpsinfo and curpsinfo variables described earlier
as stable translations. For example, the curlwpsinfo variable is actually an inline
declared as follows:
inline lwpsinfo_t *curlwpsinfo = xlate <lwpsinfo_t *> (curthread);
#pragma D attributes Stable/Stable/Common curlwpsinfo
The curlwpsinfo variable is defined as an inlined translation from the curthread
variable, a pointer to the kernel's Private data structure representing a thread,
to the Stable lwpsinfo_t type. The D compiler processes this library file
and caches the inline declaration, making curlwpsinfo appear as any other D
variable. The #pragma statement following the declaration is used to explicitly reset
the attributes of the curlwpsinfo identifier to Stable/Stable/Common, masking the reference to
curthread in the inlined expression. This combination of D features permits D
programmers to use curthread as the source of a translation in a
safe fashion that can be updated by Sun coincident to corresponding changes
in the Solaris implementation.