RFR: 8292679: Simplify thread creation in gtest and port 2 tests to new way
Thomas Stuefe
stuefe at openjdk.org
Tue Aug 23 14:58:26 UTC 2022
On Tue, 23 Aug 2022 14:20:17 GMT, Johan Sjölén <duke at openjdk.org> wrote:
> > One simpler, more pragmatic way would be for the thread group to give each started thread a numeric id. Most of the cases I can think of would be happy with that, using the id inside the thread function to control behavior.
>
> That might be sufficient. Looking through the test cases, they're either too complex for me to take the time to understand for this discussion, or would work OK with this kind of id. I'm thinking for N threads, each threads gets a unique id in the range `[0,N)`, are we thinking the same thing?
Yes. At least the tests I wrote, I usually had like one thread that would do A, the rest B, or half/half would do A or B. That can be just controlled via the running id. Beside its nice for debugging.
>
> > The ability to start with the number of threads dictated at runtime, depending on runtime conditions. The ability to reuse the same TTG in different subtests with different thread numbers without template bloat.
>
> There's probably no significant gain to be had in re-using the same TTG in different subtests, but I see the value of minimizing compilation times by not having several monomorphizations depending on N.
Not sure what you meant with the first half of the sentence. But one example for controlling num threads at runtime, I think now that we add more and more functionality to gtest, we may need a way to control the test width. Reduce the number of concurrent threads. There are folks running these tests as part of their build on tiny make machines. Of course, canonical test results would still require a certain number of concurrent tests.
>
> > Actually, the same argument goes for F. This design still requires us to use the same thread function for all threads. For cases where you want to have multiple different thread functions, you would still end up with some sort of switch inside the thread function. If F were a runtime thing, you could do something like this:
>
> That's flexible, but not easier to understand. Suddenly, several `doit()` and several `join()`s are viable, it makes the semantics of TTG way more complicated. Simple tests are preferable, I'd keep `F` if it meant that we _can't_ add two different functors to a TTG.
Ok, I agree.
>
> We _can_ get rid of `F`, as so:
>
> ```
> #include <functional>
>
> template<typename S>
> class BasicTestThread : public JavaTestThread {
> std::function<void(Thread*, S)> f;
> };
> ```
>
> Unfortunately `std::function` is a no go, but it does show an enticing way forward. It would be useful in many places of Hotspot, probably having a real build time improvement.
>
> Here's my plan:
>
> * Move N out from being a template parameter to a constructor argument
> * Try to remove S and instead use a numeric id, see how the two solutions differ for these test cases. If it's nice, I'll also remove S (and therefore also state generator, for example).
> * I'm keeping F, no changes there.
Sounds good. Thanks for considering this.
Cheers, Thomas
-------------
PR: https://git.openjdk.org/jdk/pull/9962
More information about the hotspot-dev
mailing list