On Mon, 12 May 2025 19:35:05 GMT, Chris Plummer <cjplum...@openjdk.org> wrote:
> This batch of changes mostly concerns the remaining uses of threadByName() > and converting them to use threadByFieldNameOrThrow() or the new > threadByFieldName(). The latter is used if the caller has code to handle a > null result. The former is when an exception is needed to get the test to > terminate properly. I did fix a few long standing cases where threadyByName() > was being called and not checking the result. These call sites now use > threadByFieldNameOrThrow() instead of threadByFieldName(). > > Note there is a minor semantic change in doing this. threadByName() has some > extra code to check that the named thread is only found once, and will throw > an exception if it is. I think this was just some extra checking that was > being done during test development, and is not needed for proper test > execution. I've run all the tests without this check and they still pass. I > plan on removing this check at some point. > > Tested by running all tier5 svc tests, which includes the nsk/jdi tests. Also > ran tier1 and ran locally. test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassType/invokeMethod/invokemethod009.java line 120: > 118: thrRef = debuggee.threadByFieldName(rType, "testThread", > DEBUGGEE_THRNAME); > 119: if (thrRef == null) { > 120: log.complain("TEST FAILURE: Method Debugee.threadByName() > returned null for debuggee thread " The message mentions old `threadByName` test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassType/invokeMethod/invokemethod010.java line 119: > 117: thrRef = debuggee.threadByFieldName(rType, "testThread", > DEBUGGEE_THRNAME); > 118: if (thrRef == null) { > 119: log.complain("TEST FAILURE: method Debugee.threadByName() > returned null for debuggee thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassType/invokeMethod/invokemethod014.java line 123: > 121: debuggee.threadByFieldName(rType, "testThread", > DEBUGGEE_THRNAME); > 122: if (thrRef == null) { > 123: log.complain("TEST FAILURE: method Debugee.threadByName() > returned null for debuggee thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassType/newInstance/newinstance009.java line 104: > 102: ThreadReference thrRef = debuggee.threadByFieldName(rType, > "thread", DEBUGGEE_THRNAME); > 103: if (thrRef == null) { > 104: log.complain("TEST FAILURE: method Debugee.threadByName() > returned null for debuggee thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ObjectReference/invokeMethod/invokemethod003.java line 148: > 146: thrRef = debuggee.threadByFieldName(rType[0], "testThread", > DEBUGGEE_THRNAME); > 147: if (thrRef == null) { > 148: log.complain("TEST FAILURE: Method Debugee.threadByName() > returned null for debuggee thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ObjectReference/invokeMethod/invokemethod004.java line 118: > 116: thrRef = debuggee.threadByFieldName(debuggeeClass, "testThread", > DEBUGGEE_THRNAME); > 117: if (thrRef == null) { > 118: log.complain("TEST FAILURE: method Debugee.threadByName() > returned null for debuggee thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ObjectReference/invokeMethod/invokemethod005.java line 122: > 120: thrRef = debuggee.threadByFieldName(rType[0], "testThread", > DEBUGGEE_THRNAME); > 121: if (thrRef == null) { > 122: log.complain("TEST FAILURE: Method Debugee.threadByName() > returned null for debuggee thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ObjectReference/invokeMethod/invokemethod006.java line 120: > 118: thrRef = debuggee.threadByFieldName(rType[0], "testThread", > DEBUGGEE_THRNAME); > 119: if (thrRef == null) { > 120: log.complain("TEST FAILURE: Method Debugee.threadByName() > returned null for debuggee thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ObjectReference/invokeMethod/invokemethod007.java line 136: > 134: thrRef = debuggee.threadByFieldName(rType[0], "testThread", > DEBUGGEE_THRNAME); > 135: if (thrRef == null) { > 136: log.complain("TEST FAILURE: Method Debugee.threadByName() > returned null for debuggee thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ObjectReference/invokeMethod/invokemethod008.java line 131: > 129: thrRef = debuggee.threadByFieldName(rType[0], "testThread", > DEBUGGEE_THRNAME); > 130: if (thrRef == null) { > 131: log.complain("TEST FAILURE: Method Debugee.threadByName() > returned null for debuggee thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ObjectReference/invokeMethod/invokemethod009.java line 131: > 129: thrRef = debuggee.threadByFieldName(rType[0], "testThread", > DEBUGGEE_THRNAME); > 130: if (thrRef == null) { > 131: log.complain("TEST FAILURE: Method Debugee.threadByName() > returned null for debuggee thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ObjectReference/invokeMethod/invokemethod014.java line 155: > 153: debuggee.threadByFieldName(rType[0], "testThread", > DEBUGGEE_THRNAME); > 154: if (thrRef == null) { > 155: log.complain("TEST FAILURE: method Debugee.threadByName() > returned null for debuggee thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ObjectReference/setValue/setvalue002.java line 116: > 114: thrRef = debuggee.threadByFieldName(debuggeeClass, "testThread", > DEBUGGEE_THRNAME); > 115: if (thrRef == null) { > 116: log.complain("TEST FAILURE: Method Debugee.threadByName() > returned null for debuggee's thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ObjectReference/setValue/setvalue003.java line 149: > 147: thrRef = debuggee.threadByFieldName(debuggeeClass, "testThread", > DEBUGGEE_THRNAME); > 148: if (thrRef == null) { > 149: log.complain("TEST FAILURE: Method Debugee.threadByName() > returned null for debuggee's thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ObjectReference/setValue/setvalue004.java line 129: > 127: thrRef = debuggee.threadByFieldName(debuggeeClass, "testThread", > DEBUGGEE_THRNAME); > 128: if (thrRef == null) { > 129: log.complain("TEST FAILURE: Method Debugee.threadByName() > returned null for debuggee's thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ObjectReference/setValue/setvalue005.java line 116: > 114: thrRef = debuggee.threadByFieldName(debuggeeClass, "testThread", > DEBUGGEE_THRNAME); > 115: if (thrRef == null) { > 116: log.complain("TEST FAILURE: Method Debugee.threadByName() > returned null for debuggee thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ReferenceType/sourceName/sourcename004.java line 145: > 143: debuggee.threadByFieldName(rType, "testThread", > DEBUGGEE_THRNAME); > 144: if (thrRef == null) { > 145: throw new Failure("method Debugee.threadByName() > returned null for debuggee thread " Need to update error message or use threadByFieldNameOrThrow and drop this check test/hotspot/jtreg/vmTestbase/nsk/jdi/ReferenceType/sourceNames/sourcenames002.java line 145: > 143: debuggee.threadByFieldName(rType, "testThread", > DEBUGGEE_THRNAME); > 144: if (thrRef == null) { > 145: throw new Failure("method Debugee.threadByName() > returned null for debuggee thread " Need to update error message or use threadByFieldNameOrThrow and drop this check test/hotspot/jtreg/vmTestbase/nsk/jdi/StackFrame/getValue/getvalue003.java line 115: > 113: ThreadReference auxThread = > 114: debuggee.threadByFieldNameOrThrow(rType, "auxThr", > 115: DEBUGGEE_AUX_THREAD_NAME); I suppose this should to moved inside try block so `quitDebuggee` is called on error test/hotspot/jtreg/vmTestbase/nsk/jdi/StackFrame/getValues/getvalues003.java line 121: > 119: ThreadReference auxThread = > 120: debuggee.threadByFieldNameOrThrow(rType, "auxThr", > 121: DEBUGGEE_AUX_THREAD_NAME); Need to move inside `try` block test/hotspot/jtreg/vmTestbase/nsk/jdi/StackFrame/setValue/setvalue005/setvalue005.java line 165: > 163: debuggee.threadByFieldName(rType, "mainThread", > DEBUGGEE_THRDNAME); > 164: if (thrRef == null) { > 165: log.complain("TEST FAILURE: method Debugee.threadByName() > returned null for debuggee thread " Need to update error message BTW `debuggee.classByName` also can throw exceptions, need to catch and call `quitDebuggee()` (this applicable to other changes in the fix when `debuggee.classByName` is called outside of try block) test/hotspot/jtreg/vmTestbase/nsk/jdi/StackFrame/setValue/setvalue006/setvalue006.java line 181: > 179: > 180: // debuggee main class > 181: ReferenceType rType = debuggee.classByName(DEBUGGEE_CLASS); can throw an exception test/hotspot/jtreg/vmTestbase/nsk/jdi/StackFrame/setValue/setvalue006/setvalue006.java line 186: > 184: debuggee.threadByFieldName(rType, "mainThread", > DEBUGGEE_THRDNAME); > 185: if (thrRef == null) { > 186: log.complain("TEST FAILURE: method Debugee.threadByName() > returned null for debuggee thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/interrupt/interrupt001.java line 208: > 206: > 207: private void executeCase(int testCase, String threadName2) { > 208: ReferenceType debuggeeClass = debuggee.classByName(debuggeeName); need to catch exceptions and call `debuggee.quit()` test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/ownedMonitors/ownedmonitors002.java line 95: > 93: > 94: // debuggee main class > 95: ReferenceType rType = debuggee.classByName(DEBUGGEE_CLASS); catch exception and call `quitDebuggee()` test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/ownedMonitors/ownedmonitors002.java line 100: > 98: debuggee.threadByFieldName(rType, "testThread", > DEBUGGEE_THRNAME); > 99: if (thrRef == null) { > 100: log.complain("TEST FAILURE: method Debugee.threadByName() > returned null for debuggee thread " Need to update the message test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/popFrames/popframes006.java line 110: > 108: > 109: // debuggee main class > 110: ReferenceType rType = debuggee.classByName(DEBUGGEE_CLASS); Need to catch exceptions test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/popFrames/popframes006.java line 115: > 113: debuggee.threadByFieldName(rType, "testThread", > DEBUGGEE_THRNAME); > 114: if (thrRef == null) { > 115: log.complain("TEST FAILURE: method Debugee.threadByName() > returned null for debuggee thread " Need to update error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/popFrames/popframes007.java line 110: > 108: > 109: // debuggee main class > 110: ReferenceType rType = debuggee.classByName(DEBUGGEE_CLASS); Also can throw an exception test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/popFrames/popframes007.java line 115: > 113: debuggee.threadByFieldName(rType, "mainThread", > DEBUGGEE_MAIN_THREAD_NAME); > 114: if (mainThread == null) { > 115: log.complain("TEST FAILURE: method Debugee.threadByName() > returned null for debuggee thread " error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/popFrames/popframes007.java line 124: > 122: debuggee.threadByFieldName(rType, "auxThr", > DEBUGGEE_AUX_THREAD_NAME); > 123: if (auxThread == null) { > 124: log.complain("TEST FAILURE: method Debugee.threadByName() > returned null for debuggee thread " error message test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop002.java line 119: > 117: > 118: // debuggee main class > 119: mainClass = debuggee.classByName(DEBUGGEE_CLASS); Maybe just move this into `try` and replace `debuggee.threadByFieldName` with `debuggee.threadByFieldNameOrThrow`? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087642353 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087645280 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087646349 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087648971 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087656414 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087657140 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087657694 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087658347 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087659210 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087659847 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087662171 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087663522 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087664932 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087677879 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087678551 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087678872 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087683417 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087684378 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087686629 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087688875 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087689600 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087694192 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087693950 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087697256 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087698746 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087698970 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087701217 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087701506 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087702115 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087702349 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087702545 PR Review Comment: https://git.openjdk.org/jdk/pull/25190#discussion_r2087705024