JPDA: Fix Save Value to File for large debugger strings - #9635
matthiasblaesing wants to merge 4 commits into
Conversation
While debugging with JPDA NetBeans makes strings directly available as long as they are shorter than 100000 characters. Longer strings are truncated to that length. The full string can be made available on demand and saved to a file. Before this change the truncated string was used as a key in a WeakHashmap that held the data required to fetch the full string. This causes problems: - it was observed that the contents of the WeakHashMap was collected to early, rendering the full string inaccessible - the truncated string might not be unique, which might result in crosstalk between strings displays This change switch from providing truncated strings to consumers to providing as StringInfo object that not only holds the shorted string, but also all the info that is required to fetch the full string. The caching that was done based on the shorted string was switched to StringReferences as keys, which are documented to be equal when the backing VM and string are identical.
| return this.shortendString; | ||
| } | ||
|
|
||
| public int getShortendLength() { |
There was a problem hiding this comment.
I think this is a typo. It is "shortened" according to my dictionary.
| meth public int getShortendLength() | ||
| meth public java.io.Reader getContent() | ||
| meth public java.lang.String getFullString() | ||
| meth public java.lang.String getShortendString() |
There was a problem hiding this comment.
- must these methods appear in API changes list?
- I guess they have to as they are accessed from a different package
- and this package is listed as API
- can only one of the methods be added?
- seems to me
getShortenedString().length()would be sufficient
- seems to me
| String str = ShortenedStrings.getStringWithLengthControl(sr); | ||
| Object stringData = ShortenedStrings.getStringWithLengthControl(sr); | ||
| String str; | ||
| if(stringData instanceof ShortenedStrings.StringInfo si) { |
| string = shortedString; | ||
| StringInfo si = new StringInfo(sr, shortedString, stringLength, sa, backingEncoding, isLittleEndian); | ||
| synchronized (stringCache) { | ||
| stringCache.put(sr, si); |
There was a problem hiding this comment.
- multiple threads can be running this
stringCache.put(sr, si)code - for the same
sr, but differentsi- that was also the old behavior, it is not changed by this PR
- I guess that doesn't matter
- at most the
StringInfois constructed multiple times in parallel
- at most the
- Remove "..." suffix from shortened string in StringInfo (it is a display artifact). This removes requirement for arbitrary length corrections (the three dots are not part of the real data) - fix wrong spelling shortend -> shortened - Remove unnessary method getShortendLength - fix missing space in if-block - simplify BigStringCustomEditor and remove dead code
|
@jtulach thanks for the review.
|
|
|
- don't swallow the InterruptedException in ShortenedStrings#getStringWithLengthControl move handling to callers that already handle the other potential fetch failures
|
For the question compatible change or not: This change is not compatible. I removed For the retrieval logic/sychronization pattern: I agree that a different approach might be better, but a quick rewrite did not yield more readable code so I opted to go minimal. The InterruptedException id now not swallowed anymore but passed to the caller. The callers already have to deal with retrieval problems and thus are the correct place to handle this. (Pushed as update) |
|
@entlicher would you mind having a look at this? According to the class javadoc you were the original author of |
While debugging with JPDA NetBeans makes strings directly available as long as they are shorter than 100000 characters. Longer strings are truncated to that length.
The full string can be made available on demand and saved to a file.
Before this change the truncated string was used as a key in a WeakHashmap that held the data required to fetch the full string. This causes problems:
it was observed that the contents of the WeakHashMap was collected to early, rendering the full string inaccessible
the truncated string might not be unique, which might result in crosstalk between strings displays
This change switch from providing truncated strings to consumers to providing as StringInfo object that not only holds the shorted string, but also all the info that is required to fetch the full string.
The caching that was done based on the shorted string was switched to StringReferences as keys, which are documented to be equal when the backing VM and string are identical.