Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6982310

mvm-on: OutOfProcessIsolate hangs when called from MServer isolate with non-null streams

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P3 P3
    • None
    • mvm-7
    • hotspot
    • None
    • generic
    • generic

      The following app starts an MServer, starts an app in the MServer, and then halts
      the MServer. When run with a Single-tasking VM, it works fine....

      java -jar ./dist/StreamBuster.jar

      However, when run with a Multi-tasking VM, it hangs. Setting streams parameter
      to OutOfProcessIsolate constructor will cause it to run to completion.

      java -XRunMServer &
      java -xUseMServer -jar ./dist/StreamBuster.jar


      I've attached the whole netbeans project dir for StreamBuster, which includes SampleTree.jar, which is the app that gets launched in the new MServer.

      Here is the full source for StreamBuster...

      ¿/**
       *
       * @author jmelvin
       */

      import java.io.FileInputStream;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.io.FileNotFoundException;
      import java.io.FileDescriptor;
      import java.util.Properties;
      import javax.isolate.Isolate;
      import javax.isolate.StreamBindings;
      import javax.isolate.IsolateStartupException;
      import javax.isolate.outofprocess.OutOfProcessIsolate;

      public class StreamBuster {

          private int port = 1587;
          private String mainClass = "SampleTree";

          private String javacmd = System.getProperty("java.home")
                  + System.getProperty("file.separator")
                  + "bin"
                  + System.getProperty("file.separator")
                  + "java ";
          
          private String mservercmd = javacmd + "-XRunMServer -XMServerPort:" + port;
          private String haltcmd = javacmd + "-XHaltMServer -XMServerPort:" + port;

          private String [] vmArgs = {
              "-XUseMServer",
              "-XMServerPort:" + port
          };

          private String classpath = "./SampleTree.jar";


          public StreamBuster() {
              // Start an MServer
              Process process = null;
              try {
                  process = Runtime.getRuntime().exec(mservercmd);
              }
              catch(IOException e) {
                  //ignore
              }

              // Delay
              try {
                  Thread.currentThread().sleep(5000);
              }
              catch(InterruptedException e) {
                  // ignore
              }

              // Launch an isolate in the MServer
              Properties p = new Properties();
              p.put("java.class.path",classpath);
              
              Isolate i = new OutOfProcessIsolate(
                      getIsolateStreamBindings(),
                      p,
                      vmArgs,
                      mainClass,
                      null);
              
              try {
                  i.start();
              }
              catch(IsolateStartupException e) {
                  System.out.println("Cannot launch isolate");
              }

              // Delay
              try {
                  Thread.currentThread().sleep(5000);
              }
              catch(InterruptedException e) {
                  // ignore
              }

              // Shutdown
              try {
                  Runtime.getRuntime().exec(haltcmd);
              }
              catch(IOException e) {
                  //ignore
              }

              // Wait for the MServer to fully shutdown
              try {
                  process.waitFor();
              }
              catch(InterruptedException e) {
                  //ignore
              }
          }

          /**
           * Setup the isolate stream bindings
           * @return
           */
          private StreamBindings getIsolateStreamBindings() {
              FileInputStream in = null;
              FileOutputStream out = null;
              FileOutputStream err = null;

              try {
                  in = new FileInputStream(FileDescriptor.in);
                  out = new FileOutputStream("app.out");
                  err = new FileOutputStream("app.err");
              }
              catch(FileNotFoundException e) {
                  // Ignore for now
              }

              StreamBindings streams = new StreamBindings();
              streams.setIn(in);
              streams.setOut(out);
              streams.setErr(err);

              return streams;
          }

          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              new StreamBuster();
          }
      }

            Unassigned Unassigned
            jmelvin James Melvin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: