Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.lang.ref.WeakReference;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -73,7 +74,7 @@
*/
public final class ShortenedStrings {

private static final Map<String, StringInfo> infoStrings = new WeakHashMap<String, StringInfo>();
private static final Map<String, StringInfo> infoStrings = new HashMap<String, StringInfo>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason to switch from WeakHashMap to HashMap. The full strings are looked up by a string and if the key goes out of scope it makes sense, that the referenced value is removed.

private static final Map<StringReference, StringValueInfo> stringsCache = new WeakHashMap<StringReference, StringValueInfo>();
private static final Set<StringReference> retrievingStrings = new HashSet<StringReference>();
private static final Map<VirtualMachine, Boolean> isLittleEndianCache =
Expand All @@ -85,7 +86,6 @@ public final class ShortenedStrings {

@Override
public void sessionRemoved(Session session) {
// Clean up. WeakHashMap does not clean up if not touched. :-(
int n = DebuggerManager.getDebuggerManager().getSessions().length;
if (n == 0) {
synchronized (infoStrings) {
Expand All @@ -107,8 +107,19 @@ public void sessionRemoved(Session session) {
private ShortenedStrings() {}

public static StringInfo getShortenedInfo(String s) {
if (s == null) {
return null;
}
synchronized (infoStrings) {
return infoStrings.get(s);
StringInfo info = infoStrings.get(s);
if (info != null) {
return info;
}
// Variable.getValue() wraps Strings in quotes: "content..."
if (s.length() >= 2 && s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"') {
return infoStrings.get(s.substring(1, s.length() - 1));
}
return null;
}
}

Expand Down