| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e5833e8 commit aa2db6b
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,6 +47,9 @@ public class JavaEditor extends Editor { | |||
| 47 | 47 | // Runner associated with this editor window | |
| 48 | 48 | private Runner runtime; | |
| 49 | 49 | ||
| 50 | + private boolean runtimeLaunchRequested; | ||
| 51 | + private final Object runtimeLock = new Object[0]; | ||
| 52 | + | ||
| 50 | 53 | // Need to sort through the rest of these additions [fry] | |
| 51 | 54 | ||
| 52 | 55 | protected final List<LineHighlight> breakpointedLines = new ArrayList<>(); | |
@@ -1057,57 +1060,48 @@ public void handleRun() { | |||
| 1057 | 1060 | debugger.continueDebug(); | |
| 1058 | 1061 | ||
| 1059 | 1062 | } else { | |
| 1060 | - prepareRun(); | ||
| 1061 | - toolbar.activateRun(); | ||
| 1062 | - new Thread(new Runnable() { | ||
| 1063 | - public void run() { | ||
| 1064 | - try { | ||
| 1065 | - //runtime = jmode.handleRun(sketch, JavaEditor.this); | ||
| 1066 | - runtime = jmode.handleLaunch(sketch, JavaEditor.this, false); | ||
| 1067 | - } catch (Exception e) { | ||
| 1068 | - EventQueue.invokeLater(() -> statusError(e)); | ||
| 1069 | - } | ||
| 1070 | - } | ||
| 1071 | - }).start(); | ||
| 1063 | + handleLaunch(false, false); | ||
| 1072 | 1064 | } | |
| 1073 | 1065 | } | |
| 1074 | 1066 | ||
| 1075 | 1067 | ||
| 1076 | 1068 | public void handlePresent() { | |
| 1077 | - prepareRun(); | ||
| 1078 | - toolbar.activateRun(); | ||
| 1079 | - new Thread(new Runnable() { | ||
| 1080 | - public void run() { | ||
| 1081 | - try { | ||
| 1082 | - //runtime = jmode.handlePresent(sketch, JavaEditor.this); | ||
| 1083 | - runtime = jmode.handleLaunch(sketch, JavaEditor.this, true); | ||
| 1084 | - } catch (Exception e) { | ||
| 1085 | - EventQueue.invokeLater(() -> statusError(e)); | ||
| 1086 | - } | ||
| 1087 | - } | ||
| 1088 | - }).start(); | ||
| 1069 | + handleLaunch(true, false); | ||
| 1089 | 1070 | } | |
| 1090 | 1071 | ||
| 1091 | 1072 | ||
| 1092 | 1073 | public void handleTweak() { | |
| 1093 | - prepareRun(); | ||
| 1094 | - //toolbar.activate(JavaToolbar.RUN); | ||
| 1095 | - toolbar.activateRun(); | ||
| 1074 | + autoSave(); | ||
| 1096 | 1075 | ||
| 1097 | 1076 | if (sketch.isModified()) { | |
| 1098 | - toolbar.deactivateRun(); | ||
| 1099 | 1077 | Messages.showMessage(Language.text("menu.file.save"), | |
| 1100 | 1078 | Language.text("tweak_mode.save_before_tweak")); | |
| 1101 | 1079 | return; | |
| 1102 | 1080 | } | |
| 1103 | 1081 | ||
| 1104 | - new Thread(new Runnable() { | ||
| 1105 | - public void run() { | ||
| 1106 | - try { | ||
| 1107 | - runtime = jmode.handleTweak(sketch, JavaEditor.this); | ||
| 1108 | - } catch (Exception e) { | ||
| 1109 | - EventQueue.invokeLater(() -> statusError(e)); | ||
| 1082 | + handleLaunch(false, true); | ||
| 1083 | + } | ||
| 1084 | + | ||
| 1085 | + protected void handleLaunch(boolean present, boolean tweak) { | ||
| 1086 | + prepareRun(); | ||
| 1087 | + toolbar.activateRun(); | ||
| 1088 | + synchronized (runtimeLock) { | ||
| 1089 | + runtimeLaunchRequested = true; | ||
| 1090 | + } | ||
| 1091 | + new Thread(() -> { | ||
| 1092 | + try { | ||
| 1093 | + synchronized (runtimeLock) { | ||
| 1094 | + if (runtimeLaunchRequested) { | ||
| 1095 | + runtimeLaunchRequested = false; | ||
| 1096 | + if (!tweak) { | ||
| 1097 | + runtime = jmode.handleLaunch(sketch, JavaEditor.this, present); | ||
| 1098 | + } else { | ||
| 1099 | + runtime = jmode.handleTweak(sketch, JavaEditor.this); | ||
| 1100 | + } | ||
| 1101 | + } | ||
| 1110 | 1102 | } | |
| 1103 | + } catch (Exception e) { | ||
| 1104 | + EventQueue.invokeLater(() -> statusError(e)); | ||
| 1111 | 1105 | } | |
| 1112 | 1106 | }).start(); | |
| 1113 | 1107 | } | |
@@ -1122,23 +1116,24 @@ public void handleStop() { | |||
| 1122 | 1116 | debugger.stopDebug(); | |
| 1123 | 1117 | ||
| 1124 | 1118 | } else { | |
| 1125 | - // toolbar.activate(JavaToolbar.STOP); | ||
| 1126 | 1119 | toolbar.activateStop(); | |
| 1127 | 1120 | ||
| 1128 | 1121 | try { | |
| 1129 | - //jmode.handleStop(); | ||
| 1130 | - if (runtime != null) { | ||
| 1131 | - runtime.close(); // kills the window | ||
| 1132 | - runtime = null; | ||
| 1133 | - // } else { | ||
| 1134 | - // System.out.println("runtime is null"); | ||
| 1122 | + synchronized (runtimeLock) { | ||
| 1123 | + if (runtimeLaunchRequested) { | ||
| 1124 | + // Cancel the launch before the runtime was created | ||
| 1125 | + runtimeLaunchRequested = false; | ||
| 1126 | + } | ||
| 1127 | + if (runtime != null) { | ||
| 1128 | + // Cancel the launch after the runtime was created | ||
| 1129 | + runtime.close(); // kills the window | ||
| 1130 | + runtime = null; | ||
| 1131 | + } | ||
| 1135 | 1132 | } | |
| 1136 | 1133 | } catch (Exception e) { | |
| 1137 | 1134 | statusError(e); | |
| 1138 | 1135 | } | |
| 1139 | 1136 | ||
| 1140 | - // toolbar.deactivate(JavaToolbar.RUN); | ||
| 1141 | - // toolbar.deactivate(JavaToolbar.STOP); | ||
| 1142 | 1137 | toolbar.deactivateStop(); | |
| 1143 | 1138 | toolbar.deactivateRun(); | |
| 1144 | 1139 | ||
@@ -1171,8 +1166,10 @@ public void handleContinue() { | |||
| 1171 | 1166 | ||
| 1172 | 1167 | ||
| 1173 | 1168 | public void onRunnerExiting(Runner runner) { | |
| 1174 | - if (this.runtime == runner) { | ||
| 1175 | - deactivateRun(); | ||
| 1169 | + synchronized (runtimeLock) { | ||
| 1170 | + if (this.runtime == runner) { | ||
| 1171 | + deactivateRun(); | ||
| 1172 | + } | ||
| 1176 | 1173 | } | |
| 1177 | 1174 | } | |
| 1178 | 1175 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,7 +61,7 @@ public class Runner implements MessageConsumer { | |||
| 61 | 61 | protected RunnerListener listener; | |
| 62 | 62 | ||
| 63 | 63 | // Running remote VM | |
| 64 | - protected VirtualMachine vm; | ||
| 64 | + protected volatile VirtualMachine vm; | ||
| 65 | 65 | protected boolean vmReturnedError; | |
| 66 | 66 | ||
| 67 | 67 | // Thread transferring remote error stream to our error stream | |
@@ -78,6 +78,9 @@ public class Runner implements MessageConsumer { | |||
| 78 | 78 | protected PrintStream sketchErr; | |
| 79 | 79 | protected PrintStream sketchOut; | |
| 80 | 80 | ||
| 81 | + protected volatile boolean cancelled; | ||
| 82 | + protected final Object cancelLock = new Object[0]; | ||
| 83 | + | ||
| 81 | 84 | ||
| 82 | 85 | public Runner(JavaBuild build, RunnerListener listener) throws SketchException { | |
| 83 | 86 | this.listener = listener; | |
@@ -218,6 +221,13 @@ public boolean launchVirtualMachine(boolean present, String[] args) { | |||
| 218 | 221 | ||
| 219 | 222 | commandArgs.append(vmParams); | |
| 220 | 223 | commandArgs.append(sketchParams); | |
| 224 | + | ||
| 225 | + // Opportunistically quit if the launch was cancelled, | ||
| 226 | + // the next chance to cancel will be after connecting to the VM | ||
| 227 | + if (cancelled) { | ||
| 228 | + return false; | ||
| 229 | + } | ||
| 230 | + | ||
| 221 | 231 | launchJava(commandArgs.array()); | |
| 222 | 232 | ||
| 223 | 233 | AttachingConnector connector = (AttachingConnector) | |
@@ -249,7 +259,15 @@ public boolean launchVirtualMachine(boolean present, String[] args) { | |||
| 249 | 259 | while (true) { | |
| 250 | 260 | try { | |
| 251 | 261 | Messages.log(getClass().getName() + " attempting to attach to VM"); | |
| 252 | - vm = connector.attach(arguments); | ||
| 262 | + synchronized (cancelLock) { | ||
| 263 | + vm = connector.attach(arguments); | ||
| 264 | + if (cancelled && vm != null) { | ||
| 265 | + // cancelled and connected to the VM, handle closing now | ||
| 266 | + Messages.log(getClass().getName() + " aborting, launch cancelled"); | ||
| 267 | + close(); | ||
| 268 | + return false; | ||
| 269 | + } | ||
| 270 | + } | ||
| 253 | 271 | // vm = connector.attach(arguments); | |
| 254 | 272 | if (vm != null) { | |
| 255 | 273 | Messages.log(getClass().getName() + " attached to the VM"); | |
@@ -523,29 +541,28 @@ protected void generateTrace() { | |||
| 523 | 541 | //vm.setDebugTraceMode(debugTraceMode); | |
| 524 | 542 | // vm.setDebugTraceMode(VirtualMachine.TRACE_ALL); | |
| 525 | 543 | // vm.setDebugTraceMode(VirtualMachine.TRACE_NONE); // formerly, seems to have no effect | |
| 526 | - | ||
| 527 | - // Calling this seems to set something internally to make the | ||
| 528 | - // Eclipse JDI wake up. Without it, an ObjectCollectedException | ||
| 529 | - // is thrown on excReq.enable(). No idea why this works, | ||
| 530 | - // but at least exception handling has returned. (Suspect that it may | ||
| 531 | - // block until all or at least some threads are available, meaning | ||
| 532 | - // that the app has launched and we have legit objects to talk to). | ||
| 533 | - vm.allThreads(); | ||
| 534 | - // The bug may not have been noticed because the test suite waits for | ||
| 535 | - // a thread to be available, and queries it by calling allThreads(). | ||
| 536 | - // See org.eclipse.debug.jdi.tests.AbstractJDITest for the example. | ||
| 537 | - | ||
| 538 | - EventRequestManager mgr = vm.eventRequestManager(); | ||
| 539 | - // get only the uncaught exceptions | ||
| 540 | - ExceptionRequest excReq = mgr.createExceptionRequest(null, false, true); | ||
| 541 | - // System.out.println(excReq); | ||
| 542 | - // this version reports all exceptions, caught or uncaught | ||
| 543 | - // ExceptionRequest excReq = mgr.createExceptionRequest(null, true, true); | ||
| 544 | - // suspend so we can step | ||
| 545 | - excReq.setSuspendPolicy(EventRequest.SUSPEND_ALL); | ||
| 546 | - // excReq.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); | ||
| 547 | - // excReq.setSuspendPolicy(EventRequest.SUSPEND_NONE); // another option? | ||
| 548 | - excReq.enable(); | ||
| 544 | + try { | ||
| 545 | + // Calling this seems to set something internally to make the | ||
| 546 | + // Eclipse JDI wake up. Without it, an ObjectCollectedException | ||
| 547 | + // is thrown on excReq.enable(). No idea why this works, | ||
| 548 | + // but at least exception handling has returned. (Suspect that it may | ||
| 549 | + // block until all or at least some threads are available, meaning | ||
| 550 | + // that the app has launched and we have legit objects to talk to). | ||
| 551 | + vm.allThreads(); | ||
| 552 | + // The bug may not have been noticed because the test suite waits for | ||
| 553 | + // a thread to be available, and queries it by calling allThreads(). | ||
| 554 | + // See org.eclipse.debug.jdi.tests.AbstractJDITest for the example. | ||
| 555 | + | ||
| 556 | + EventRequestManager mgr = vm.eventRequestManager(); | ||
| 557 | + // get only the uncaught exceptions | ||
| 558 | + ExceptionRequest excReq = mgr.createExceptionRequest(null, false, true); | ||
| 559 | + // this version reports all exceptions, caught or uncaught | ||
| 560 | + // suspend so we can step | ||
| 561 | + excReq.setSuspendPolicy(EventRequest.SUSPEND_ALL); | ||
| 562 | + excReq.enable(); | ||
| 563 | + } catch (VMDisconnectedException ignore) { | ||
| 564 | + return; | ||
| 565 | + } | ||
| 549 | 566 | ||
| 550 | 567 | Thread eventThread = new Thread() { | |
| 551 | 568 | public void run() { | |
@@ -851,19 +868,22 @@ protected SketchException findException(String message, ObjectReference or, Thre | |||
| 851 | 868 | ||
| 852 | 869 | ||
| 853 | 870 | public void close() { | |
| 854 | - // TODO make sure stop() has already been called to exit the sketch | ||
| 871 | + synchronized (cancelLock) { | ||
| 872 | + cancelled = true; | ||
| 873 | + | ||
| 874 | + // TODO make sure stop() has already been called to exit the sketch | ||
| 855 | 875 | ||
| 856 | - // TODO actually kill off the vm here | ||
| 857 | - if (vm != null) { | ||
| 858 | - try { | ||
| 859 | - vm.exit(0); | ||
| 876 | + // TODO actually kill off the vm here | ||
| 877 | + if (vm != null) { | ||
| 878 | + try { | ||
| 879 | + vm.exit(0); | ||
| 860 | 880 | ||
| 861 | - } catch (com.sun.jdi.VMDisconnectedException vmde) { | ||
| 862 | - // if the vm has disconnected on its own, ignore message | ||
| 863 | - //System.out.println("harmless disconnect " + vmde.getMessage()); | ||
| 864 | - // TODO shouldn't need to do this, need to do more cleanup | ||
| 881 | + } catch (com.sun.jdi.VMDisconnectedException vmde) { | ||
| 882 | + // if the vm has disconnected on its own, ignore message | ||
| 883 | + //System.out.println("harmless disconnect " + vmde.getMessage()); | ||
| 884 | + // TODO shouldn't need to do this, need to do more cleanup | ||
| 885 | + } | ||
| 865 | 886 | } | |
| 866 | - vm = null; | ||
| 867 | 887 | } | |
| 868 | 888 | } | |
| 869 | 889 | ||
@@ -884,7 +904,9 @@ synchronized public void message(String s) { | |||
| 884 | 904 | if (editor != null) { | |
| 885 | 905 | // editor.internalCloseRunner(); // [091124] | |
| 886 | 906 | // editor.handleStop(); // prior to 0192 | |
| 887 | - editor.internalCloseRunner(); // 0192 | ||
| 907 | + java.awt.EventQueue.invokeLater(() -> { | ||
| 908 | + editor.internalCloseRunner(); // 0192 | ||
| 909 | + }); | ||
| 888 | 910 | } | |
| 889 | 911 | return; | |
| 890 | 912 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments