RFR: 8355773: Some nsk/jdi tests can fetch ThreadReference from static field in the debuggee
Chris Plummer
cjplummer at openjdk.org
Wed Apr 30 17:18:51 UTC 2025
On Mon, 28 Apr 2025 18:27:26 GMT, Chris Plummer <cjplummer at openjdk.org> wrote:
> In an effort go get rid of calls to Debugee.threadByName() or Debugee.threadByNameOrThrow(), I found that many tests store the thread being looked up in a static field of the debuggee. The test can fetch the ThreadReference from the static field instead of looking it up using APIs that rely on vm.allThreads().
>
> Most of the changes take advantage of the following common pattern:
>
> In the debugger:
>
> String threadName1 = "thread1";
> thread1 = debuggee.threadByNameOrThrow(threadName1);
>
> In the debuggee:
>
> static Thread thread1 = null;
> thread1 = JDIThreadFactory.newThread(new Thread1addcountfilter001a("thread1"));
>
> Note that the static field name for the Thread is the same as the thread name. Thus we can easily switch from looking up by thread name to instead looking up by static field name since they both use the same name.
Thank you for the review Alex and Serguei!
-------------
PR Comment: https://git.openjdk.org/jdk/pull/24935#issuecomment-2842705536
More information about the serviceability-dev
mailing list