What determines what happens to a star in its final stage?