Backported r9982 and r9984 from trunk.
Authored by: jplang 2012-07-15
Parent: [r9999]
Child: [r10001]