This is a port of #8470 and #8501 from the former mainline branch, in support of #2600 and #9076. No additional changes other than checking out the code have been implemented in this PR. A subsequent PR will incorporate this code.