Phase locking and ac amplification of small Josephson junctions