What I Don’t (and Probably Won’t) Do

I mentioned earlier that the checker currently generates a lot of warnings, many of which seem unnecessary. When I change the checker to match Corky’s suggestion, that will reduce the number of warnings, but there could potentially still be a lot.

I do filter out multiple warnings that are exactly the same, and I also remove warnings that concern an individual method if the entire class is affected. For efficiency reasons, I also don’t match a thread name or group name against the same regular expression twice. What I don’t do, and I guess that deserves to be mentioned, is see if matching a thread name or group name against a particular regular expression R1 is unnecessary because the language accepted by R1 is already a subset of the language accepted by a second regular expression R2.

While determining whether the language of one regular expression is the subset of another is decidable, I don’t think this is necessary here. I don’t think Java’s builtin java.util.regex package can do minimization or compare regular expressions somehow. It’s theoretically interesting but practically probably rather irrelevant.

Thinking about this got me wondering whether creating one long regular expression for all the @OnlyRunBy thread names or group names is more efficient than what I do right now. If I have the annotation @OnlyRunBy(threadNames={"foo","bar"}), I could just match the thread name against the regular expression "(foo)|(bar)"… I have a feeling that’s better. I’m gonna try that now.

Update

No, using one single long regular expression apparently is not good. I ran the following method 1,000,000 times with the old system (preparing a list of regexes with a call per pattern, then checking it with another call) and the new system (statically preparing one long regex, then making one call to check it):

1
2
3
@OnlyRunBy(threadNames={"main","main2","main3","main4","main5"})
public static void allowed() {
}

The new system with the more complex regex was on average about five times slower.

Share

About Mathias

Software development engineer. Principal developer of DrJava. Recent Ph.D. graduate from the Department of Computer Science at Rice University.
This entry was posted in Concurrent Unit Testing. Bookmark the permalink.

Leave a Reply