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

Chris Plummer cjplummer at openjdk.org
Tue Apr 29 17:46:27 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.

test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequest/hashCode/hashcode001.java line 121:

> 119: 
> 120:                 case 0:
> 121:                        ThreadReference thread = debuggee.mainThread();

This is one that was missed during the PR for #24867.

test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createStepRequest/crstepreq003.java line 81:

> 79: 
> 80:     static final int lineForBreakInThread    = 141;
> 81:     static final int[] checkedLines = { 142, 142, 182 };

Note the added lines in the debuggee below.

test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createStepRequest/crstepreq004.java line 82:

> 80:     static final int lineForBreakInThread = 149;
> 81:     static final int[] checkedLines = { 163, 163, 196 };
> 82:     static final int[] checkedLinesAlt = { 164, 164, 196 };

Note the added lines in the debuggee below.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24935#discussion_r2064317075
PR Review Comment: https://git.openjdk.org/jdk/pull/24935#discussion_r2064320290
PR Review Comment: https://git.openjdk.org/jdk/pull/24935#discussion_r2064321920


More information about the serviceability-dev mailing list