Skip to content

Commit 75504a3

Browse files
committed
8356588: Some nsk/jdi tests can fetch ThreadReference from static field in the debuggee: part 3
Reviewed-by: amenkov, sspitsyn
1 parent 7c8e273 commit 75504a3

File tree

35 files changed

+156
-353
lines changed

35 files changed

+156
-353
lines changed

test/hotspot/jtreg/vmTestbase/nsk/jdi/BreakpointEvent/_itself_/breakpoint001.java

Lines changed: 2 additions & 11 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
@@ -117,16 +117,7 @@ public static int run(final String args[], final PrintStream out) {
117117
checkedClass = (ReferenceType) classes.get(0);
118118

119119
log.display("Getting reference to main thread");
120-
Iterator threadIterator = vm.allThreads().iterator();
121-
while (threadIterator.hasNext()) {
122-
ThreadReference curThread = (ThreadReference) threadIterator.next();
123-
if (curThread.name().equals("main")) {
124-
checkedThread = curThread;
125-
}
126-
}
127-
if (checkedThread == null) {
128-
throw new Failure("TEST BUG: unable to find reference to main thread");
129-
}
120+
checkedThread = debuggee.threadByFieldNameOrThrow(checkedClass, "mainThread", "main");
130121

131122
log.display("Getting reference to method <foo>");
132123
List allMethods = checkedClass.methodsByName("foo");

test/hotspot/jtreg/vmTestbase/nsk/jdi/BreakpointEvent/_itself_/breakpoint001a.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2018, 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
@@ -40,11 +40,13 @@ public class breakpoint001a {
4040
static final String COMMAND_GO = "go";
4141
static final String COMMAND_DONE = "done";
4242

43-
public static final int breakpointLineNumber = 86;
43+
public static final int breakpointLineNumber = 90;
4444

4545
static private int counter = 0;
4646
static private final int LIMIT = 10;
4747

48+
static Thread mainThread = null;
49+
4850
public static void main(String args[]) {
4951
breakpoint001a _breakpoint001a = new breakpoint001a();
5052
System.exit(JCK_STATUS_BASE + _breakpoint001a.run(args));
@@ -54,6 +56,8 @@ int run( String args[]) {
5456
ArgumentHandler argHandler = new ArgumentHandler(args);
5557
IOPipe pipe = argHandler.createDebugeeIOPipe();
5658

59+
mainThread = Thread.currentThread();
60+
5761
// notify debugger about ready to execute
5862
pipe.println(COMMAND_READY);
5963

test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createStepRequest/crstepreq001.java

Lines changed: 18 additions & 28 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
@@ -23,6 +23,7 @@
2323

2424
package nsk.jdi.EventRequestManager.createStepRequest;
2525

26+
import com.sun.jdi.ReferenceType;
2627
import com.sun.jdi.ThreadReference;
2728
import com.sun.jdi.VirtualMachine;
2829
import com.sun.jdi.request.StepRequest;
@@ -104,35 +105,24 @@ private int runIt(String args[], PrintStream out) {
104105
return quitDebuggee(FAILED);
105106
}
106107

108+
ReferenceType debuggeeClass = debuggee.classByName(DEBUGGEE_CLASS);
109+
thR = debuggee.threadByFieldNameOrThrow(debuggeeClass, "debuggeeThread", DEBUGGEE_THRD);
110+
log.display("\nCreating StepRequest for the debuggee's thread \""
111+
+ thR.name() + "\"");
107112
try {
108-
threads = vm.allThreads();
109-
} catch (Exception e) {
110-
log.complain("TEST FAILURE: allThreads: " + e);
113+
StepRequest sReq =
114+
erManager.createStepRequest(thR, RESTRICTIONS[0][0],RESTRICTIONS[0][1]);
115+
sReq.enable();
116+
enabledStepRequests.add(sReq);
117+
} catch (DuplicateRequestException e) {
118+
log.complain("TEST FAILURE: createStepRequest: caught " + e);
119+
return quitDebuggee(FAILED);
120+
} catch (ObjectCollectedException e) {
121+
log.complain("TEST FAILURE: createStepRequest: caught " + e);
122+
return quitDebuggee(FAILED);
123+
} catch (VMMismatchException e) {
124+
log.complain("TEST FAILURE: createStepRequest: caught " + e);
111125
return quitDebuggee(FAILED);
112-
}
113-
Iterator iter = threads.iterator();
114-
while (iter.hasNext()) {
115-
thR = (ThreadReference) iter.next();
116-
if (thR.name().equals(DEBUGGEE_THRD)) {
117-
log.display("\nCreating StepRequest for the debuggee's thread \""
118-
+ thR.name() + "\"");
119-
try {
120-
StepRequest sReq = erManager.createStepRequest(thR,
121-
RESTRICTIONS[0][0],RESTRICTIONS[0][1]);
122-
sReq.enable();
123-
enabledStepRequests.add(sReq);
124-
} catch (DuplicateRequestException e) {
125-
log.complain("TEST FAILURE: createStepRequest: caught " + e);
126-
return quitDebuggee(FAILED);
127-
} catch (ObjectCollectedException e) {
128-
log.complain("TEST FAILURE: createStepRequest: caught " + e);
129-
return quitDebuggee(FAILED);
130-
} catch (VMMismatchException e) {
131-
log.complain("TEST FAILURE: createStepRequest: caught " + e);
132-
return quitDebuggee(FAILED);
133-
}
134-
break;
135-
}
136126
}
137127

138128
// Check that createStepRequest() throws DuplicateRequestException

test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createStepRequest/crstepreq001t.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2018, 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
@@ -32,12 +32,14 @@
3232
* This is a debuggee class.
3333
*/
3434
public class crstepreq001t {
35+
static Thread debuggeeThread = null;
36+
3537
public static void main(String args[]) {
3638
ArgumentHandler argHandler = new ArgumentHandler(args);
3739
IOPipe pipe = argHandler.createDebugeeIOPipe();
38-
Thread thr = Thread.currentThread();
40+
debuggeeThread = Thread.currentThread();
3941

40-
thr.setName(crstepreq001.DEBUGGEE_THRD);
42+
debuggeeThread.setName(crstepreq001.DEBUGGEE_THRD);
4143
pipe.println(crstepreq001.COMMAND_READY);
4244
String cmd = pipe.readln();
4345
if (!cmd.equals(crstepreq001.COMMAND_QUIT)) {

test/hotspot/jtreg/vmTestbase/nsk/jdi/ExceptionEvent/catchLocation/location001.java

Lines changed: 2 additions & 11 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
@@ -165,16 +165,7 @@ public static int run(final String args[], final PrintStream out) {
165165

166166
// get mirror of main thread in debuggee
167167
log.display("Getting reference to main thread");
168-
Iterator threadIterator = vm.allThreads().iterator();
169-
while (threadIterator.hasNext()) {
170-
ThreadReference curThread = (ThreadReference) threadIterator.next();
171-
if (curThread.name().equals("main")) {
172-
checkedThread = curThread;
173-
}
174-
}
175-
if (checkedThread == null) {
176-
throw new Failure("TEST BUG: unable to find reference to main thread");
177-
}
168+
checkedThread = debuggee.threadByFieldNameOrThrow(checkedClass, "mainThread", "main");
178169

179170
// create ExceptionRequest for all throwable classes (initially disabled)
180171
log.display("Creating ExceptionRequest");

test/hotspot/jtreg/vmTestbase/nsk/jdi/ExceptionEvent/catchLocation/location001a.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2018, 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
@@ -47,16 +47,16 @@ class location001a {
4747
static final String COMMAND_ERROR = "error";
4848

4949
// line numbers where checked exceptions thrown (for user exceptions only)
50-
public static final int userExceptionLocation = 98;
51-
public static final int userErrorLocation = 105;
52-
public static final int userThrowableLocation = 112;
50+
public static final int userExceptionLocation = 101;
51+
public static final int userErrorLocation = 108;
52+
public static final int userThrowableLocation = 115;
5353

5454
// line numbers where checked exceptions caught. Numbers were changed due to 4740123
55-
public static final int userExceptionCatchLocation = 99;
56-
public static final int userErrorCatchLocation = 106;
57-
public static final int userThrowableCatchLocation = 113;
58-
public static final int javaExceptionCatchLocation = 120;
59-
public static final int javaErrorCatchLocation = 127;
55+
public static final int userExceptionCatchLocation = 102;
56+
public static final int userErrorCatchLocation = 109;
57+
public static final int userThrowableCatchLocation = 116;
58+
public static final int javaExceptionCatchLocation = 123;
59+
public static final int javaErrorCatchLocation = 130;
6060

6161
// flags marked all actually thrown exceptions
6262
private static boolean userExceptionThrown = false;
@@ -65,9 +65,12 @@ class location001a {
6565
private static boolean javaExceptionThrown = false;
6666
private static boolean javaErrorThrown = false;
6767

68+
static Thread mainThread = null;
69+
6870
// run debuggee from command line
6971
public static void main(String args[]) throws Throwable {
7072
location001a _location001a = new location001a();
73+
mainThread = Thread.currentThread();
7174
System.exit(JCK_STATUS_BASE + _location001a.runIt(args, System.err));
7275
}
7376

test/hotspot/jtreg/vmTestbase/nsk/jdi/ExceptionEvent/exception/exception001.java

Lines changed: 2 additions & 11 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
@@ -165,16 +165,7 @@ public static int run(final String args[], final PrintStream out) {
165165

166166
// get mirror of main thread in debuggee
167167
log.display("Getting reference to main thread");
168-
Iterator threadIterator = vm.allThreads().iterator();
169-
while (threadIterator.hasNext()) {
170-
ThreadReference curThread = (ThreadReference) threadIterator.next();
171-
if (curThread.name().equals("main")) {
172-
checkedThread = curThread;
173-
}
174-
}
175-
if (checkedThread == null) {
176-
throw new Failure("TEST BUG: unable to find reference to main thread");
177-
}
168+
checkedThread = debuggee.threadByFieldNameOrThrow(checkedClass, "mainThread", "main");
178169

179170
// create ExceptionRequest for all throwable classes (initially disabled)
180171
log.display("Creating ExceptionRequest");

test/hotspot/jtreg/vmTestbase/nsk/jdi/ExceptionEvent/exception/exception001a.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2018, 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
@@ -65,9 +65,12 @@ class exception001a {
6565
private static boolean javaExceptionThrown = false;
6666
private static boolean javaErrorThrown = false;
6767

68+
static Thread mainThread = null;
69+
6870
// run debuggee from command line
6971
public static void main(String args[]) throws Throwable {
7072
exception001a _exception001a = new exception001a();
73+
mainThread = Thread.currentThread();
7174
System.exit(JCK_STATUS_BASE + _exception001a.runIt(args, System.err));
7275
}
7376

test/hotspot/jtreg/vmTestbase/nsk/jdi/LocalVariable/isVisible/isvisible001.java

Lines changed: 3 additions & 17 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
@@ -173,6 +173,7 @@ private int runThis (String argv[], PrintStream out) {
173173
}
174174

175175
VirtualMachine vm = debuggee.VM();
176+
ReferenceType debuggeeClass = debuggee.classByName(debuggeeName);
176177

177178
//------------------------------------------------------ testing section
178179
log1(" TESTING BEGINS");
@@ -204,8 +205,6 @@ private int runThis (String argv[], PrintStream out) {
204205

205206
BreakpointRequest breakpRequest1 = null;
206207

207-
List allThreads = null;
208-
ListIterator listIterator = null;
209208
List classes = null;
210209

211210
StackFrame stackFrame = null;
@@ -230,7 +229,6 @@ private int runThis (String argv[], PrintStream out) {
230229

231230
log2("getting ThreadReference object");
232231
try {
233-
allThreads = vm.allThreads();
234232
classes = vm.classesByName(testedClassName);
235233
testedclass = (ReferenceType) classes.get(0);
236234
} catch ( Exception e) {
@@ -239,19 +237,7 @@ private int runThis (String argv[], PrintStream out) {
239237
break label0;
240238
}
241239

242-
listIterator = allThreads.listIterator();
243-
for (;;) {
244-
try {
245-
thread2 = (ThreadReference) listIterator.next();
246-
if (thread2.name().equals(threadName))
247-
break ;
248-
} catch ( NoSuchElementException e ) {
249-
log3("ERROR: NoSuchElementException for listIterator.next()");
250-
log3("ERROR: NO THREAD2 ?????????!!!!!!!");
251-
expresult = returnCode1;
252-
break label0;
253-
}
254-
}
240+
thread2 = debuggee.threadByFieldNameOrThrow(debuggeeClass, "thread2", threadName);
255241

256242
log2("setting up breakpoint");
257243

test/hotspot/jtreg/vmTestbase/nsk/jdi/LocalVariable/isVisible/isvisible001a.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2021, 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
@@ -58,6 +58,9 @@ private static void logErr(String message) {
5858
}
5959

6060
//====================================================== test program
61+
62+
static Thread thread2 = null;
63+
6164
//---------------------------------------------------- main method
6265

6366
public static void main (String argv[]) {
@@ -93,7 +96,7 @@ public static void main (String argv[]) {
9396
//------------------------------------------------------ section tested
9497

9598
case 0:
96-
Thread thread2 =
99+
thread2 =
97100
JDIThreadFactory.newThread(new Threadisvisible001a("Thread2"));
98101
log1(" thread2 is created");
99102

test/hotspot/jtreg/vmTestbase/nsk/jdi/Locatable/location/location004.java

Lines changed: 3 additions & 17 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
@@ -162,6 +162,7 @@ private int runThis (String argv[], PrintStream out) {
162162
}
163163

164164
VirtualMachine vm = debuggee.VM();
165+
ReferenceType debuggeeClass = debuggee.classByName(debuggeeName);
165166

166167
//------------------------------------------------------ testing section
167168
log1(" TESTING BEGINS");
@@ -195,8 +196,6 @@ private int runThis (String argv[], PrintStream out) {
195196

196197
BreakpointRequest breakpRequest1 = null;
197198

198-
List allThreads = null;
199-
ListIterator listIterator = null;
200199
List classes = null;
201200

202201
StackFrame stackFrame = null;
@@ -206,7 +205,6 @@ private int runThis (String argv[], PrintStream out) {
206205

207206
log2("getting ThreadReference object");
208207
try {
209-
allThreads = vm.allThreads();
210208
classes = vm.classesByName(testedClassName);
211209
testedclass = (ReferenceType) classes.get(0);
212210
} catch ( Exception e) {
@@ -215,19 +213,7 @@ private int runThis (String argv[], PrintStream out) {
215213
break label0;
216214
}
217215

218-
listIterator = allThreads.listIterator();
219-
for (;;) {
220-
try {
221-
thread2 = (ThreadReference) listIterator.next();
222-
if (thread2.name().equals(threadName))
223-
break ;
224-
} catch ( NoSuchElementException e ) {
225-
log3("ERROR: NoSuchElementException for listIterator.next()");
226-
log3("ERROR: NO THREAD2 ?????????!!!!!!!");
227-
expresult = returnCode1;
228-
break label0;
229-
}
230-
}
216+
thread2 = debuggee.threadByFieldNameOrThrow(debuggeeClass, "thread2", threadName);
231217

232218
log2("setting up breakpoint");
233219

0 commit comments

Comments
 (0)