-
Notifications
You must be signed in to change notification settings - Fork 4
Add a model for String.intern #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This contains a model for String.intern diffblue/java-models-library#22
59a2dbf
to
2568c36
Compare
src/main/java/java/lang/String.java
Outdated
static String[] cproverInternPool = null; | ||
|
||
/** | ||
* Number of element stored in the pool for {@code String.intern} pool. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ Typo: element -> elements
src/main/java/java/lang/String.java
Outdated
|
||
/** | ||
* Number of element stored in the pool for {@code String.intern} pool. | ||
* This can be smaller than {@code cproverInternPoll.length} which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ Typo: Poll -> Pool
src/main/java/java/lang/String.java
Outdated
CProver.notModelled(); | ||
return CProver.nondetWithoutNullForNotModelled(); | ||
// Initialize the pool if needed | ||
if(cproverInternPool == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ Space before (
🍵
src/main/java/java/lang/String.java
Outdated
return this; | ||
} | ||
// Look for an entry in the pool equal to `this` | ||
for(int i = 0; i < cproverInternPoolSize; ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍵 (here and in the line just below)
if(cproverInternPool == null) { | ||
int capacity = CProver.nondetInt(); | ||
CProver.assume(capacity > 0); | ||
cproverInternPool = new String[capacity]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Why isn't this done as part of the initialisation of cproverInternPool
? Is this to avoid the static initialiser getting too complicated? If that is not a problem, it would be good to avoid this null check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I don't expect String.intern to be used often so I prefer to keep the String static initialiser simple (which is called all the time). The null check is relatively simple compared to the loop that follows, it could also be replaced by if(cproverInternPoolSize == 0)
but I don't know if there is an advantage in that.
This uses a custom static pool of strings, through which we look-up strings on which intern was already called.
2568c36
to
1d879b0
Compare
This contains a model for String.intern diffblue/java-models-library#22
This uses a custom static pool of strings, through which we look-up
strings on which intern was already called.
This is in preparation for removing the special handling of
intern
in JBMC: diffblue/cbmc#4554