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

Reviewed-by: sspitsyn, amenkov
This commit is contained in:
Chris Plummer 2025-04-30 17:15:52 +00:00
parent 486acc06e0
commit 50145bb74a
31 changed files with 77 additions and 44 deletions

View File

@ -291,7 +291,7 @@ public class addcountfilter001 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest");
eventRequest1 = eventRManager.createStepRequest

View File

@ -289,7 +289,7 @@ public class disable001 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest");
eventRequest1 = eventRManager.createStepRequest

View File

@ -283,8 +283,7 @@ public class disable002 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest");
eventRequest1 = eventRManager.createStepRequest
(thread1, StepRequest.STEP_MIN, StepRequest.STEP_INTO);

View File

@ -283,7 +283,7 @@ public class enable001 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest");
eventRequest1 = eventRManager.createStepRequest

View File

@ -285,7 +285,7 @@ public class enable002 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest");
eventRequest1 = eventRManager.createStepRequest

View File

@ -289,7 +289,7 @@ public class getproperty001 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest");
eventRequest1 = eventRManager.createStepRequest

View File

@ -284,7 +284,7 @@ public class isenabled001 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest");
eventRequest1 = eventRManager.createStepRequest

View File

@ -289,7 +289,7 @@ public class putproperty001 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest");
eventRequest1 = eventRManager.createStepRequest

View File

@ -282,7 +282,7 @@ public class setenabled001 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest");
eventRequest1 = eventRManager.createStepRequest

View File

@ -286,7 +286,7 @@ public class setenabled002 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest");
eventRequest1 = eventRManager.createStepRequest

View File

@ -291,7 +291,7 @@ public class setsuspendpolicy001 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest");
eventRequest1 = eventRManager.createStepRequest

View File

@ -287,7 +287,7 @@ public class suspendpolicy001 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest");
eventRequest1 = eventRManager.createStepRequest

View File

