Skip to content

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

Merged
merged 1 commit into from
Apr 30, 2019
Merged

Add a model for String.intern #22

merged 1 commit into from
Apr 30, 2019

Conversation

romainbrenguier
Copy link
Contributor

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

romainbrenguier added a commit to romainbrenguier/cbmc that referenced this pull request Apr 30, 2019
static String[] cproverInternPool = null;

/**
* Number of element stored in the pool for {@code String.intern} pool.

Choose a reason for hiding this comment

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

⛏️ Typo: element -> elements


/**
* Number of element stored in the pool for {@code String.intern} pool.
* This can be smaller than {@code cproverInternPoll.length} which

Choose a reason for hiding this comment

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

⛏️ Typo: Poll -> Pool

CProver.notModelled();
return CProver.nondetWithoutNullForNotModelled();
// Initialize the pool if needed
if(cproverInternPool == null) {

Choose a reason for hiding this comment

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

⛏️ Space before ( 🍵

return this;
}
// Look for an entry in the pool equal to `this`
for(int i = 0; i < cproverInternPoolSize; ++i) {

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];
Copy link

@antlechner antlechner Apr 30, 2019

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.

Copy link
Contributor Author

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.
@romainbrenguier romainbrenguier merged commit 14e140f into master Apr 30, 2019
@romainbrenguier romainbrenguier deleted the romain/intern branch April 30, 2019 20:13
romainbrenguier added a commit to romainbrenguier/cbmc that referenced this pull request Apr 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants