Sun, 15 Apr 2012 15:37:20 -0700
Merge
1.1 --- a/src/share/vm/runtime/thread.cpp Thu Apr 12 18:41:24 2012 -0400 1.2 +++ b/src/share/vm/runtime/thread.cpp Sun Apr 15 15:37:20 2012 -0700 1.3 @@ -3468,13 +3468,13 @@ 1.4 create_vm_init_libraries(); 1.5 } 1.6 1.7 + // Notify JVMTI agents that VM initialization is complete - nop if no agents. 1.8 + JvmtiExport::post_vm_initialized(); 1.9 + 1.10 if (!TRACE_START()) { 1.11 vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION)); 1.12 } 1.13 1.14 - // Notify JVMTI agents that VM initialization is complete - nop if no agents. 1.15 - JvmtiExport::post_vm_initialized(); 1.16 - 1.17 if (CleanChunkPoolAsync) { 1.18 Chunk::start_chunk_pool_cleaner_task(); 1.19 }
2.1 --- a/test/runtime/7158988/TestPostFieldModification.java Thu Apr 12 18:41:24 2012 -0400 2.2 +++ b/test/runtime/7158988/TestPostFieldModification.java Sun Apr 15 15:37:20 2012 -0700 2.3 @@ -21,229 +21,38 @@ 2.4 * questions. 2.5 */ 2.6 2.7 -/* 2.8 - * @test FieldMonitor.java 2.9 - * @bug 7158988 2.10 - * @summary verify jvm does not crash while debugging 2.11 - * @run shell TestFieldMonitor.sh 2.12 - * @author axel.siebenborn@sap.com 2.13 - */ 2.14 -import java.io.BufferedReader; 2.15 -import java.io.IOException; 2.16 -import java.io.InputStream; 2.17 -import java.io.InputStreamReader; 2.18 -import java.io.OutputStream; 2.19 -import java.io.OutputStreamWriter; 2.20 -import java.io.Reader; 2.21 -import java.io.Writer; 2.22 -import java.util.Iterator; 2.23 -import java.util.List; 2.24 -import java.util.Map; 2.25 +public class TestPostFieldModification { 2.26 2.27 -import com.sun.jdi.Bootstrap; 2.28 -import com.sun.jdi.Field; 2.29 -import com.sun.jdi.ReferenceType; 2.30 -import com.sun.jdi.VirtualMachine; 2.31 -import com.sun.jdi.connect.Connector; 2.32 -import com.sun.jdi.connect.IllegalConnectorArgumentsException; 2.33 -import com.sun.jdi.connect.LaunchingConnector; 2.34 -import com.sun.jdi.connect.VMStartException; 2.35 -import com.sun.jdi.event.ClassPrepareEvent; 2.36 -import com.sun.jdi.event.Event; 2.37 -import com.sun.jdi.event.EventQueue; 2.38 -import com.sun.jdi.event.EventSet; 2.39 -import com.sun.jdi.event.ModificationWatchpointEvent; 2.40 -import com.sun.jdi.event.VMDeathEvent; 2.41 -import com.sun.jdi.event.VMDisconnectEvent; 2.42 -import com.sun.jdi.request.ClassPrepareRequest; 2.43 -import com.sun.jdi.request.EventRequest; 2.44 -import com.sun.jdi.request.EventRequestManager; 2.45 -import com.sun.jdi.request.ModificationWatchpointRequest; 2.46 + public String value; // watch modification of value 2.47 2.48 -public class FieldMonitor { 2.49 + public static void main(String[] args){ 2.50 2.51 - public static final String CLASS_NAME = "TestPostFieldModification"; 2.52 - public static final String FIELD_NAME = "value"; 2.53 - public static final String ARGUMENTS = "-Xshare:off -XX:+PrintGC"; 2.54 - 2.55 - public static void main(String[] args) 2.56 - throws IOException, InterruptedException { 2.57 - 2.58 - StringBuffer sb = new StringBuffer(); 2.59 - 2.60 - for (int i=0; i < args.length; i++) { 2.61 - sb.append(' '); 2.62 - sb.append(args[i]); 2.63 - } 2.64 - //VirtualMachine vm = launchTarget(sb.toString()); 2.65 - VirtualMachine vm = launchTarget(CLASS_NAME); 2.66 - 2.67 - System.out.println("Vm launched"); 2.68 - // set watch field on already loaded classes 2.69 - List<ReferenceType> referenceTypes = vm 2.70 - .classesByName(CLASS_NAME); 2.71 - for (ReferenceType refType : referenceTypes) { 2.72 - addFieldWatch(vm, refType); 2.73 - } 2.74 - // watch for loaded classes 2.75 - addClassWatch(vm); 2.76 - 2.77 - // process events 2.78 - EventQueue eventQueue = vm.eventQueue(); 2.79 - // resume the vm 2.80 - 2.81 - Process process = vm.process(); 2.82 - 2.83 - 2.84 - // Copy target's output and error to our output and error. 2.85 - Thread outThread = new StreamRedirectThread("out reader", process.getInputStream()); 2.86 - Thread errThread = new StreamRedirectThread("error reader", process.getErrorStream()); 2.87 - 2.88 - errThread.start(); 2.89 - outThread.start(); 2.90 - 2.91 - 2.92 - vm.resume(); 2.93 - boolean connected = true; 2.94 - while (connected) { 2.95 - EventSet eventSet = eventQueue.remove(); 2.96 - for (Event event : eventSet) { 2.97 - if (event instanceof VMDeathEvent 2.98 - || event instanceof VMDisconnectEvent) { 2.99 - // exit 2.100 - connected = false; 2.101 - } else if (event instanceof ClassPrepareEvent) { 2.102 - // watch field on loaded class 2.103 - System.out.println("ClassPrepareEvent"); 2.104 - ClassPrepareEvent classPrepEvent = (ClassPrepareEvent) event; 2.105 - ReferenceType refType = classPrepEvent 2.106 - .referenceType(); 2.107 - addFieldWatch(vm, refType); 2.108 - } else if (event instanceof ModificationWatchpointEvent) { 2.109 - System.out.println("sleep for 500 ms"); 2.110 - Thread.sleep(500); 2.111 - System.out.println("resume..."); 2.112 - 2.113 - ModificationWatchpointEvent modEvent = (ModificationWatchpointEvent) event; 2.114 - System.out.println("old=" 2.115 - + modEvent.valueCurrent()); 2.116 - System.out.println("new=" + modEvent.valueToBe()); 2.117 - System.out.println(); 2.118 + System.out.println("Start threads"); 2.119 + // this thread modifies the field 'value' 2.120 + new Thread() { 2.121 + TestPostFieldModification test = new TestPostFieldModification(); 2.122 + public void run() { 2.123 + test.value="test"; 2.124 + for(int i = 0; i < 10; i++) { 2.125 + test.value += new String("_test"); 2.126 } 2.127 } 2.128 - eventSet.resume(); 2.129 - } 2.130 - // Shutdown begins when event thread terminates 2.131 - try { 2.132 - errThread.join(); // Make sure output is forwarded 2.133 - outThread.join(); 2.134 - } catch (InterruptedException exc) { 2.135 - // we don't interrupt 2.136 - } 2.137 - } 2.138 + }.start(); 2.139 2.140 - /** 2.141 - * Find a com.sun.jdi.CommandLineLaunch connector 2.142 - */ 2.143 - static LaunchingConnector findLaunchingConnector() { 2.144 - List <Connector> connectors = Bootstrap.virtualMachineManager().allConnectors(); 2.145 - Iterator <Connector> iter = connectors.iterator(); 2.146 - while (iter.hasNext()) { 2.147 - Connector connector = iter.next(); 2.148 - if (connector.name().equals("com.sun.jdi.CommandLineLaunch")) { 2.149 - return (LaunchingConnector)connector; 2.150 + // this thread is used to trigger a gc 2.151 + Thread d = new Thread() { 2.152 + public void run() { 2.153 + while(true) { 2.154 + try { 2.155 + Thread.sleep(100); 2.156 + } catch (InterruptedException e) { 2.157 + 2.158 + } 2.159 + System.gc(); 2.160 + } 2.161 } 2.162 - } 2.163 - throw new Error("No launching connector"); 2.164 - } 2.165 - /** 2.166 - * Return the launching connector's arguments. 2.167 - */ 2.168 - static Map <String,Connector.Argument> connectorArguments(LaunchingConnector connector, String mainArgs) { 2.169 - Map<String,Connector.Argument> arguments = connector.defaultArguments(); 2.170 - for (String key : arguments.keySet()) { 2.171 - System.out.println(key); 2.172 - } 2.173 - 2.174 - Connector.Argument mainArg = (Connector.Argument)arguments.get("main"); 2.175 - if (mainArg == null) { 2.176 - throw new Error("Bad launching connector"); 2.177 - } 2.178 - mainArg.setValue(mainArgs); 2.179 - 2.180 - Connector.Argument optionsArg = (Connector.Argument)arguments.get("options"); 2.181 - if (optionsArg == null) { 2.182 - throw new Error("Bad launching connector"); 2.183 - } 2.184 - optionsArg.setValue(ARGUMENTS); 2.185 - return arguments; 2.186 - } 2.187 - 2.188 - static VirtualMachine launchTarget(String mainArgs) { 2.189 - LaunchingConnector connector = findLaunchingConnector(); 2.190 - Map arguments = connectorArguments(connector, mainArgs); 2.191 - try { 2.192 - return (VirtualMachine) connector.launch(arguments); 2.193 - } catch (IOException exc) { 2.194 - throw new Error("Unable to launch target VM: " + exc); 2.195 - } catch (IllegalConnectorArgumentsException exc) { 2.196 - throw new Error("Internal error: " + exc); 2.197 - } catch (VMStartException exc) { 2.198 - throw new Error("Target VM failed to initialize: " + 2.199 - exc.getMessage()); 2.200 - } 2.201 -} 2.202 - 2.203 - 2.204 - private static void addClassWatch(VirtualMachine vm) { 2.205 - EventRequestManager erm = vm.eventRequestManager(); 2.206 - ClassPrepareRequest classPrepareRequest = erm 2.207 - .createClassPrepareRequest(); 2.208 - classPrepareRequest.addClassFilter(CLASS_NAME); 2.209 - classPrepareRequest.setEnabled(true); 2.210 - } 2.211 - 2.212 - 2.213 - private static void addFieldWatch(VirtualMachine vm, 2.214 - ReferenceType refType) { 2.215 - EventRequestManager erm = vm.eventRequestManager(); 2.216 - Field field = refType.fieldByName(FIELD_NAME); 2.217 - ModificationWatchpointRequest modificationWatchpointRequest = erm 2.218 - .createModificationWatchpointRequest(field); 2.219 - modificationWatchpointRequest.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); 2.220 - modificationWatchpointRequest.setEnabled(true); 2.221 + }; 2.222 + d.setDaemon(true); 2.223 + d.start(); 2.224 } 2.225 } 2.226 - 2.227 -class StreamRedirectThread extends Thread { 2.228 - 2.229 - private final BufferedReader in; 2.230 - 2.231 - private static final int BUFFER_SIZE = 2048; 2.232 - 2.233 - /** 2.234 - * Set up for copy. 2.235 - * @param name Name of the thread 2.236 - * @param in Stream to copy from 2.237 - * @param out Stream to copy to 2.238 - */ 2.239 - StreamRedirectThread(String name, InputStream in) { 2.240 - super(name); 2.241 - this.in = new BufferedReader(new InputStreamReader(in)); 2.242 - } 2.243 - 2.244 - /** 2.245 - * Copy. 2.246 - */ 2.247 - public void run() { 2.248 - try { 2.249 - String line; 2.250 - while ((line = in.readLine ()) != null) { 2.251 - System.out.println ("testvm: " + line); 2.252 - } 2.253 - System.out.flush(); 2.254 - } catch(IOException exc) { 2.255 - System.err.println("Child I/O Transfer - " + exc); 2.256 - } 2.257 - } 2.258 -}