RFR: 8355773: Some nsk/jdi tests can fetch ThreadReference from static field in the debuggee

Serguei Spitsyn sspitsyn at openjdk.org
Tue Apr 29 23:00:54 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.

Looks good.

-------------

Marked as reviewed by sspitsyn (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/24935#pullrequestreview-2805279197


More information about the serviceability-dev mailing list