9. (16 points) Given the function
$$
f(x)=\ln (a x+b)+x^{2} \quad (a \neq 0).
$$
(1) If the tangent line to the curve $y=f(x)$ at the point $(1, f(1))$ is $y=x$, find the values of $a$ and $b$;
(2) If $f(x) \leqslant x^{2}+x$ always holds, find the maximum value of $a b$.
(1) From the problem, we know that $f^{\prime}(x)=\frac{a}{a x+b}+2 x$.
According to the problem, we have
$$
\begin{array}{l}
\left\{\begin{array}{l}
f^{\prime}(1)=\frac{a}{a+b}+2=1, \\
f(1)=\ln (a+b)+1=1
\end{array}\right. \\
\Rightarrow a=-1, b=2 .
\end{array}
$$
(2) Let $g(x)=f(x)-\left(x^{2}+x\right)$. Then
$$
g(x)=\ln (a x+b)-x, g(x) \leqslant 0 \text {. }
$$

When $a\ln \left(a x_{0}+b\right)-\left(-\frac{b}{a}\right)=1>0,
\end{array}
$$

this contradicts $g(x) \leqslant 0$.
Thus, when $a>0$,
$$
g^{\prime}(x)=\frac{-a\left(x-\frac{a-b}{a}\right)}{a x+b}(a x+b>0) \text {. }
$$

When $-\frac{b}{a}<x<\frac{a-b}{a}$, $g^{\prime}(x)>0$;
When $x>\frac{a-b}{a}$, $g^{\prime}(x)<0$;
When $a>\sqrt{\mathrm{e}}$, $h^{\prime}(a)<0$.
Therefore, the maximum value of $h(a)$ is
$$
h(\sqrt{\mathrm{e}})=\mathrm{e}-\frac{\mathrm{e}}{2}=\frac{\mathrm{e}}{2} \text {. }
$$

In summary, when $a=\sqrt{\mathrm{e}}, b=\frac{\sqrt{\mathrm{e}}}{2}$, $a b$ achieves its maximum value of $\frac{\mathrm{e}}{2}$.