Package com.sun.jdi

Examples of com.sun.jdi.VirtualMachine


    new Thread(this).start();
    stageHandler.handle(new WrappedPipedOutputStream(new PipedOutputStream(pipedIn)), new PipedInputStream(pos), parameters);
  }
 
  public void run() {
    VirtualMachine vm = communicationClass.virtualMachine();
    try {
      Location interceptIn = ((Method)communicationClass.methodsByName("interceptIn").get(0)).locationOfCodeIndex(2);
      Location interceptOut = ((Method)communicationClass.methodsByName("interceptOut").get(0)).locationOfCodeIndex(2);
      BreakpointRequest req =  vm.eventRequestManager().createBreakpointRequest(interceptIn);
      req.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
      req.setEnabled(true);
      req = vm.eventRequestManager().createBreakpointRequest(interceptOut);
      req.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
      req.setEnabled(true);
      final com.sun.jdi.event.EventQueue q = vm.eventQueue();
      boolean done = false;
      errorStream.println("== Handling I/O events...");
      while (true) {
        final EventSet es;
        if (!done) {
          es = q.remove();
        } else {
          es = q.remove(1000);
          if (es == null) {
            break;
          }
        }
        for (final EventIterator ei = es.eventIterator(); ei.hasNext();) {
          final Event e = ei.nextEvent();
          if (!done && e instanceof BreakpointEvent) {
            final BreakpointEvent be = (BreakpointEvent) e;
            final Location loc = be.location();
            final ThreadReference tr = be.thread()
            if (loc.equals(interceptIn)) {
              LocalVariable result = (LocalVariable) loc.method().variablesByName("result").get(0);
              LocalVariable buffer = (LocalVariable) loc.method().arguments().get(0);
              ArrayReference buf = (ArrayReference) tr.frame(0).getValue(buffer);
              new InputInterceptHandler(tr, buf, result).start();
            } else if (loc.equals(interceptOut)) {
              LocalVariable result = (LocalVariable) loc.method().variablesByName("result").get(0);
              LocalVariable data = (LocalVariable) loc.method().arguments().get(0);
              ArrayReference buf = (ArrayReference) tr.frame(0).getValue(data);
              List values = buf.getValues();
              byte[] temp = new byte[buf.length()];
              for (int i = 0; i < temp.length; i++) {
                temp[i] = ((ByteValue)values.get(i)).byteValue();
              }
              pipedOut.write(temp);
              pipedOut.flush();
              if (temp.length == 0) {
                pipedOut.close();
                pipedIn.close();
                done = true;
              }
              tr.frame(0).setValue(result, vm.mirrorOf(true));
              tr.resume();
            } else {
              throw new RuntimeException("Unknown location: "+loc);
           
          } else {
            System.out.println("== Unknown event received: " + e.toString());
            es.resume();
          }
        }
      }
    }
    catch(Throwable t) {
      t.printStackTrace(errorStream);
    }
    vm.dispose();
  }
View Full Code Here


        else if ("dt_shmem".equals(transport)) {
            ((Connector.Argument)args.get("name")).setValue(address);
        }

        try {
            VirtualMachine vm = connector.attach(args);
            return vm;
        }
        catch (IllegalConnectorArgumentsException e) {
            System.err.println("failed to attach to VM (" + transport + ", " + address + "):");
            e.printStackTrace();
View Full Code Here

     *
     * @param jdwp
     * @throws Exception
     */
    public void resume(Map jdwp) throws Exception {
        VirtualMachine vm = connect(jdwp);
        if (vm != null) {
            vm.resume();
            vm.dispose();
        }
    }
View Full Code Here

     *
     * @param jdwp
     * @throws Exception
     */
    public void info(Map jdwp) throws Exception {
        VirtualMachine vm = connect(jdwp);
        if (vm != null) {
            System.out.println("java.vm.name = " + vm.name());
            System.out.println("java.version = " + vm.version());
            System.out.println(vm.description());
            vm.resume();
            vm.dispose();
        }
    }
View Full Code Here

     * @param jdwp
     * @throws Exception
     */
    public void hotswap(Map jdwp) throws Exception {
        // @todo check it works at runtime not suspended
        VirtualMachine vm = ClassLoaderPatcher.hotswapClassLoader(
                System.getProperty(ProcessStarter.CL_PRE_PROCESSOR_CLASSNAME_PROPERTY, org.codehaus.aspectwerkz.hook.impl.ClassLoaderPreProcessorImpl.class.getName()),
                (String)jdwp.get(TRANSPORT_JDWP), (String)jdwp.get(ADDRESS_JDWP));
        if (vm != null) {
            vm.resume();
            vm.dispose();
        }
    }
View Full Code Here

                secondsToWait = Integer.parseInt(System.getProperty(CONNECTION_WAIT_PROPERTY, "0"));
            }
            catch (NumberFormatException nfe) {
                ;
            }
            VirtualMachine vm = ClassLoaderPatcher.hotswapClassLoader(clp, starter.getTransport(), starter.getAddress(), secondsToWait);
            if (vm == null) {
                process.destroy();
            }
            else {
                vm.resume();
                vm.dispose();
            }
        }

        // attach VM other streams to this streams
        redirectOtherStreams();
View Full Code Here

                    ;
                }
            }
            // loop 10 times, during 5 sec max. It appears some VM under Linux take time to accept connections
            // this avoid to specifically set -Daspectwerkz.classloader.wait
            VirtualMachine vm = null;
            ConnectException vmConnectionRefused = new ConnectException("should not appear as is");
            for (int retry = 0; retry < 10; retry++) {
                try {
                    vm = connector.attach(args);
                    break;
View Full Code Here

            try {
                secondsToWait = Integer.parseInt(System.getProperty(CONNECTION_WAIT_PROPERTY, "0"));
            } catch (NumberFormatException nfe) {
                ;
            }
            VirtualMachine vm = ClassLoaderPatcher.hotswapClassLoader(clp, starter.getTransport(), starter.getAddress(), secondsToWait);
            if (vm == null) {
                process.destroy();
            } else {
              vm.resume();
              vm.dispose();
      }
        }

        // attach VM other streams to this streams
        redirectOtherStreams();
View Full Code Here

            if (secondsToWait > 0) {
                try { Thread.sleep(1000*secondsToWait); } catch (Exception e) { ; }
            }
            // loop 10 times, during 5 sec max. It appears some VM under Linux take time to accept connections
            // this avoid to specifically set -Daspectwerkz.classloader.wait
            VirtualMachine vm = null;
            ConnectException vmConnectionRefused = new ConnectException("should not appear as is");
            for (int retry=0; retry<10; retry++) {
                try {
                    vm = connector.attach(args);
                    break;
View Full Code Here

        } else if ("dt_shmem".equals(transport)) {
            ((Connector.Argument)args.get("name")).setValue(address);
        }

        try {
            VirtualMachine vm = connector.attach(args);
            return vm;
        } catch (IllegalConnectorArgumentsException e) {
            System.err.println("failed to attach to VM ("+transport+", "+address+"):");
            e.printStackTrace();
            for (Iterator i = e.argumentNames().iterator(); i.hasNext();) {
View Full Code Here

TOP

Related Classes of com.sun.jdi.VirtualMachine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.