Skip to content

Commit

Permalink
Merge pull request #4211 from keithc-ca/snap
Browse files Browse the repository at this point in the history
Fix tools for formatting tracepoints
  • Loading branch information
pshipton authored Jan 9, 2019
2 parents 8d181eb + a5c9c6a commit 9245ae0
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 275 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013, 2015 IBM Corp. and others
* Copyright (c) 2013, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -38,11 +38,10 @@ public SnapFormatWrapperCommand()
addCommand("snapformat", "[<filename>]", "format trace buffers to a specified file or stdout");
addCommand("snapformat", "-help", "print detailed help");
addCommand("snapformat", "[-f <filename>] [-d <datfile_directory>] [-t <j9vmthread id>] [-s <filter>]", "format trace buffers for all threads or just the specified thread to a file or stdout using the specified .dat files");
}
}

public void run(String command, String[] args, Context context,
PrintStream out) throws DDRInteractiveCommandException {

if ((args.length > 0) && (args[0].equals("-help") || args[0].equals("-h") || args[0].equals("-?"))) {
out.println("Format selected trace buffers.");
out.println();
Expand All @@ -64,35 +63,21 @@ public void run(String command, String[] args, Context context,
return;
}
try {
Class snapFormatCommandCls = Class.forName("com.ibm.j9ddr.tools.ddrinteractive.commands.SnapFormatCommand");
Class<?> snapFormatCommandCls = Class.forName("com.ibm.j9ddr.tools.ddrinteractive.commands.SnapFormatCommand");
Object snapFormatCommandInstance = snapFormatCommandCls.newInstance();
if( snapFormatCommandInstance instanceof Command) {
Command c = (Command)snapFormatCommandInstance;
if (snapFormatCommandInstance instanceof Command) {
Command c = (Command) snapFormatCommandInstance;
c.run(command, args, context, out);
} else {
throw new DDRInteractiveCommandException("Unable to format trace. Could not create formatter.");
}
} catch (ClassNotFoundException e) {
//e.printStackTrace(out);
throw new DDRInteractiveCommandException("Unable to format trace. " + e.getMessage(), e);
} catch (IllegalAccessException e) {
//e.printStackTrace(out);
throw new DDRInteractiveCommandException("Unable to format trace. " + e.getMessage(), e);
} catch (InstantiationException e) {
//e.printStackTrace(out);
throw new DDRInteractiveCommandException("Unable to format trace. " + e.getMessage(), e);
} catch (SecurityException e) {
//e.printStackTrace(out);
throw new DDRInteractiveCommandException("Unable to format trace. " + e.getMessage(), e);
} catch (IllegalArgumentException e) {
//e.printStackTrace(out);
} catch (ClassNotFoundException
| IllegalAccessException
| IllegalArgumentException
| InstantiationException
| SecurityException e) {
throw new DDRInteractiveCommandException("Unable to format trace. " + e.getMessage(), e);
}
// catch (java.lang.Error e) {
// /* Naughty catching this but good for catching unresolved com.ibm.jvm.trace.* problems. */
// //e.printStackTrace(out);
// throw new DDRInteractiveCommandException("Unable to format trace. " + e.getMessage(), e);
// }
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar18-SE]*/
/*******************************************************************************
* Copyright (c) 2004, 2018 IBM Corp. and others
* Copyright (c) 2004, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -66,6 +66,7 @@ static final class ImageReference {
private ClassLoader imageFactoryClassLoader;
private File tmpdir = null; // the directory which holds any extracted files

/*[IF Sidecar19-SE]*/
static {
/*
* Even though j9ddr.jar is a resource within the module openj9.dtfj,
Expand Down Expand Up @@ -99,9 +100,10 @@ static final class ImageReference {
exportToAll.invoke(null, thisModule, "com.ibm.java.diagnostics.utils"); //$NON-NLS-1$
exportToAll.invoke(null, thisModule, "com.ibm.java.diagnostics.utils.commands"); //$NON-NLS-1$
} catch (Exception e) {
// assume pre-Java 9 jvm
throw new InternalError("Failed to adjust module exports", e); //$NON-NLS-1$
}
}
/*[ENDIF] Sidecar19-SE*/

/**
* This public constructor is intended for use with Class.newInstance().
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar18-SE]*/
/*******************************************************************************
* Copyright (c) 2004, 2017 IBM Corp. and others
* Copyright (c) 2004, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -208,7 +208,6 @@ private File sysFileRelative(File virtualRoot, File originalPath)
return result;
}


public Object buildSymbol(Object addressSpace, String functionName, long relocatedFunctionAddress) {
return new Object();
}
Expand Down Expand Up @@ -474,25 +473,30 @@ private void runZip(String outputName) {
for (Iterator iter = _dump.getAdditionalFileNames(); iter.hasNext();) {
files.add(iter.next());
}



try {
// Add the trace formatting template files (Traceformat.dat and J9TraceFormat.dat) into the zip
// Add trace formatting template files (Traceformat.dat, J9TraceFormat.dat and OMRTraceFormat.dat) into the archive.
String lib_dir = System.getProperty("java.home") + File.separator + "lib" + File.separator;
String trace = lib_dir + "TraceFormat.dat";
if (new File(trace).exists())
if (new File(trace).exists()) {
files.add(trace);
}
String j9trace = lib_dir + "J9TraceFormat.dat";
if (new File(j9trace).exists())
if (new File(j9trace).exists()) {
files.add(j9trace);

}
String omrtrace = lib_dir + "OMRTraceFormat.dat";
if (new File(omrtrace).exists()) {
files.add(omrtrace);
}

// Add the debugger extension library into the zip, available only on AIX
String osName = System.getProperty("os.name");
if (osName != null && osName.equalsIgnoreCase("AIX")) {
files.add("libdbx_j9.so");
}
} catch (Exception e) {
// Ignore
// Ignore
}

try {
Expand Down Expand Up @@ -635,7 +639,6 @@ private static void copy(ClosingFileReader from, OutputStream to, byte[] buffer)
}
}


private native long getEnvironmentPointer(IAbstractAddressSpace dump) throws Exception;
private native void doCommand(IAbstractAddressSpace dump, String command) throws Exception;

Expand Down
3 changes: 2 additions & 1 deletion jcl/src/openj9.dtfj/share/classes/module-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar19-SE]*/
/*******************************************************************************
* Copyright (c) 2016, 2017 IBM Corp. and others
* Copyright (c) 2016, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -32,6 +32,7 @@
requires transitive java.desktop;
requires transitive java.logging;
requires java.xml;
requires openj9.traceformat;
/*[IF PLATFORM-mz31 | PLATFORM-mz64]*/
requires com.ibm.jzos;
/*[ENDIF]*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar18-SE]*/
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corp. and others
* Copyright (c) 2000, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -448,6 +448,16 @@ private void instantiateMessageFiles(String lowestPriorityDefault)
TraceFormat.outStream.println("*** Could not find a J9TraceFormat.dat file. JVM trace points may be formatted incorrectly.");
}

/*
* Now load OMRTraceFormat.dat if available.
*/
String omrFormatFilePath = findDatFile(dirsToSearch, "OMRTraceFormat.dat");

if (omrFormatFilePath != null) {
/* we found a suitable dat file */
tryMessageFileInstantiation(omrFormatFilePath);
}

/*
* Also load TraceFormat.dat as it contains the trace points for the class libraries.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/*[INCLUDE-IF Sidecar19-SE]*/
/*[IF Sidecar19-SE]*/
package com.ibm.jvm.traceformat;
/*[ELSE]
package com.ibm.jvm;
/*[ENDIF]*/

/*******************************************************************************
* Copyright (c) 2010, 2018 IBM Corp. and others
* Copyright (c) 2010, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -26,6 +20,11 @@
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/
/*[IF Sidecar19-SE]*/
package com.ibm.jvm.traceformat;
/*[ELSE]
package com.ibm.jvm;
/*[ENDIF]*/

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -55,7 +54,7 @@

/**
* !!! WARNING !!!
* Adding any new top level classes in this file requires modification to jcl\jcl_build.mk
* Adding any new top level classes in this file requires modification to jcl/jcl_build.mk
* to ensure the new classes are included within traceformat.jar for Java 8.
*/
public class TraceFormat
Expand Down Expand Up @@ -528,9 +527,11 @@ class MessageFile extends ProgramOption {
List messageFiles = new LinkedList();

String getDescription() {
return "A comma separated list of files containing the trace format strings. By default the following files are used:"+System.getProperty("line.separator")+
" $JAVA_HOME/lib/J9TraceFormat.dat"+System.getProperty("line.separator")+
" $JAVA_HOME/lib/TraceFormat.dat";
String eol = System.getProperty("line.separator", "\n");
return "A comma separated list of files containing the trace format strings. By default the following files are used:" + eol
+ " $JAVA_HOME/lib/J9TraceFormat.dat" + eol
+ " $JAVA_HOME/lib/OMRTraceFormat.dat" + eol
+ " $JAVA_HOME/lib/TraceFormat.dat";
}

String getName() {
Expand All @@ -554,13 +555,11 @@ void setValue(String value) throws IllegalArgumentException {
token = st.nextToken();
/* construct files from the tokens. These files must exist */
File datFile = new File(token);
if( !datFile.exists() ) {
throw new FileNotFoundException(token);
if (!datFile.exists()) {
throw new IllegalArgumentException("dat file \"" + token + "\" not found");
}
messageFiles.add(datFile);
}
} catch (FileNotFoundException e) {
throw new IllegalArgumentException("dat file \""+token+"\" not found");
} catch (SecurityException e) {
throw new IllegalArgumentException("The application does not have permission to access the specified dat file, \""+token+"\"");
}
Expand All @@ -571,6 +570,7 @@ void setDefault() {
dir = dir.concat(File.separator).concat("lib").concat(File.separator);

setValue(dir + "J9TraceFormat.dat");
setValue(dir + "OMRTraceFormat.dat");
try {
setValue(dir + "TraceFormat.dat");
} catch (IllegalArgumentException e) {
Expand Down
7 changes: 4 additions & 3 deletions jcl/src/openj9.traceformat/share/classes/module-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar19-SE]*/
/*******************************************************************************
* Copyright (c) 2016, 2017 IBM Corp. and others
* Copyright (c) 2016, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -20,5 +20,6 @@
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/
module openj9.traceformat {
}
module openj9.traceformat {
exports com.ibm.jvm.trace.format.api;
}

0 comments on commit 9245ae0

Please sign in to comment.