[cs/java] add function to save and restore temp var counters