Skip to content

Commit

Permalink
Synchronize the String dedupe cache.
Browse files Browse the repository at this point in the history
Without explicit synchronization, an internal iterator can be corrupted and result in an infinite loop on WeakHashMap#get calls.

Fixes #3171: Hang with threads and Hash[]= on unfrozen keys.
nirvdrum committed Jul 23, 2015
1 parent e6a26e3 commit e88911e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -177,6 +177,7 @@
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
@@ -5105,7 +5106,7 @@ public void addToObjectSpace(boolean useObjectSpace, IRubyObject object) {
*
* Access must be synchronized.
*/
private WeakHashMap<RubyString, WeakReference<RubyString>> dedupMap = new WeakHashMap<RubyString, WeakReference<RubyString>>();
private Map<RubyString, WeakReference<RubyString>> dedupMap = Collections.synchronizedMap(new WeakHashMap<RubyString, WeakReference<RubyString>>());

private static final AtomicInteger RUNTIME_NUMBER = new AtomicInteger(0);
private final int runtimeNumber = RUNTIME_NUMBER.getAndIncrement();

0 comments on commit e88911e

Please sign in to comment.