Black hole thermodynamics and Hamilton–Jacobi counterterm