com.sun.jdi.event.VMDeathEvent Java Examples

The following examples show how to use com.sun.jdi.event.VMDeathEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VMRemoteTarget.java    From gravel with Apache License 2.0 6 votes vote down vote up
private void eventLoop() throws InterruptedException {
	System.out.println("eventLoop started");
	EventQueue eventQueue = vm.eventQueue();
	boolean isRunning = true;
	while (isRunning) {
		EventSet eventSet = eventQueue.remove();
		boolean mayResume = true;
		for (Event event : eventSet) {
			System.out.println(event);
			if (event instanceof VMDeathEvent
					|| event instanceof VMDisconnectEvent) {
				isRunning = false;
			} else if (event instanceof ExceptionEvent) {
				mayResume = false;
			}
		}
		if (mayResume) eventSet.resume();
	}
}
 
Example #2
Source File: EventHub.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the observable object for vm events.
 * @return      the observable object for vm events
 */
@Override
public Observable<DebugEvent> vmEvents() {
    return this.events().filter(debugEvent -> debugEvent.event instanceof VMStartEvent
            || debugEvent.event instanceof VMDisconnectEvent
            || debugEvent.event instanceof VMDeathEvent);
}
 
Example #3
Source File: SetExceptionBreakpointsRequestHandler.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public synchronized CompletableFuture<Response> handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) {
    if (context.getDebugSession() == null) {
        return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.EMPTY_DEBUG_SESSION, "Empty debug session.");
    }

    if (!isInitialized) {
        isInitialized = true;
        debugSession = context.getDebugSession();
        DebugSettings.addDebugSettingChangeListener(this);
        debugSession.getEventHub().events().subscribe(debugEvent -> {
            if (debugEvent.event instanceof VMDeathEvent
                || debugEvent.event instanceof VMDisconnectEvent) {
                DebugSettings.removeDebugSettingChangeListener(this);
            }
        });
    }

    String[] filters = ((SetExceptionBreakpointsArguments) arguments).filters;
    try {
        this.notifyCaught = ArrayUtils.contains(filters, Types.ExceptionBreakpointFilter.CAUGHT_EXCEPTION_FILTER_NAME);
        this.notifyUncaught = ArrayUtils.contains(filters, Types.ExceptionBreakpointFilter.UNCAUGHT_EXCEPTION_FILTER_NAME);
        setExceptionBreakpoints(context.getDebugSession(), this.notifyCaught, this.notifyUncaught);
        return CompletableFuture.completedFuture(response);
    } catch (Exception ex) {
        throw AdapterUtils.createCompletionException(
            String.format("Failed to setExceptionBreakpoints. Reason: '%s'", ex.toString()),
            ErrorCode.SET_EXCEPTIONBREAKPOINT_FAILURE,
            ex);
    }
}
 
Example #4
Source File: DynamothCollector.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void processVMEvents() {
	try {
		// process events
		final EventQueue eventQueue = vm.eventQueue();
		while (true) {
			EventSet eventSet = eventQueue.remove(TimeUnit.SECONDS.toMillis(this.dataCollectionTimeoutInSeconds));
			if (eventSet == null)
				return; // timeout
			for (Event event : eventSet) {
				if (event instanceof VMDeathEvent || event instanceof VMDisconnectEvent) {
					// exit
					DebugJUnitRunner.process.destroy();
					// logger.debug("Exit");
					// System.out.println("VM Event: Exit");
					return;
				} else if (event instanceof ClassPrepareEvent) {
					// logger.debug("ClassPrepareEvent");
					// System.out.println("VM event: ClassPrepareEvent");
					processClassPrepareEvent();
				} else if (event instanceof BreakpointEvent) {
					// logger.debug("VM Event: BreakpointEvent");
					// System.out.println("VM BreakpointEvent");
					processBreakPointEvents((BreakpointEvent) event);
				}
			}
			eventSet.resume();
		} // end while true
	} catch (Exception e) {
		System.err.println("Error processing VMEvents");
		e.printStackTrace();
	} finally {
		DebugJUnitRunner.process.destroy();
	}
}
 
Example #5
Source File: FieldMonitor.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws IOException, InterruptedException {

  //VirtualMachine vm = launchTarget(sb.toString());
  VirtualMachine vm = launchTarget(CLASS_NAME);

  System.out.println("Vm launched");

  // process events
  EventQueue eventQueue = vm.eventQueue();
  // resume the vm

  Process process = vm.process();


  // Copy target's output and error to our output and error.
  Thread outThread = new StreamRedirectThread("out reader", process.getInputStream());
  Thread errThread = new StreamRedirectThread("error reader", process.getErrorStream());

  errThread.start();
  outThread.start();

  boolean connected = true;
  int watched = 0;
  while (connected) {
    EventSet eventSet = eventQueue.remove();
    for (Event event : eventSet) {
      System.out.println("FieldMonitor-main receives: "+event);
      if (event instanceof VMStartEvent) {
        addClassWatch(vm);
      } else if (event instanceof VMDeathEvent
          || event instanceof VMDisconnectEvent) {
        // exit
        connected = false;
      } else if (event instanceof ClassPrepareEvent) {
        // watch field on loaded class
        System.out.println("ClassPrepareEvent");
        ClassPrepareEvent classPrepEvent = (ClassPrepareEvent) event;
        ReferenceType refType = classPrepEvent
            .referenceType();
        addFieldWatch(vm, refType);
      } else if (event instanceof ModificationWatchpointEvent) {
        watched++;
        System.out.println("sleep for 500 ms");
        Thread.sleep(500);

        ModificationWatchpointEvent modEvent = (ModificationWatchpointEvent) event;
        System.out.println("old="
            + modEvent.valueCurrent());
        System.out.println("new=" + modEvent.valueToBe());
      }
    }
    System.out.println("resume...");
    eventSet.resume();
  }
  // Shutdown begins when event thread terminates
  try {
      errThread.join(); // Make sure output is forwarded
      outThread.join();
  } catch (InterruptedException exc) {
      // we don't interrupt
  }

  if (watched != 11) { // init + 10 modifications in TestPostFieldModification class
      throw new Error("Expected to receive 11 times ModificationWatchpointEvent, but got "+watched);
  }
}
 
Example #6
Source File: FieldMonitor.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws IOException, InterruptedException {

  //VirtualMachine vm = launchTarget(sb.toString());
  VirtualMachine vm = launchTarget(CLASS_NAME);

  System.out.println("Vm launched");

  // process events
  EventQueue eventQueue = vm.eventQueue();
  // resume the vm

  Process process = vm.process();


  // Copy target's output and error to our output and error.
  Thread outThread = new StreamRedirectThread("out reader", process.getInputStream());
  Thread errThread = new StreamRedirectThread("error reader", process.getErrorStream());

  errThread.start();
  outThread.start();

  boolean connected = true;
  int watched = 0;
  while (connected) {
    EventSet eventSet = eventQueue.remove();
    for (Event event : eventSet) {
      System.out.println("FieldMonitor-main receives: "+event);
      if (event instanceof VMStartEvent) {
        addClassWatch(vm);
      } else if (event instanceof VMDeathEvent
          || event instanceof VMDisconnectEvent) {
        // exit
        connected = false;
      } else if (event instanceof ClassPrepareEvent) {
        // watch field on loaded class
        System.out.println("ClassPrepareEvent");
        ClassPrepareEvent classPrepEvent = (ClassPrepareEvent) event;
        ReferenceType refType = classPrepEvent
            .referenceType();
        addFieldWatch(vm, refType);
      } else if (event instanceof ModificationWatchpointEvent) {
        watched++;
        System.out.println("sleep for 500 ms");
        Thread.sleep(500);

        ModificationWatchpointEvent modEvent = (ModificationWatchpointEvent) event;
        System.out.println("old="
            + modEvent.valueCurrent());
        System.out.println("new=" + modEvent.valueToBe());
      }
    }
    System.out.println("resume...");
    eventSet.resume();
  }
  // Shutdown begins when event thread terminates
  try {
      errThread.join(); // Make sure output is forwarded
      outThread.join();
  } catch (InterruptedException exc) {
      // we don't interrupt
  }

  if (watched != 11) { // init + 10 modifications in TestPostFieldModification class
      throw new Error("Expected to receive 11 times ModificationWatchpointEvent, but got "+watched);
  }
}
 
