The mass is changed by injecting molecules at the left. The density (mass/volume) increases as the volume is held fixed by the piston and the temperature is fixed.