Bacterial Heterochromatin Promotes Genome Defense and Optimal Resource Allocation