Skip to content

Check that dotty is reentrant #708

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 14 commits into from
Jul 6, 2015

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jul 1, 2015

Not quite done yet. But the basic checking is in place and a lot of false positives are eliminated. One true possible datarace involving Symbols.nextId was eliminated. partest afterwards runs OK in parallel on my machine.

@DarkDimius
Copy link
Contributor

Succeeds running 8 threads on my machine in 4 min 15 sec, sequential time was 7 min 20 sec.

@odersky odersky force-pushed the add/check-reentrant branch from 1e322e4 to f7ac8df Compare July 1, 2015 16:11
*/
class CtxLazy[T](expr: Context => T) {
private var myValue: T = _
private var forced = false
Copy link
Member

Choose a reason for hiding this comment

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

forced is never set to true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops.

@odersky odersky closed this Jul 2, 2015
@odersky odersky reopened this Jul 2, 2015
@DarkDimius
Copy link
Contributor

@odersky, is this PR ready for review?

@odersky
Copy link
Contributor Author

odersky commented Jul 3, 2015

Yes, please review.

On Fri, Jul 3, 2015 at 11:31 AM, Dmitry Petrashko [email protected]
wrote:

@odersky https://github.com/odersky, ready for review?


Reply to this email directly or view it on GitHub
#708 (comment).

Martin Odersky
EPFL

@@ -200,44 +203,21 @@ object Names {
private final val fillFactor = 0.7

/** Memory to store all names sequentially. */
@sharable // because it's only mutated in synchronized block of termName
Copy link
Contributor

Choose a reason for hiding this comment

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

Keeping track and maintaining such annotation could be a burden.
Instead of annotating explicitly, could we infer that private fields that are modified in synchronized(this) blocks are sharable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe at some point. But right now that's probably too much of a detour. Let's see first whether @sharable thing becomes a feature of general utility. Even now it serves a purpose: If we want to figure out data races, it's good to scrutinize members with @sharable annotations. For the others we can run -Ycheck:reentrant to rule them out (well, almost, modulo to the shortcomings mentioned in the comment).

@DarkDimius
Copy link
Contributor

Otherwise LGTM.

odersky added 14 commits July 6, 2015 17:46
New miniphase CheckRentrant verifies that compiled program is
without vars accessible through global roots if -Ycheck-reentrant
option is set.

Known shortcoming: Array elements are currently not considered as vars. This
is because in many programs arrays are used as an efficient container
for immutable fields.
Add @sharable annotation for classes and vals that are presumed
to be safely sharable between threads.

Also: Document CtxLazy.
Some global roots were pointing to shared mutable state but were never used.
Some globally accessible vars were never updated; should be vals.
The resident compiler is not supposed to be called from multiple
threads; mark as unshared to avoid spurious re-entrancy errors.
_nextId is used to set Symbol's id fields. That field is actually used for more
than priunting. In LambdaLift, it determines Symbol ordering when constructing
(tree-) sets of symbols.

Instead of a thread-unsafe global counter, we not use existing infrastructure
in ConetxtState.
Also, some code movements in Names to make it more obvious that mutating operations
are only called from synchronized blocks.
and use ctx.log for other output.
The thread-shared value NoDenotation has a validity with  run-id that got updated to the run-id
of the current thread. This caused a partest failure with a "demanding denotation outside its range"
error. We now treat NoDenotation specially in current, hoping this will avoid the condition.
Avoids the need of an @Unshared annotation.

For now I leave the annotation in, maybe it will be
useful later.
@odersky odersky force-pushed the add/check-reentrant branch from 90e4d4f to c7cc6d8 Compare July 6, 2015 16:24
@odersky
Copy link
Contributor Author

odersky commented Jul 6, 2015

Rebased to master.

odersky added a commit that referenced this pull request Jul 6, 2015
@odersky odersky merged commit b823132 into scala:master Jul 6, 2015
@allanrenucci allanrenucci deleted the add/check-reentrant branch December 14, 2017 16:57
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