Skip to content

Commit 0665c39

Browse files
authored
Merge branch 'master' into goetz_backport_8355569
2 parents 2c5b571 + 8135648 commit 0665c39

File tree

27 files changed

+1290
-409
lines changed

27 files changed

+1290
-409
lines changed

src/hotspot/share/prims/jvmtiAgentList.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, 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
@@ -124,11 +124,11 @@ void JvmtiAgentList::add(JvmtiAgent* agent) {
124124
} while (Atomic::cmpxchg(&_list, next, agent) != next);
125125
}
126126

127-
void JvmtiAgentList::add(const char* name, char* options, bool absolute_path) {
127+
void JvmtiAgentList::add(const char* name, const char* options, bool absolute_path) {
128128
add(new JvmtiAgent(name, options, absolute_path));
129129
}
130130

131-
void JvmtiAgentList::add_xrun(const char* name, char* options, bool absolute_path) {
131+
void JvmtiAgentList::add_xrun(const char* name, const char* options, bool absolute_path) {
132132
JvmtiAgent* agent = new JvmtiAgent(name, options, absolute_path);
133133
agent->set_xrun();
134134
add(agent);
@@ -198,18 +198,14 @@ void JvmtiAgentList::load_xrun_agents() {
198198
}
199199

200200
// Invokes Agent_OnAttach for agents loaded dynamically during runtime.
201-
jint JvmtiAgentList::load_agent(const char* agent_name, const char* absParam,
202-
const char* options, outputStream* st) {
203-
// The abs parameter should be "true" or "false"
204-
const bool is_absolute_path = (absParam != nullptr) && (strcmp(absParam, "true") == 0);
201+
void JvmtiAgentList::load_agent(const char* agent_name, bool is_absolute_path,
202+
const char* options, outputStream* st) {
205203
JvmtiAgent* const agent = new JvmtiAgent(agent_name, options, is_absolute_path, /* dynamic agent */ true);
206204
if (agent->load(st)) {
207205
add(agent);
208206
} else {
209207
delete agent;
210208
}
211-
// Agent_OnAttach executed so completion status is JNI_OK
212-
return JNI_OK;
213209
}
214210

215211
// Send any Agent_OnUnload notifications

src/hotspot/share/prims/jvmtiAgentList.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, 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
@@ -64,14 +64,15 @@ class JvmtiAgentList : AllStatic {
6464
static void initialize();
6565
static void convert_xrun_agents();
6666

67-
public:
6867
static void add(JvmtiAgent* agent) NOT_JVMTI_RETURN;
69-
static void add(const char* name, char* options, bool absolute_path) NOT_JVMTI_RETURN;
70-
static void add_xrun(const char* name, char* options, bool absolute_path) NOT_JVMTI_RETURN;
68+
69+
public:
70+
static void add(const char* name, const char* options, bool absolute_path) NOT_JVMTI_RETURN;
71+
static void add_xrun(const char* name, const char* options, bool absolute_path) NOT_JVMTI_RETURN;
7172

7273
static void load_agents() NOT_JVMTI_RETURN;
73-
static jint load_agent(const char* agent, const char* absParam,
74-
const char* options, outputStream* st) NOT_JVMTI_RETURN_(0);
74+
static void load_agent(const char* agent, bool is_absolute_path,
75+
const char* options, outputStream* st) NOT_JVMTI_RETURN;
7576
static void load_xrun_agents() NOT_JVMTI_RETURN;
7677
static void unload_agents() NOT_JVMTI_RETURN;
7778

src/hotspot/share/services/attachListener.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,12 @@ static jint load_agent(AttachOperation* op, outputStream* out) {
135135
}
136136
}
137137

138-
return JvmtiAgentList::load_agent(agent, absParam, options, out);
138+
// The abs parameter should be "true" or "false".
139+
const bool is_absolute_path = (absParam != nullptr) && (strcmp(absParam, "true") == 0);
140+
JvmtiAgentList::load_agent(agent, is_absolute_path, options, out);
141+
142+
// Agent_OnAttach result or error message is written to 'out'.
143+
return JNI_OK;
139144
}
140145

141146
// Implementation of "properties" command.

src/hotspot/share/services/diagnosticCommand.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ void JVMTIAgentLoadDCmd::execute(DCmdSource source, TRAPS) {
304304

305305
if (is_java_agent) {
306306
if (_option.value() == nullptr) {
307-
JvmtiAgentList::load_agent("instrument", "false", _libpath.value(), output());
307+
JvmtiAgentList::load_agent("instrument", false, _libpath.value(), output());
308308
} else {
309309
size_t opt_len = strlen(_libpath.value()) + strlen(_option.value()) + 2;
310310
if (opt_len > 4096) {
@@ -321,12 +321,12 @@ void JVMTIAgentLoadDCmd::execute(DCmdSource source, TRAPS) {
321321
}
322322

323323
jio_snprintf(opt, opt_len, "%s=%s", _libpath.value(), _option.value());
324-
JvmtiAgentList::load_agent("instrument", "false", opt, output());
324+
JvmtiAgentList::load_agent("instrument", false, opt, output());
325325

326326
os::free(opt);
327327
}
328328
} else {
329-
JvmtiAgentList::load_agent(_libpath.value(), "true", _option.value(), output());
329+
JvmtiAgentList::load_agent(_libpath.value(), true, _option.value(), output());
330330
}
331331
}
332332

src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2024, 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
@@ -96,22 +96,30 @@ private void loadAgentLibrary(String agentLibrary, boolean isAbsolute, String op
9696
}
9797

9898
String msgPrefix = "return code: ";
99-
InputStream in = execute("load",
100-
agentLibrary,
101-
isAbsolute ? "true" : "false",
102-
options);
103-
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
104-
String result = reader.readLine();
105-
if (result == null) {
99+
String errorMsg = "Failed to load agent library";
100+
try {
101+
InputStream in = execute("load",
102+
agentLibrary,
103+
isAbsolute ? "true" : "false",
104+
options);
105+
String result = readErrorMessage(in);
106+
if (result.isEmpty()) {
106107
throw new AgentLoadException("Target VM did not respond");
107108
} else if (result.startsWith(msgPrefix)) {
108109
int retCode = Integer.parseInt(result.substring(msgPrefix.length()));
109110
if (retCode != 0) {
110111
throw new AgentInitializationException("Agent_OnAttach failed", retCode);
111112
}
112113
} else {
113-
throw new AgentLoadException(result);
114+
if (!result.isEmpty()) {
115+
errorMsg += ": " + result;
116+
}
117+
throw new AgentLoadException(errorMsg);
114118
}
119+
} catch (AttachOperationFailedException ex) {
120+
// execute() throws AttachOperationFailedException if attach agent reported error.
121+
// Convert it to AgentLoadException.
122+
throw new AgentLoadException(errorMsg + ": " + ex.getMessage());
115123
}
116124
}
117125

@@ -364,6 +372,9 @@ String readErrorMessage(InputStream in) throws IOException {
364372
StringBuilder message = new StringBuilder();
365373
BufferedReader br = new BufferedReader(new InputStreamReader(in));
366374
while ((s = br.readLine()) != null) {
375+
if (message.length() > 0) {
376+
message.append(' ');
377+
}
367378
message.append(s);
368379
}
369380
return message.toString();
@@ -399,20 +410,10 @@ void processCompletionStatus(IOException ioe, String cmd, InputStream sis) throw
399410
throw new IOException("Protocol mismatch with target VM");
400411
}
401412

402-
// Special-case the "load" command so that the right exception is
403-
// thrown.
404-
if (cmd.equals("load")) {
405-
String msg = "Failed to load agent library";
406-
if (!message.isEmpty()) {
407-
msg += ": " + message;
408-
}
409-
throw new AgentLoadException(msg);
410-
} else {
411-
if (message.isEmpty()) {
412-
message = "Command failed in target VM";
413-
}
414-
throw new AttachOperationFailedException(message);
413+
if (message.isEmpty()) {
414+
message = "Command failed in target VM";
415415
}
416+
throw new AttachOperationFailedException(message);
416417
}
417418
}
418419

test/hotspot/jtreg/ProblemList-Virtual.txt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,8 @@ vmTestbase/nsk/jvmti/CompiledMethodUnload/compmethunload001/TestDescription.java
3636
####
3737
## Tests for functionality which currently is not supported for virtual threads
3838

39-
vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001/TestDescription.java 8300708 generic-all
40-
vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime001/TestDescription.java 8300708 generic-all
41-
vmTestbase/nsk/jvmti/NotifyFramePop/nframepop002/TestDescription.java 8300708 generic-all
42-
vmTestbase/nsk/jvmti/NotifyFramePop/nframepop003/TestDescription.java 8300708 generic-all
43-
vmTestbase/nsk/jvmti/StopThread/stopthrd006/TestDescription.java 8300708 generic-all
44-
vmTestbase/nsk/jvmti/scenarios/events/EM02/em02t012/TestDescription.java 8300708 generic-all
45-
vmTestbase/nsk/jvmti/SetLocalVariable/setlocal004/TestDescription.java 8300708 generic-all
46-
vmTestbase/nsk/jvmti/SetLocalVariable/setlocal003/TestDescription.java 8300708 generic-all
47-
vmTestbase/nsk/jvmti/SetLocalVariable/setlocal002/TestDescription.java 8300708 generic-all
48-
vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001/TestDescription.java 8300708 generic-all
49-
vmTestbase/nsk/jvmti/unit/GetLocalVariable/getlocal003/TestDescription.java 8300708 generic-all
39+
vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001/TestDescription.java 8348844 generic-all
40+
vmTestbase/nsk/jvmti/GetThreadCpuTime/thrcputime001/TestDescription.java 8348844 generic-all
5041

5142
####
5243
## Test fails because it expects to find vthreads in GetAllThreads

test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/resume/resume001.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ private static void log3(String message) {
117117
static int waitTime;
118118

119119
static VirtualMachine vm = null;
120+
static Debugee debuggee = null;
120121
static EventRequestManager eventRManager = null;
121122
static EventQueue eventQueue = null;
122123
static EventSet eventSet = null;
@@ -137,8 +138,6 @@ private static void log3(String message) {
137138

138139
private int runThis (String argv[], PrintStream out) {
139140

140-
Debugee debuggee;
141-
142141
argsHandler = new ArgumentHandler(argv);
143142
logHandler = new Log(out, argsHandler);
144143
Binder binder = new Binder(argsHandler, logHandler);
@@ -336,13 +335,23 @@ private int runThis (String argv[], PrintStream out) {
336335
break label1;
337336
log2(" thread2 is at breakpoint");
338337

339-
340338
log2("......checking up that thread2.resume() resumes thread2 suspended with VirtualMachine.suspend()");
341339

342340
log2(" enabling breakpRequest3");
343341
breakpRequest3.enable();
342+
343+
// don't do vm.suspend() until mainThread is waiting
344+
line = pipe.readln();
345+
if (line.equals("waiting")) {
346+
log2(" : returned string is 'waiting'");
347+
} else {
348+
log3("ERROR: returned string is not 'waiting': " + line);
349+
expresult = returnCode4;
350+
break label1;
351+
}
344352
log2(" suspending the thread2 with vm.suspend()");
345353
vm.suspend();
354+
346355
log2(" first resuming the thread2 with eventSet.resume()");
347356
eventSet.resume();
348357
log2(" checking up thread's state");
@@ -361,13 +370,17 @@ private int runThis (String argv[], PrintStream out) {
361370
break label1;
362371
log2(" thread2 is at breakpoint");
363372

364-
365-
log2(" resuming the thread2");
373+
log2(" resuming the thread2");
366374
thread2.resume();
367375

376+
log2(" undo the vm.suspend() with vm.resume()");
377+
vm.resume();
378+
}
379+
// These are only needed if we break out of the loop due to an error
380+
if (expresult != returnCode0) {
381+
vm.resume();
382+
vm.resume(); // for case error when both VirtualMachine and the thread2 were suspended
368383
}
369-
vm.resume();
370-
vm.resume(); // for case error when both VirtualMachine and the thread2 were suspended
371384

372385
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
373386
log2(" the end of testing");
@@ -487,7 +500,8 @@ private int breakpoint () {
487500
try {
488501
eventSet = eventQueue.remove(waitTime*60000);
489502
if (eventSet == null) {
490-
log3("ERROR: timeout for waiting for a BreakpintEvent");
503+
log3("ERROR: timeout for waiting for a BreakpointEvent");
504+
debuggee.printThreadsInfo(vm);
491505
returnCode = returnCode3;
492506
break labelBP;
493507
}

test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/resume/resume001a.java

Lines changed: 8 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, 2024, 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
@@ -81,7 +81,13 @@ public static void main (String argv[]) {
8181

8282
String instruction;
8383

84-
log1("waiting for an instruction from the debugger ...");
84+
log1("waiting for an instruction from the debugger: iteration " + i);
85+
if (i == 1) {
86+
// Let the debugger know we finished the first iteration and are now
87+
// waiting for next command. This is needed so we don't suspend the
88+
// main thread while it is doing a log(), which can hold a needed lock.
89+
pipe.println("waiting");
90+
}
8591
instruction = pipe.readln();
8692
if (instruction.equals("quit")) {
8793
log1("'quit' recieved");

test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetLocalVariable/setlocal001.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 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
@@ -80,6 +80,10 @@ public double meth01() {
8080
float f = 0f;
8181
double d = 0;
8282
checkPoint();
83+
if (currThread.isVirtual()) {
84+
out.println("meth01: skipping results check for virtual thread");
85+
return d + f + 1; // SetLocal* should return OPAQUE_FRAME for a virtual thread
86+
}
8387
if (l != 22L || f != floatVal || d != doubleVal) {
8488
out.println("meth01: l =" + l + " f = " + f + " d = " + d);
8589
result = 2;
@@ -97,6 +101,10 @@ public void meth02(int step) {
97101
meth02(step - 1);
98102
} else {
99103
checkPoint();
104+
if (currThread.isVirtual()) {
105+
out.println("meth02: skipping results check for virtual thread");
106+
return; // SetLocal* should return OPAQUE_FRAME for a virtual thread
107+
}
100108
if (i1 != 1 || i2 != 1 || i3 != 1 || i4 != 1 || !i5) {
101109
out.println("meth02: i1 =" + i1 + " i2 = " + i2 +
102110
" i3 = " + i3 + " i4 = " + i4 + " i5 = " + i5);
@@ -109,6 +117,10 @@ public static void meth03() {
109117
setlocal001 ob1 = null;
110118
int[] ob2 = null;
111119
checkPoint();
120+
if (currThread.isVirtual()) {
121+
out.println("meth03: skipping results check for virtual thread");
122+
return; // SetLocalObject for obj1 and obj2 should return OPAQUE_FRAME for a virtual thread
123+
}
112124
if (ob1.val != 3 || ob2[2] != 8) {
113125
out.println("meth03: ob1.val =" + ob1.val + " ob2[2] = " + ob2[2]);
114126
result = 2;
@@ -118,6 +130,10 @@ public static void meth03() {
118130
public static void meth04(int i1, long l, short i2, double d,
119131
char i3, float f, byte i4, boolean b) {
120132
checkPoint();
133+
if (currThread.isVirtual()) {
134+
out.println("meth04: skipping results check for virtual thread");
135+
return; // SetLocal* should return OPAQUE_FRAME for a virtual thread
136+
}
121137
if (i1 != 1 || i2 != 2 || i3 != 3 || i4 != 4 ||
122138
l != 22L || f != floatVal || d != doubleVal || !b) {
123139
out.println("meth04: i1 =" + i1 + " i2 = " + i2 +

0 commit comments

Comments
 (0)