test/runtime/7158988/FieldMonitor.java

Print this page

        

*** 32,58 **** */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; - import java.io.OutputStream; - import java.io.OutputStreamWriter; - import java.io.Reader; - import java.io.Writer; import java.util.Iterator; import java.util.List; import java.util.Map; import com.sun.jdi.Bootstrap; import com.sun.jdi.Field; import com.sun.jdi.ReferenceType; import com.sun.jdi.VirtualMachine; import com.sun.jdi.connect.Connector; import com.sun.jdi.connect.IllegalConnectorArgumentsException; import com.sun.jdi.connect.LaunchingConnector; import com.sun.jdi.connect.VMStartException; import com.sun.jdi.event.ClassPrepareEvent; import com.sun.jdi.event.Event; import com.sun.jdi.event.EventQueue; import com.sun.jdi.event.EventSet; import com.sun.jdi.event.ModificationWatchpointEvent; import com.sun.jdi.event.VMDeathEvent; --- 32,56 ---- */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Iterator; import java.util.List; import java.util.Map; + import java.io.PrintWriter; import com.sun.jdi.Bootstrap; import com.sun.jdi.Field; import com.sun.jdi.ReferenceType; import com.sun.jdi.VirtualMachine; import com.sun.jdi.connect.Connector; import com.sun.jdi.connect.IllegalConnectorArgumentsException; import com.sun.jdi.connect.LaunchingConnector; import com.sun.jdi.connect.VMStartException; import com.sun.jdi.event.ClassPrepareEvent; + import com.sun.jdi.event.VMStartEvent; import com.sun.jdi.event.Event; import com.sun.jdi.event.EventQueue; import com.sun.jdi.event.EventSet; import com.sun.jdi.event.ModificationWatchpointEvent; import com.sun.jdi.event.VMDeathEvent;
*** 69,108 **** public static final String ARGUMENTS = "-Xshare:off -XX:+PrintGC"; public static void main(String[] args) throws IOException, InterruptedException { ! StringBuffer sb = new StringBuffer(); ! for (int i=0; i < args.length; i++) { ! sb.append(' '); ! sb.append(args[i]); } - //VirtualMachine vm = launchTarget(sb.toString()); - VirtualMachine vm = launchTarget(CLASS_NAME); System.out.println("Vm launched"); ! // set watch field on already loaded classes ! List<ReferenceType> referenceTypes = vm ! .classesByName(CLASS_NAME); ! for (ReferenceType refType : referenceTypes) { ! addFieldWatch(vm, refType); ! } // watch for loaded classes addClassWatch(vm); // 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(); vm.resume(); --- 67,108 ---- public static final String ARGUMENTS = "-Xshare:off -XX:+PrintGC"; public static void main(String[] args) throws IOException, InterruptedException { ! VirtualMachine vm = launchTarget(CLASS_NAME); ! EventQueue eventQueue = vm.eventQueue(); ! // make sure the vm is started ! boolean started = false; ! while(!started) { ! EventSet eventSet = eventQueue.remove(); ! for (Event event : eventSet) { ! if (event instanceof VMStartEvent) { ! started = true; ! } ! if (event instanceof VMDeathEvent ! || event instanceof VMDisconnectEvent) { ! throw new Error("VM died before it started...:"+event); ! } ! } } System.out.println("Vm launched"); ! // watch for loaded classes addClassWatch(vm); // process events 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()); + PrintWriter vmPrinter = null; errThread.start(); outThread.start(); vm.resume();
*** 119,128 **** --- 119,135 ---- System.out.println("ClassPrepareEvent"); ClassPrepareEvent classPrepEvent = (ClassPrepareEvent) event; ReferenceType refType = classPrepEvent .referenceType(); addFieldWatch(vm, refType); + + // inform TestPostFieldModification that it can exit. // JDK-8007710 + if (vmPrinter == null) { + vmPrinter = new PrintWriter(process.getOutputStream()); + vmPrinter.println(""); + vmPrinter.flush(); + } } else if (event instanceof ModificationWatchpointEvent) { System.out.println("sleep for 500 ms"); Thread.sleep(500); System.out.println("resume...");