@ -275,7 +275,7 @@ public class crstepreq002 extends JDIBase {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
thread = debuggee.threadByNameOrThrow(threadName);
thread = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName);
if (StepRequest.STEP_MIN > StepRequest.STEP_LINE) {
maxSize = StepRequest.STEP_MIN;

View File

@ -77,8 +77,8 @@ public class crstepreq003 {
//------------------------------------------------------ test specific fields
static final int lineForBreakInThread = 137;
static final int[] checkedLines = { 138, 138, 178 };
static final int lineForBreakInThread = 141;
static final int[] checkedLines = { 142, 142, 182 };
//------------------------------------------------------ mutable common methods
@ -247,7 +247,7 @@ public class crstepreq003 {
exitCode = FAILED;
}
ThreadReference thread = debuggee.threadByNameOrThrow(threadName);
ThreadReference thread = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName);
StepRequest stepRequest = setStepRequest( thread,
StepRequest.STEP_LINE,
stepDepth,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -55,6 +55,10 @@ public class crstepreq003a {
static Object waitnotifyObj = new Object();
static Thread thread0;
static Thread thread1;
static Thread thread2;
//------------------------------------------------------ mutable common method
public static void main (String argv[]) {
@ -72,21 +76,21 @@ public class crstepreq003a {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test case section
case 0:
Thread thread0 = JDIThreadFactory.newThread(new Thread0crstepreq003a("thread0"));
thread0 = JDIThreadFactory.newThread(new Thread0crstepreq003a("thread0"));
threadStart(thread0);
threadJoin (thread0, "0");
break;
case 1:
Thread thread1 = JDIThreadFactory.newThread(new Thread0crstepreq003a("thread1"));
thread1 = JDIThreadFactory.newThread(new Thread0crstepreq003a("thread1"));
threadStart(thread1);
threadJoin (thread1, "1");
break;
case 2:
Thread thread2 = JDIThreadFactory.newThread(new Thread0crstepreq003a("thread2"));
thread2 = JDIThreadFactory.newThread(new Thread0crstepreq003a("thread2"));
threadStart(thread2);
threadJoin (thread2, "2");

View File

@ -77,9 +77,9 @@ public class crstepreq004 {
//------------------------------------------------------ test specific fields
static final int lineForBreakInThread = 146;
static final int[] checkedLines = { 160, 160, 193 };
static final int[] checkedLinesAlt = { 161, 161, 193 };
static final int lineForBreakInThread = 149;
static final int[] checkedLines = { 163, 163, 196 };
static final int[] checkedLinesAlt = { 164, 164, 196 };
//------------------------------------------------------ mutable common methods
@ -248,7 +248,7 @@ public class crstepreq004 {
exitCode = FAILED;
}
ThreadReference thread = debuggee.threadByNameOrThrow(threadName);
ThreadReference thread = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName);
StepRequest stepRequest = setStepRequest( thread,
StepRequest.STEP_LINE,
stepDepth,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -58,6 +58,9 @@ public class crstepreq004a {
private static volatile boolean isFirstThreadReady = false;
private static volatile boolean isSecondThreadReady = false;
static Thread thread1;
static Thread thread2;
//------------------------------------------------------ mutable common method
public static void main (String argv[]) {
@ -95,8 +98,8 @@ public class crstepreq004a {
private static void runTestCase(int testCaseId) {
isFirstThreadReady = false;
isSecondThreadReady = false;
Thread thread1 = JDIThreadFactory.newThread(new Thread1crstepreq004a("thread1"));
Thread thread2 = JDIThreadFactory.newThread(new Thread2crstepreq004a("thread2"));
thread1 = JDIThreadFactory.newThread(new Thread1crstepreq004a("thread1"));
thread2 = JDIThreadFactory.newThread(new Thread2crstepreq004a("thread2"));
synchronized (lockObj) {
thread1.start();
while (!isFirstThreadReady) {

View File

@ -290,7 +290,7 @@ public class filter_rt002 extends JDIBase {
testClassReference =
(ReferenceType) vm.classesByName(testedClassName).get(0);
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
eventRequest1 = setting21StepRequest(thread1, testClassReference,
EventRequest.SUSPEND_NONE, property1);

View File

@ -282,7 +282,7 @@ public class filter_s002 extends JDIBase {
switch (i) {
case 0:
ThreadReference thread1 = debuggee.threadByNameOrThrow("thread1");
ThreadReference thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, "thread1");
eventRequest1 = setting23StepRequest(thread1, testedClassName1,
EventRequest.SUSPEND_NONE, property1);

View File

@ -281,7 +281,7 @@ public class depth001 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest with depth StepRequest.STEP_INTO");
eventRequest1 = setting24StepRequest(thread1, StepRequest.STEP_LINE,

View File

@ -281,7 +281,7 @@ public class depth002 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest with depth StepRequest.STEP_OVER");
eventRequest1 = setting24StepRequest(thread1, StepRequest.STEP_LINE,

View File

@ -281,7 +281,7 @@ public class depth003 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest with depth StepRequest.STEP_OUT");
eventRequest1 = setting24StepRequest(thread1, StepRequest.STEP_LINE,

View File

@ -281,7 +281,7 @@ public class size001 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest with size StepRequest.STEP_MIN");
eventRequest1 = setting24StepRequest(thread1, StepRequest.STEP_MIN,

View File

@ -281,7 +281,7 @@ public class size002 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest with size StepRequest.STEP_LINE");
eventRequest1 = setting24StepRequest(thread1, StepRequest.STEP_LINE,

View File

@ -283,7 +283,7 @@ public class thread001 extends JDIBase {
switch (i) {
case 0:
thread1 = debuggee.threadByNameOrThrow(threadName1);
thread1 = debuggee.threadByFieldNameOrThrow(debuggeeClass, threadName1);
log2("......setting up StepRequest with size StepRequest.STEP_MIN");
eventRequest1 = setting24StepRequest(thread1, StepRequest.STEP_MIN,

View File

@ -302,7 +302,7 @@ public class popframes001 extends JDIBase {
}
String thread2Name = "thread2";
ThreadReference thread2Ref = debuggee.threadByNameOrThrow(thread2Name);
ThreadReference thread2Ref = debuggee.threadByFieldNameOrThrow(debuggeeClass, thread2Name);
String poppedMethod = "poppedMethod";
@ -311,7 +311,7 @@ public class popframes001 extends JDIBase {
log2("......setting breakpoint in poppedMethod");
try {
breakpointRequest = settingBreakpoint(debuggee.threadByNameOrThrow(thread2Name),
breakpointRequest = settingBreakpoint(thread2Ref,
debuggeeClass,
poppedMethod, breakpointLine, "one");
} catch ( Exception e ) {

View File

@ -270,10 +270,10 @@ public class popframes002 extends JDIBase {
breakpointForCommunication();
String thread2Name = "thread2";
ThreadReference thread2Ref = debuggee.threadByNameOrThrow(thread2Name);
ThreadReference thread2Ref = debuggee.threadByFieldNameOrThrow(debuggeeClass, thread2Name);
String thread3Name = "thread3";
ThreadReference thread3Ref = debuggee.threadByNameOrThrow(thread3Name);
ThreadReference thread3Ref = debuggee.threadByFieldNameOrThrow(debuggeeClass, thread3Name);
String poppedMethod = "poppedMethod";
String breakpointLine = "breakpointLine";

View File

@ -283,10 +283,10 @@ public class popframes003 extends JDIBase {
String thread2Name = "thread2";
ThreadReference thread2Ref = debuggee.threadByNameOrThrow(thread2Name);
ThreadReference thread2Ref = debuggee.threadByFieldNameOrThrow(debuggeeClass, thread2Name);
String thread3Name = "thread3";
ThreadReference thread3Ref = debuggee.threadByNameOrThrow(thread3Name);
ThreadReference thread3Ref = debuggee.threadByFieldNameOrThrow(debuggeeClass, thread3Name);
String poppedMethod = "poppedMethod";
String breakpointLine = "breakpointLine";

View File

@ -270,7 +270,7 @@ public class popframes004 extends JDIBase {
breakpointForCommunication();
String thread2Name = "thread2";
ThreadReference thread2Ref = debuggee.threadByNameOrThrow(thread2Name);
ThreadReference thread2Ref = debuggee.threadByFieldNameOrThrow(debuggeeClass, thread2Name);
StackFrame stackFrame = null;
int var;

View File

@ -274,7 +274,7 @@ public class popframes005 extends JDIBase {
breakpointForCommunication();
String thread2Name = "thread2";
ThreadReference thread2Ref = debuggee.threadByNameOrThrow(thread2Name);
ThreadReference thread2Ref = debuggee.threadByFieldNameOrThrow(debuggeeClass, thread2Name);
StackFrame stackFrame0 = null;
StackFrame stackFrame1 = null;

View File

@ -264,6 +264,33 @@ public class Debugee extends DebugeeProcess {
throw new JDITestRuntimeException("** Thread IS NOT found ** : " + name);
}
/**
* Return a debuggee thread by fetching it from a static field in the debuggee.
*/
public ThreadReference threadByFieldNameOrThrow(ReferenceType debuggeeClass,
String threadFieldName)
throws JDITestRuntimeException {
Field field = debuggeeClass.fieldByName(threadFieldName);
if (field == null) {
throw new JDITestRuntimeException("** Thread field not found ** : "
+ threadFieldName);
}
ThreadReference thread = (ThreadReference)debuggeeClass.getValue(field);
if (thread == null) {
throw new JDITestRuntimeException("** Thread field is null ** : "
+ threadFieldName);
}
if (!thread.name().equals(threadFieldName)) {
throw new JDITestRuntimeException("** Thread names do not match ** : "
+ threadFieldName + " vs. " + thread.name());
}
return thread;
}
// --------------------------------------------------- //
/**