Example #7
Source File: FieldMonitor.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws IOException, InterruptedException {

  //VirtualMachine vm = launchTarget(sb.toString());
  VirtualMachine vm = launchTarget(CLASS_NAME);

  System.out.println("Vm launched");

  // process events
  EventQueue eventQueue = vm.eventQueue();
  // resume the vm

  Process process = vm.process();


  // Copy target's output and error to our output and error.
  Thread outThread = new StreamRedirectThread("out reader", process.getInputStream());
  Thread errThread = new StreamRedirectThread("error reader", process.getErrorStream());

  errThread.start();
  outThread.start();

  boolean connected = true;
  int watched = 0;
  while (connected) {
    EventSet eventSet = eventQueue.remove();
    for (Event event : eventSet) {
      System.out.println("FieldMonitor-main receives: "+event);
      if (event instanceof VMStartEvent) {
        addClassWatch(vm);
      } else if (event instanceof VMDeathEvent
          || event instanceof VMDisconnectEvent) {
        // exit
        connected = false;
      } else if (event instanceof ClassPrepareEvent) {
        // watch field on loaded class
        System.out.println("ClassPrepareEvent");
        ClassPrepareEvent classPrepEvent = (ClassPrepareEvent) event;
        ReferenceType refType = classPrepEvent
            .referenceType();
        addFieldWatch(vm, refType);
      } else if (event instanceof ModificationWatchpointEvent) {
        watched++;
        System.out.println("sleep for 500 ms");
        Thread.sleep(500);

        ModificationWatchpointEvent modEvent = (ModificationWatchpointEvent) event;
        System.out.println("old="
            + modEvent.valueCurrent());
        System.out.println("new=" + modEvent.valueToBe());
      }
    }
    System.out.println("resume...");
    eventSet.resume();
  }
  // Shutdown begins when event thread terminates
  try {
      errThread.join(); // Make sure output is forwarded
      outThread.join();
  } catch (InterruptedException exc) {
      // we don't interrupt
  }

  if (watched != 11) { // init + 10 modifications in TestPostFieldModification class
      throw new Error("Expected to receive 11 times ModificationWatchpointEvent, but got "+watched);
  }
}
 
Example #8
Source File: FieldMonitor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws IOException, InterruptedException {

  //VirtualMachine vm = launchTarget(sb.toString());
  VirtualMachine vm = launchTarget(CLASS_NAME);

  System.out.println("Vm launched");

  // process events
  EventQueue eventQueue = vm.eventQueue();
  // resume the vm

  Process process = vm.process();


  // Copy target's output and error to our output and error.
  Thread outThread = new StreamRedirectThread("out reader", process.getInputStream());
  Thread errThread = new StreamRedirectThread("error reader", process.getErrorStream());

  errThread.start();
  outThread.start();

  boolean connected = true;
  int watched = 0;
  while (connected) {
    EventSet eventSet = eventQueue.remove();
    for (Event event : eventSet) {
      System.out.println("FieldMonitor-main receives: "+event);
      if (event instanceof VMStartEvent) {
        addClassWatch(vm);
      } else if (event instanceof VMDeathEvent
          || event instanceof VMDisconnectEvent) {
        // exit
        connected = false;
      } else if (event instanceof ClassPrepareEvent) {
        // watch field on loaded class
        System.out.println("ClassPrepareEvent");
        ClassPrepareEvent classPrepEvent = (ClassPrepareEvent) event;
        ReferenceType refType = classPrepEvent
            .referenceType();
        addFieldWatch(vm, refType);
      } else if (event instanceof ModificationWatchpointEvent) {
        watched++;
        System.out.println("sleep for 500 ms");
        Thread.sleep(500);

        ModificationWatchpointEvent modEvent = (ModificationWatchpointEvent) event;
        System.out.println("old="
            + modEvent.valueCurrent());
        System.out.println("new=" + modEvent.valueToBe());
      }
    }
    System.out.println("resume...");
    eventSet.resume();
  }
  // Shutdown begins when event thread terminates
  try {
      errThread.join(); // Make sure output is forwarded
      outThread.join();
  } catch (InterruptedException exc) {
      // we don't interrupt
  }

  if (watched != 11) { // init + 10 modifications in TestPostFieldModification class
      throw new Error("Expected to receive 11 times ModificationWatchpointEvent, but got "+watched);
  }
}
 
