Skip to content

Commit e2ae50d

Browse files
committed
8355569: Some nsk/jdi tests can glean the "main" thread by using the ClassPrepareEvent for the debuggee main class
Reviewed-by: sspitsyn, amenkov
1 parent e36756b commit e2ae50d

38 files changed

+150
-90
lines changed

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/Accessible/isPackagePrivate/accipp001.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -108,8 +108,7 @@ private int runThis (String argv[], PrintStream out) {
108108
logHandler = new Log(out, argsHandler);
109109
Binder binder = new Binder(argsHandler, logHandler);
110110

111-
debugee = Debugee.prepareDebugee(argsHandler, logHandler,
112-
debugeeName + (argsHandler.verbose() ? " -vbs" : ""));
111+
debugee = Debugee.prepareDebugee(argsHandler, logHandler, debugeeName);
113112

114113
// ReferenceType classes[] = debugee.classes();
115114
// for (int i=0; i<classes.length; i++) {

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequest/hashCode/hashcode001.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -118,7 +118,7 @@ private static void execTest() {
118118
switch (i) {
119119

120120
case 0:
121-
ThreadReference thread = debuggee.threadByNameOrThrow(methodName);
121+
ThreadReference thread = debuggee.mainThread();
122122

123123
display(".....setting up StepRequest");
124124
eventRequest = eventRequestManager.createStepRequest

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/_bounds_/requests001.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -95,7 +95,7 @@ private void execTest() {
9595

9696
EventRequest request;
9797
EventRequestManager evm = debugee.getEventRequestManager();
98-
ThreadReference thread = debugee.threadByName("main");
98+
ThreadReference thread = debugee.mainThread();
9999

100100
display("");
101101
display("...calling createStepRequest(null, StepRequest.STEP_LINE, "

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/EventSet/suspendPolicy/suspendpolicy001.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,15 @@ private void testRun()
250250

251251
ClassPrepareEvent event = (ClassPrepareEvent) eventIterator.next();
252252
debuggeeClass = event.referenceType();
253+
debuggee.setMainThread(event.thread());
253254

254255
if (!debuggeeClass.name().equals(debuggeeName))
255256
throw new JDITestRuntimeException("** Unexpected ClassName for ClassPrepareEvent **");
256257
log2(" received: ClassPrepareEvent for debuggeeClass");
257258

258259
log2("......setting up ClassPrepareEvent for breakpointForCommunication");
259260

260-
ThreadReference mainThread = debuggee.threadByNameOrThrow("main");
261+
ThreadReference mainThread = debuggee.mainThread();
261262
setupBreakpointForCommunication(debuggeeClass);
262263

263264
//------------------------------------------------------ testing section

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/Method/isObsolete/isobsolete003.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -139,7 +139,7 @@ public static int run(String argv[], PrintStream out) {
139139

140140
private static void execTest() {
141141

142-
ThreadReference mainThread = debuggee.threadByName("main");
142+
ThreadReference mainThread = debuggee.mainThread();
143143

144144
// Set first breakpoint to have isobsolete003b class loaded.
145145
BreakpointRequest bpRequest = debuggee.makeBreakpoint(debuggeeClass, "main", brkpMainLineNumber);
@@ -456,6 +456,7 @@ private static void waitForDebuggeeClassPrepared () {
456456
ClassPrepareEvent event = (ClassPrepareEvent) waitForEvent(cpRequest);
457457
cpRequest.disable();
458458

459+
debuggee.setMainThread(event.thread());
459460
debuggeeClass = event.referenceType();
460461
if (!debuggeeClass.name().equals(debuggeeName))
461462
throw new Failure("Unexpected class name for ClassPrepareEvent : " + debuggeeClass.name());

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/MethodEntryEvent/method/method002.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -113,6 +113,9 @@ public static int run(final String args[], final PrintStream out) {
113113

114114
pipe = debuggee.createIOPipe();
115115

116+
ClassPrepareEvent cpEvent = debuggee.waitForClassPrepare(DEBUGGEE_NAME);
117+
debuggee.setMainThread(cpEvent.thread());
118+
116119
// resume debuggee
117120
log.display("Resuming debuggee");
118121
debuggee.resume();
@@ -135,7 +138,7 @@ public static int run(final String args[], final PrintStream out) {
135138
checkedClass = debuggee.classByName(CHILD_NAME);
136139

137140
log.display("Getting <main> thread in debuggee");
138-
checkedThread = debuggee.threadByName("main");
141+
checkedThread = debuggee.mainThread();
139142
if (checkedThread == null) {
140143
throw new Failure("TEST BUG: unable to find reference to main thread");
141144
}

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/MethodExitEvent/method/method001.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -110,6 +110,9 @@ public static int run(final String args[], final PrintStream out) {
110110

111111
pipe = debuggee.createIOPipe();
112112

113+
ClassPrepareEvent cpEvent = debuggee.waitForClassPrepare(DEBUGGEE_NAME);
114+
debuggee.setMainThread(cpEvent.thread());
115+
113116
// resume debuggee
114117
log.display("Resuming debuggee");
115118
debuggee.resume();
@@ -131,7 +134,7 @@ public static int run(final String args[], final PrintStream out) {
131134
checkedClass = debuggee.classByName(DEBUGGEE_NAME);
132135

133136
log.display("Getting reference to thread <main>");
134-
checkedThread = debuggee.threadByName("main");
137+
checkedThread = debuggee.mainThread();
135138
if (checkedThread == null) {
136139
throw new Failure("TEST BUG: unable to find reference to main thread");
137140
}

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/MethodExitEvent/method/method002.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -114,6 +114,9 @@ public static int run(final String args[], final PrintStream out) {
114114

115115
pipe = debuggee.createIOPipe();
116116

117+
ClassPrepareEvent cpEvent = debuggee.waitForClassPrepare(DEBUGGEE_NAME);
118+
debuggee.setMainThread(cpEvent.thread());
119+
117120
// resume debuggee
118121
log.display("Resuming debuggee");
119122
debuggee.resume();
@@ -136,7 +139,7 @@ public static int run(final String args[], final PrintStream out) {
136139
checkedClass = debuggee.classByName(CHILD_NAME);
137140

138141
log.display("Getting reference to thread <main>");
139-
checkedThread = debuggee.threadByName("main");
142+
checkedThread = debuggee.mainThread();
140143
if (checkedThread == null) {
141144
throw new Failure("TEST BUG: unable to find reference to main thread");
142145
}

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/ObjectReference/entryCount/entrycount002.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -153,7 +153,7 @@ private int runThis(String argv[], PrintStream out) {
153153
//--------------------------------------------------------- mutable common methods
154154

155155
private void execTest() {
156-
ThreadReference mainThread = debuggee.threadByName("main");
156+
ThreadReference mainThread = debuggee.mainThread();
157157

158158
BreakpointRequest bpRequest = debuggee.makeBreakpoint(debuggeeClass,
159159
"methodForCommunication",
@@ -293,6 +293,8 @@ private ReferenceType waitForDebuggeeClassPrepared () {
293293
ClassPrepareEvent event = (ClassPrepareEvent) waitForEvent(cpRequest);
294294
cpRequest.disable();
295295

296+
debuggee.setMainThread(event.thread()); // Needed so debuggee.mainThread() will work
297+
296298
if (!event.referenceType().name().equals(debuggeeName)) {
297299
throw new Failure("Unexpected class name for ClassPrepareEvent : " + debuggeeClass.name());
298300
}

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/ObjectReference/owningThread/owningthread002.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -153,7 +153,7 @@ private int runThis(String argv[], PrintStream out) {
153153
//--------------------------------------------------------- mutable common methods
154154

155155
private void execTest() {
156-
ThreadReference mainThread = debuggee.threadByName("main");
156+
ThreadReference mainThread = debuggee.mainThread();
157157

158158
BreakpointRequest bpRequest = debuggee.makeBreakpoint(debuggeeClass,
159159
"methodForCommunication",
@@ -307,6 +307,8 @@ private ReferenceType waitForDebuggeeClassPrepared () {
307307
ClassPrepareEvent event = (ClassPrepareEvent) waitForEvent(cpRequest);
308308
cpRequest.disable();
309309

310+
debuggee.setMainThread(event.thread()); // Needed so debuggee.mainThread() will work
311+
310312
if (!event.referenceType().name().equals(debuggeeName)) {
311313
throw new Failure("Unexpected class name for ClassPrepareEvent : " + debuggeeClass.name());
312314
}

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/StackFrame/_bounds_/bounds002.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -95,7 +95,7 @@ public static int run(String argv[], PrintStream out) {
9595
private void execTest() {
9696

9797
debugee.VM().suspend();
98-
ThreadReference thread = debugee.threadByName("main");
98+
ThreadReference thread = debugee.mainThread();
9999
StackFrame stackFrame = null;
100100
boolean isTopmostFrame = false;
101101
try {

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/StepRequest/_bounds_/filters001.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -87,7 +87,7 @@ private void execTest() {
8787
display("");
8888
display(">>>creating StepRequest");
8989

90-
ThreadReference thread = debugee.threadByName("main");
90+
ThreadReference thread = debugee.mainThread();
9191
EventRequestManager evm = debugee.getEventRequestManager();
9292
StepRequest request = evm.createStepRequest(thread, StepRequest.STEP_LINE,
9393
StepRequest.STEP_INTO);

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/_bounds_/bounds001.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -97,7 +97,7 @@ public static int run(String argv[], PrintStream out) {
9797
private void execTest() {
9898

9999
debugee.VM().suspend();
100-
ThreadReference thread = debugee.threadByName("main");
100+
ThreadReference thread = debugee.mainThread();
101101

102102
display("\nTEST BEGINS");
103103
display("===========");

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/VirtualMachine/redefineClasses/redefineclasses004.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -158,7 +158,7 @@ private void execTest() throws TestBug {
158158
display("\nTEST BEGINS");
159159
display("===========");
160160

161-
ThreadReference thrd = debugee.threadByName("main");
161+
ThreadReference thrd = debugee.mainThread();
162162
if (thrd.isSuspended()) {
163163
display("\n\n<<<Debugee is suspended>>>");
164164
display("--------------------------");
@@ -167,7 +167,6 @@ private void execTest() throws TestBug {
167167

168168
debugee.resume();
169169

170-
thrd = debugee.threadByName("main");
171170
if (!thrd.isSuspended()) {
172171
display("\n\n<<<Debugee is not suspended>>>");
173172
display("------------------------------");

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/VirtualMachine/redefineClasses/redefineclasses005.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -155,7 +155,7 @@ private void execTest() throws TestBug {
155155
display("\nTEST BEGINS");
156156
display("===========");
157157

158-
ThreadReference thrd = debugee.threadByName("main");
158+
ThreadReference thrd = debugee.mainThread();
159159
if (thrd.isSuspended()) {
160160
statDebugee = "Debugee is suspended";
161161
display("\n\n<<<" + statDebugee + ">>>");
@@ -165,7 +165,6 @@ private void execTest() throws TestBug {
165165

166166
debugee.resume();
167167

168-
thrd = debugee.threadByName("main");
169168
if (!thrd.isSuspended()) {
170169
statDebugee = "Debugee is not suspended";
171170
display("\n\n<<<" + statDebugee + ">>>");

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/VirtualMachine/redefineClasses/redefineclasses006.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -157,7 +157,7 @@ private void execTest() throws TestBug {
157157
display("\nTEST BEGINS");
158158
display("===========");
159159

160-
ThreadReference thrd = debugee.threadByName("main");
160+
ThreadReference thrd = debugee.mainThread();
161161
if (thrd.isSuspended()) {
162162
statDebugee = "Debugee is suspended";
163163
display("\n\n<<<" + statDebugee + ">>>");
@@ -167,7 +167,6 @@ private void execTest() throws TestBug {
167167

168168
debugee.resume();
169169

170-
thrd = debugee.threadByName("main");
171170
if (!thrd.isSuspended()) {
172171
statDebugee = "Debugee is not suspended";
173172
display("\n\n<<<" + statDebugee + ">>>");

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/VirtualMachine/redefineClasses/redefineclasses007.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -164,7 +164,7 @@ private void execTest() throws TestBug {
164164
display("\nTEST BEGINS");
165165
display("===========");
166166

167-
ThreadReference thrd = debugee.threadByName("main");
167+
ThreadReference thrd = debugee.mainThread();
168168
if (thrd.isSuspended()) {
169169
statDebugee = "Debugee is suspended";
170170
display("\n\n<<<" + statDebugee + ">>>");
@@ -174,7 +174,6 @@ private void execTest() throws TestBug {
174174

175175
debugee.resume();
176176

177-
thrd = debugee.threadByName("main");
178177
if (!thrd.isSuspended()) {
179178
statDebugee = "Debugee is not suspended";
180179
display("\n\n<<<" + statDebugee + ">>>");

‎test/hotspot/jtreg/vmTestbase/nsk/jdi/VirtualMachine/redefineClasses/redefineclasses008.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -162,7 +162,7 @@ private void execTest() throws TestBug {
162162
display("\nTEST BEGINS");
163163
display("===========");
164164

165-
ThreadReference thrd = debugee.threadByName("main");
165+
ThreadReference thrd = debugee.mainThread();
166166
if (thrd.isSuspended()) {
167167
statDebugee = "Debugee is suspended";
168168
display("\n\n<<<" + statDebugee + ">>>");
@@ -172,7 +172,6 @@ private void execTest() throws TestBug {
172172

173173
debugee.resume();
174174

175-
thrd = debugee.threadByName("main");
176175
if (!thrd.isSuspended()) {
177176
statDebugee = "Debugee is not suspended";
178177
display("\n\n<<<" + statDebugee + ">>>");

0 commit comments

Comments
 (0)