Preheat oven to 450°.
Remove and discard giblets and neck from chicken. Rinse chicken under cold water; pat dry. Trim excess fat. Starting at neck cavity, loosen skin from breast and drumsticks by inserting fingers and gently pushing fingers between the skin and meat. Place rosemary and crushed garlic beneath skin of breast and drumsticks. Lift wing tips up and over back; tuck under chicken. Place chicken, breast side up, on a broiler pan.
Cut a thin slice from end of each onion. Remove white papery skins from garlic heads (do not peel or separate cloves). Cut tops off garlic heads, leaving root end intact.
Insert meat thermometer into meaty part of thigh, making sure not to touch bone. Bake at 450° for 30 minutes. Brush onions and garlic heads with olive oil. Arrange onions and garlic heads around chicken. Reduce oven temperature to 350°; bake an additional 1 hour and 15 minutes or until meat thermometer registers 180°. Cover chicken loosely with foil; let stand 10 minutes. Discard skin from chicken. Squeeze roasted heads of garlic to extract pulp; serve as a spread on French bread, if desired.