Statistical physics of self-replication