Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JFR can invoke VM.setJFRRecordingFileName() before VM.startJFR() #21070

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -448,35 +448,33 @@ private static String parseStringParameter(String paramName, String[] parameters

private static DiagnosticProperties doJFR(String diagnosticCommand) {
DiagnosticProperties result = null;

// split the command and arguments
String[] parts = diagnosticCommand.split(DIAGNOSTICS_OPTION_SEPARATOR);
IPC.logMessage("doJFR: ", diagnosticCommand);

// ensure there's at least one part for the command
if (parts.length == 0) {
return DiagnosticProperties.makeErrorProperties("Error: No JFR command specified");
}

String command = parts[0].trim();
String[] parameters = Arrays.copyOfRange(parts, 1, parts.length);

String fileName = parseStringParameter("filename", parameters, null);
IPC.logMessage("doJFR: filename = ", fileName);
boolean setFileName = (fileName != null) && !fileName.isEmpty();
if (setFileName) {
if (!VM.setJFRRecordingFileName(fileName)) {
return DiagnosticProperties.makeErrorProperties("setJFRRecordingFileName failed");
} else {
jfrRecordingFileName = fileName;
}
}

try {
if (command.equalsIgnoreCase(DIAGNOSTICS_JFR_START)) {
if (VM.isJFRRecordingStarted()) {
result = DiagnosticProperties.makeErrorProperties("One JFR recording is in progress [" + jfrRecordingFileName + "], only one recording is allowed at a time.");
} else {
// only JFR.start command is allowed to change the recording filename
boolean setFileName = (fileName != null) && !fileName.isEmpty();
if (setFileName) {
// the recording filename should be set before VM.startJFR() which invokes JFRWriter:openJFRFile()
JasonFengJ9 marked this conversation as resolved.
Show resolved Hide resolved
if (!VM.setJFRRecordingFileName(fileName)) {
JasonFengJ9 marked this conversation as resolved.
Show resolved Hide resolved
return DiagnosticProperties.makeErrorProperties("setJFRRecordingFileName() failed");
} else {
jfrRecordingFileName = fileName;
}
}
VM.startJFR();
long duration = parseTimeParameter("duration", parameters);
IPC.logMessage("doJFR: duration = " + duration);
Expand Down
15 changes: 9 additions & 6 deletions runtime/vm/jfr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,12 +1127,15 @@ jfrSamplingThreadProc(void *entryArg)
jboolean
setJFRRecordingFileName(J9JavaVM *vm, char *fileName)
{
UDATA defaultFileNameLen = strlen(DEFAULT_JFR_FILE_NAME);
if ((defaultFileNameLen != strlen(vm->jfrState.jfrFileName))
|| (0 != strncmp(DEFAULT_JFR_FILE_NAME, vm->jfrState.jfrFileName, defaultFileNameLen))
) {
PORT_ACCESS_FROM_JAVAVM(vm);
j9mem_free_memory(vm->jfrState.jfrFileName);
if (NULL != vm->jfrState.jfrFileName) {
UDATA defaultFileNameLen = strlen(DEFAULT_JFR_FILE_NAME);
const char *jfrFileName = vm->jfrState.jfrFileName;
if ((defaultFileNameLen != strlen(jfrFileName))
|| (0 != strncmp(DEFAULT_JFR_FILE_NAME, jfrFileName, defaultFileNameLen))
) {
PORT_ACCESS_FROM_JAVAVM(vm);
j9mem_free_memory(vm->jfrState.jfrFileName);
}
}
vm->jfrState.jfrFileName = fileName;
VM_JFRWriter::closeJFRFile(vm);
Expand Down