User Tools

Site Tools


java_class_process

This is an old revision of the document!


Between 1.4.2 and the versions v1.6+ of the JDK, changes have been made to the creation of processes. These changes bring benefits, in particular in the light of a nasty bug found by Soumaya and Venera when running MoDeC on MacOS.

Java Class Process

The Java class Process is used together with class Runtime. As explained by Oracle: “The Runtime.exec methods create a native process and return an instance of a subclass of Process that can be used to control the process and obtain information about it. The class Process provides methods for performing input from the process, performing output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process.” (from the Javadocs of version 1.4.2).

Typically, in MoDeC, we created and run a Process that executes a new Java virtual machine, which itself runs a program whose bytecodes we had instrumented to collect traces. Simply put:

String commandLine = ...;
String absolutePathToInstrumentedFiles = ...;

final Process process =
	Runtime.getRuntime().exec(
		commandLine,
		new String[0],
		absolutePathToInstrumentedFiles);

where

  • commandLine is the complete command line to run a new Java virtual machine;
  • new string[0] tells the Runime.exec() that we do not touch the environment;
  • absolutePathToInstrumentedFiles is the complete, absolute path to the root directory containing the instrumented bytecodes.

The Bug

When applying MoDeC on “small” program, we did not encounter any problem, neither on Windows nor on Mac OS. However, when Soumaya ran MoDeC on the instrumented version of ArgoUML v0.19.8, should got this exception (here reproduced using Venera's Mac):

Exception in thread "main"  java.lang.NoClassDefFoundError: Invoker/bin:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/pdf-transcoder/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-anim/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-bridge/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-codec/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-extension/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-gui-util/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-gvt/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-script/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-swing/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-transcoder/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-parser/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-css/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-svg-dom/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-ext/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/commons-lang-2/4/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/bin:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/tools/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/xalan-2/6/0/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/xerces_2_5_0/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/xml-apis/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/xml-apis-ext/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/cfparse:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/bcel:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-awt-util/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-dom/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-svggen/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-util/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/batik-xml/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/CPL/lib/trove-3/0/0a3/jar:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/MoDeCMetamodel/bin:/Users/Neni/Documents/Research/2013-LabalingTraceSegm/eclipseWS/MoDeC
Caused by: java.lang.ClassNotFoundException: Invoker.bin:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.pdf-transcoder.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-anim.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-bridge.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-codec.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-extension.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-gui-util.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-gvt.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-script.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-swing.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-transcoder.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-parser.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-css.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-svg-dom.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-ext.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.commons-lang-2.4.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.bin:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.tools.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.xalan-2.6.0.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.xerces_2_5_0.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.xml-apis.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.xml-apis-ext.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.cfparse:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.bcel:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-awt-util.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-dom.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-svggen.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-util.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.batik-xml.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.CPL.lib.trove-3.0.0a3.jar:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.MoDeCMetamodel.bin:.Users.Neni.Documents.Research.2013-LabalingTraceSegm.eclipseWS.MoDeC
	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

which was very puzzling because the version of MoDeC and the same input file and the same instrumented bytecodes would work on Yann's Windows laptop and produce the expected traces.

The Solution

After much tinkering, we decided manage to get MoDeC to work by using the “new” class ProcessBuilder because “As of 1.5, ProcessBuilder.start() is the preferred way to create a Process.” (according to Oracle in a version of the Javadocs subsequent to 1.5). We modified essentially the code as follows:

final ProcessBuilder pb = new ProcessBuilder(commandLine);
pb.directory(absolutePathToInstrumentedFiles);
final Process process = pb.start();

With these changes, the same input file and the same instrumented bytecodes would produced the same, expected traces in both Windows and MacOS computers!

Acknowledgements

This bug could not have been found without the dedicated MacOS users of the lab. Soumaya and Venera ;-). This bug could not have been fixed without Venera's great help and patience!

java_class_process.1367223199.txt.gz · Last modified: 2018/03/04 02:53 (external edit)