public boolean launchVirtualMachine(boolean presenting) { String[] vmParams = getMachineParams(); String[] sketchParams = getSketchParams(presenting); int port = 8000 + (int) (Math.random() * 1000); String portStr = String.valueOf(port); // Older (Java 1.5 and earlier) version, go figure // String jdwpArg = "-Xrunjdwp:transport=dt_socket,address=" + portStr + // ",server=y,suspend=y"; // String debugArg = "-Xdebug"; // Newer (Java 1.5+) version that uses JVMTI String jdwpArg = "-agentlib:jdwp=transport=dt_socket,address=" + portStr + ",server=y,suspend=y"; // Everyone works the same under Java 7 (also on OS X) String[] commandArgs = new String[] {Base.getJavaPath(), jdwpArg}; /* String[] commandArgs = null; if (!Base.isMacOS()) { commandArgs = new String[] { Base.getJavaPath(), jdwpArg }; } else { // Decided to just set this to 1.6 only, because otherwise it's gonna // be a shitshow if folks are getting Apple's 1.6 with 32-bit and // Oracle's 1.7 when run in 64-bit mode. ("Why does my sketch suck in // 64-bit? Why is retina broken?) // The --request flag will prompt to install Apple's 1.6 JVM if none is // available. We're specifying 1.6 so that we can get support for both // 32- and 64-bit, because Oracle won't be releasing Java 1.7 in 32-bit. // Helpfully, the --request flag is not present on Mac OS X 10.6 // (luckily it is also not needed, because 1.6 is installed by default) // but it requires an additional workaround to not use that flag, // otherwise will see an error about an unsupported option. The flag is // available with 10.7 and 10.8, the only other supported versions of // OS X at this point, because we require 10.6.8 and higher. That also // means we don't need to check for any other OS versions, the user is // a douchebag and modifies Info.plist to get around the restriction. if (false) { if (System.getProperty("os.version").startsWith("10.6")) { commandArgs = new String[] { "/usr/libexec/java_home", "--version", "1.6", "--exec", "java", "-d" + Base.getNativeBits(), jdwpArg }; } else { // for 10.7, 10.8, etc commandArgs = new String[] { "/usr/libexec/java_home", "--request", // install on-demand "--version", "1.6", "--exec", "java", "-d" + Base.getNativeBits(), // debugArg, jdwpArg }; } } else { // testing jdk-7u40 commandArgs = new String[] { //"/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/bin/java", Base.getJavaPath(), jdwpArg }; } } */ commandArgs = PApplet.concat(commandArgs, vmParams); commandArgs = PApplet.concat(commandArgs, sketchParams); // PApplet.println(commandArgs); // commandArg.setValue(commandArgs); launchJava(commandArgs); AttachingConnector connector = (AttachingConnector) findConnector("com.sun.jdi.SocketAttach"); // PApplet.println(connector); // gets the defaults Map arguments = connector.defaultArguments(); // Connector.Argument addressArg = // (Connector.Argument)arguments.get("address"); // addressArg.setValue(addr); Connector.Argument portArg = (Connector.Argument) arguments.get("port"); portArg.setValue(portStr); // Connector.Argument timeoutArg = // (Connector.Argument)arguments.get("timeout"); // timeoutArg.setValue("10000"); // PApplet.println(connector); // prints the current // com.sun.tools.jdi.AbstractLauncher al; // com.sun.tools.jdi.RawCommandLineLauncher rcll; // System.out.println(PApplet.javaVersion); // http://java.sun.com/j2se/1.5.0/docs/guide/jpda/conninv.html#sunlaunch try { // boolean available = false; // while (!available) { while (true) { try { vm = connector.attach(arguments); // vm = connector.attach(arguments); if (vm != null) { // generateTrace(); // available = true; return true; } } catch (IOException e) { // System.out.println("waiting"); // e.printStackTrace(); try { Thread.sleep(100); } catch (InterruptedException e1) { e1.printStackTrace(); } } } // } catch (IOException exc) { // throw new Error("Unable to launch target VM: " + exc); } catch (IllegalConnectorArgumentsException exc) { throw new Error("Internal error: " + exc); } }
protected String[] getMachineParams() { ArrayList<String> params = new ArrayList<String>(); // params.add("-Xint"); // interpreted mode // params.add("-Xprof"); // profiler // params.add("-Xaprof"); // allocation profiler // params.add("-Xrunhprof:cpu=samples"); // old-style profiler // TODO change this to use run.args = true, run.args.0, run.args.1, etc. // so that spaces can be included in the arg names String options = Preferences.get("run.options"); if (options.length() > 0) { String pieces[] = PApplet.split(options, ' '); for (int i = 0; i < pieces.length; i++) { String p = pieces[i].trim(); if (p.length() > 0) { params.add(p); } } } // params.add("-Djava.ext.dirs=nuffing"); if (Preferences.getBoolean("run.options.memory")) { params.add("-Xms" + Preferences.get("run.options.memory.initial") + "m"); params.add("-Xmx" + Preferences.get("run.options.memory.maximum") + "m"); } if (Base.isMacOS()) { params.add("-Xdock:name=" + build.getSketchClassName()); // params.add("-Dcom.apple.mrj.application.apple.menu.about.name=" + // sketch.getMainClassName()); } // sketch.libraryPath might be "" // librariesClassPath will always have sep char prepended params.add( "-Djava.library.path=" + build.getJavaLibraryPath() + File.pathSeparator + System.getProperty("java.library.path")); params.add("-cp"); params.add(build.getClassPath()); // params.add(sketch.getClassPath() + // File.pathSeparator + // Base.librariesClassPath); // enable assertions // http://dev.processing.org/bugs/show_bug.cgi?id=1188 params.add("-ea"); // PApplet.println(PApplet.split(sketch.classPath, ':')); String outgoing[] = new String[params.size()]; params.toArray(outgoing); // PApplet.println(outgoing); // PApplet.println(PApplet.split(outgoing[0], ":")); // PApplet.println(); // PApplet.println("class path"); // PApplet.println(PApplet.split(outgoing[2], ":")); return outgoing; // return (String[]) params.toArray(); // System.out.println("sketch class path"); // PApplet.println(PApplet.split(sketch.classPath, ';')); // System.out.println(); // System.out.println("libraries class path"); // PApplet.println(PApplet.split(Base.librariesClassPath, ';')); // System.out.println(); }
public boolean launchVirtualMachine(boolean presenting) { String[] vmParams = getMachineParams(); String[] sketchParams = getSketchParams(presenting); // PApplet.printArray(sketchParams); int port = 8000 + (int) (Math.random() * 1000); String portStr = String.valueOf(port); // Older (Java 1.5 and earlier) version, go figure // String jdwpArg = "-Xrunjdwp:transport=dt_socket,address=" + portStr + // ",server=y,suspend=y"; // String debugArg = "-Xdebug"; // Newer (Java 1.5+) version that uses JVMTI String jdwpArg = "-agentlib:jdwp=transport=dt_socket,address=" + portStr + ",server=y,suspend=y"; // Everyone works the same under Java 7 (also on OS X) String[] commandArgs = new String[] {Base.getJavaPath(), jdwpArg}; commandArgs = PApplet.concat(commandArgs, vmParams); commandArgs = PApplet.concat(commandArgs, sketchParams); // PApplet.println(commandArgs); // commandArg.setValue(commandArgs); launchJava(commandArgs); AttachingConnector connector = (AttachingConnector) findConnector("com.sun.jdi.SocketAttach"); // PApplet.println(connector); // gets the defaults Map<String, Argument> arguments = connector.defaultArguments(); // Connector.Argument addressArg = // (Connector.Argument)arguments.get("address"); // addressArg.setValue(addr); Connector.Argument portArg = arguments.get("port"); portArg.setValue(portStr); // Connector.Argument timeoutArg = // (Connector.Argument)arguments.get("timeout"); // timeoutArg.setValue("10000"); // PApplet.println(connector); // prints the current // com.sun.tools.jdi.AbstractLauncher al; // com.sun.tools.jdi.RawCommandLineLauncher rcll; // System.out.println(PApplet.javaVersion); // http://java.sun.com/j2se/1.5.0/docs/guide/jpda/conninv.html#sunlaunch try { // boolean available = false; // while (!available) { while (true) { try { vm = connector.attach(arguments); // vm = connector.attach(arguments); if (vm != null) { // generateTrace(); // available = true; return true; } } catch (IOException e) { // System.out.println("waiting"); // e.printStackTrace(); try { Thread.sleep(100); } catch (InterruptedException e1) { e1.printStackTrace(sketchErr); } } } // } catch (IOException exc) { // throw new Error("Unable to launch target VM: " + exc); } catch (IllegalConnectorArgumentsException exc) { throw new Error("Internal error: " + exc); } }