Example #9
Source File: FieldMonitor.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
    throws IOException, InterruptedException {

  //VirtualMachine vm = launchTarget(sb.toString());
  VirtualMachine vm = launchTarget(CLASS_NAME);

  System.out.println("Vm launched");

  // process events
  EventQueue eventQueue = vm.eventQueue();
  // resume the vm

  Process process = vm.process();


  // Copy target's output and error to our output and error.
  Thread outThread = new StreamRedirectThread("out reader", process.getInputStream());
  Thread errThread = new StreamRedirectThread("error reader", process.getErrorStream());

  errThread.start();
  outThread.start();

  boolean connected = true;
  int watched = 0;
  while (connected) {
    EventSet eventSet = eventQueue.remove();
    for (Event event : eventSet) {
      System.out.println("FieldMonitor-main receives: "+event);
      if (event instanceof VMStartEvent) {
        addClassWatch(vm);
      } else if (event instanceof VMDeathEvent
          || event instanceof VMDisconnectEvent) {
        // exit
        connected = false;
      } else if (event instanceof ClassPrepareEvent) {
        // watch field on loaded class
        System.out.println("ClassPrepareEvent");
        ClassPrepareEvent classPrepEvent = (ClassPrepareEvent) event;
        ReferenceType refType = classPrepEvent
            .referenceType();
        addFieldWatch(vm, refType);
      } else if (event instanceof ModificationWatchpointEvent) {
        watched++;
        System.out.println("sleep for 500 ms");
        Thread.sleep(500);

        ModificationWatchpointEvent modEvent = (ModificationWatchpointEvent) event;
        System.out.println("old="
            + modEvent.valueCurrent());
        System.out.println("new=" + modEvent.valueToBe());
      }
    }
    System.out.println("resume...");
    eventSet.resume();
  }
  // Shutdown begins when event thread terminates
  try {
      errThread.join(); // Make sure output is forwarded
      outThread.join();
  } catch (InterruptedException exc) {
      // we don't interrupt
  }

  if (watched != 11) { // init + 10 modifications in TestPostFieldModification class
      throw new Error("Expected to receive 11 times ModificationWatchpointEvent, but got "+watched);
  }
}
 
Example #10
Source File: VMTargetStarter.java    From gravel with Apache License 2.0 4 votes vote down vote up
public VMRemoteTarget createJVM() throws IOException, InterruptedException,
		IncompatibleThreadStateException {
	Process process = startSecondJVM(VMLocalTarget.class);
	sleep(90);
	// connect
	VirtualMachine vm = new VMAcquirer().connect(debugPort);

	ClassPrepareRequest createClassPrepareRequest = vm
			.eventRequestManager().createClassPrepareRequest();
	createClassPrepareRequest.addClassFilter(VMLocalTarget.class.getName());
	createClassPrepareRequest.enable();
	
	vm.resume();

	List<ThreadReference> allThreads = vm.allThreads();
	for (ThreadReference threadReference : allThreads) {
		System.out.println(threadReference+" isSuspended: "+threadReference.isSuspended()+" suspendCount: "+threadReference.suspendCount());
	}

	// process events
	EventQueue eventQueue = vm.eventQueue();
	while (true) {
		EventSet eventSet = eventQueue.remove();
		for (Event event : eventSet) {
			if (event instanceof ClassPrepareEvent) {
				event.request().disable();
				installHaltPoint(vm);
			}
			if (event instanceof VMDeathEvent
					|| event instanceof VMDisconnectEvent) {
				return null;
			}
			if (event instanceof BreakpointEvent) {
				event.request().disable();
				ThreadReference thread = ((BreakpointEvent) event).thread();
				return new VMRemoteTarget(process, vm, thread, debugPort);
			}
		}
		eventSet.resume();
	}
}