17.4 Stable Translations

Although 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 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 to permit stable programs to be constructed. To facilitate such stable translations, you can use the D inline mechanism.

The DTrace procfs.d library provides the curlwpsinfo and curpsinfo variables, which were previously described as stable translations. For example, the curpsinfo and curlwpsinfo variables are actually inline and declared as follows:

inline psinfo_t *curpsinfo = xlate <psinfo_t *> (curthread);
#pragma D attributes Stable/Stable/Common curpsinfo

inline lwpsinfo_t *curlwpsinfo = xlate <lwpsinfo_t *> (curthread);
#pragma D attributes Stable/Stable/Common curlwpsinfo

The curpsinfo and curlwpsinfo are both defined as inline translations from the curthread variable, a pointer to the kernel's Private data structure representing a process descriptor, to the Stable lwpsinfo_t type. The D compiler processes this library file and caches the inline declarations, making curpsinfo and curlwpsinfo appear as any other D variable. The #pragma statement following the declaration is used to explicitly reset the attributes of the curpsinfo and curlwpsinfo identifiers to Stable/Stable/Common, masking the reference to curthread in the inline expressions.