<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><br></div><div class="gmail_quote">On 7 August 2018 at 19:47, Ben Coman <span dir="ltr"><<a href="mailto:btc@openinworld.com" target="_blank">btc@openinworld.com</a>></span> wrote:</div><div class="gmail_quote">

<div class="gmail_quote" style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">></div><div class="gmail_quote" style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">> <span> </span><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">it gets stuck the following loop... <span> </span></span><a href="https://github.com/bencoman/opensmalltalk-vm/blob/8231b96f9b/platforms/win32/vm/sqWin32SpurAlloc.c#L139-L183" target="_blank" style="color:rgb(17,85,204);font-size:12.8px;background-color:rgb(255,255,255)">https://github.com/bencoman/<wbr>opensmalltalk-vm/blob/<wbr>8231b96f9b/platforms/win32/vm/<wbr>sqWin32SpurAlloc.c#L139-L183</a></div><div class="gmail_quote" style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></div><div class="gmail_quote" style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">whoops, that was meant to be the minheadless file....</div><div class="gmail_quote" style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><a href="https://github.com/bencoman/opensmalltalk-vm/blob/8231b96f9b/platforms/minheadless/windows/sqWin32SpurAlloc.c#L140-L184">https://github.com/bencoman/opensmalltalk-vm/blob/8231b96f9b/platforms/minheadless/windows/sqWin32SpurAlloc.c#L140-L184</a></div><br class="gmail-Apple-interchange-newline">

<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>In the meantime, I'll forge ahead to play with  osvm_run();</div></div></div></div></blockquote><div><br></div><div>I've hardly used Visual Studio before, and never combined with CMake,</div><div>so I'll record a few things I discover in case others might find it interesting or advise a better way.</div><div><br></div><div><br></div><div>To try with the Stack Interpreter first, in CMakeLists.txt changed...</div><div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">    option(COG_JIT "Cog JIT" ON)</div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">to...</div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">    option(COG_JIT "Cog JIT" OFF)</div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">then cleared the cache... Right-clicked on "CMakeLists.txt > Cache(x64-Debug only) > Delete cache folder..."</div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">otherwise it didn't seem to pick up that change.</div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">To give the VM an image to run and something to do... </div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">Right-clicked on "<span style="font-size:12.8px">CMakeLists.tx<wbr>t > Debug and Launch Settings > pharo.exe"</span></div><div style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><div style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">then edited the presented "launch.vs.json" as follows...</div><div style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><div style="font-size:12.8px">{</div><div style="font-size:12.8px">  "version": "0.2.1",</div><div style="font-size:12.8px">  "defaults": {},</div><div style="font-size:12.8px">  "configurations": [</div><div style="font-size:12.8px">    {</div><div style="font-size:12.8px">      "type": "default",</div><div style="font-size:12.8px">      "project": "CMakeLists.txt",</div><div style="font-size:12.8px">      "projectTarget": "pharo.exe (dist\\pharo.exe)",</div><div style="font-size:12.8px">      "name": "pharo.exe minImage+eval (dist\\pharo.exe)",</div><div style="font-size:12.8px">      "args": [</div><div style="font-size:12.8px">        "C:\\#Dev\\latest-minimal-64\\<wbr>Pharo7.0-metacello-64bit-65cff<wbr>7b.image eval 19 + 23",</div><div style="font-size:12.8px">      ]</div><div style="font-size:12.8px">    },</div><div style="font-size:12.8px">  ]</div><div style="font-size:12.8px">}</div></div>

</span></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">

<div style="text-decoration-style:initial;text-decoration-color:initial">Then... "CMake > Build All"  </div><div style="text-decoration-style:initial;text-decoration-color:initial">followed by starting... "x64-Debug" with "pharo.exe minImage+eval"</div><div style="text-decoration-style:initial;text-decoration-color:initial">which opened a console window that doesn't do much besides output like this...</div>

<span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">GIV(remapBufferCount) == 0 47923</span>

<br class="gmail-Apple-interchange-newline">

<br></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">

<div style="text-decoration-style:initial;text-decoration-color:initial">Now I notice the file "dist\stderr" says...</div><div style="text-decoration-style:initial;text-decoration-color:initial">    "Your VM is too old for this image. Please download the latest VM."<br></div><div style="text-decoration-style:initial;text-decoration-color:initial">so probably I need to run "scripts\updateSCCSVersions"</div><div style="text-decoration-style:initial;text-decoration-color:initial">but thats a shell script.  How to run it under Windows?</div>

<br></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">

<div style="text-decoration-style:initial;text-decoration-color:initial">Luckily my installed Git Windows has Git Bash which opens a cygwin environment.</div><div style="text-decoration-style:initial;text-decoration-color:initial">where I do...</div><div style="text-decoration-style:initial;text-decoration-color:initial">   cd /c/#Repos/OpenSmalltalk/opensmalltalk-vm/</div><div style="text-decoration-style:initial;text-decoration-color:initial">   ./scripts/<span> </span><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">updateSCCSVersions</span></div>

<br></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">

<div style="text-decoration-style:initial;text-decoration-color:initial">Now to give a bit more visibility to program execution, </div><div style="text-decoration-style:initial;text-decoration-color:initial">in "spurstack64src/interp.c" I inserted the following into main interpreter loop...</div><div style="text-decoration-style:initial;text-decoration-color:initial"><div style="text-decoration-style:initial;text-decoration-color:initial"><div><span style="white-space:pre-wrap"><br></span></div><div><span style="white-space:pre-wrap">"+"  </span>unsigned long long debugCountBytecode = 0;</div><div><span style="white-space:pre-wrap">       </span>while (1) {</div><div><span style="white-space:pre-wrap">"+"         </span>debugCountBytecode += 1;</div><div><span style="white-space:pre-wrap">"+"            </span>if ((debugCountBytecode % 100000 == 0))</div><div><span style="white-space:pre-wrap">"+"             </span>{</div><div><span style="white-space:pre-wrap">"+"                   </span>printf("%llu\n", debugCountBytecode);</div><div><span style="white-space:pre-wrap">"+"             </span>}</div></div></div><br class="gmail-Apple-interchange-newline"></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">Then... "CMake > Build All"  </div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">followed by starting... "x64-Debug" with "pharo.exe minImage+eval"</div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">which opened a console window with the following output...</div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">GIV(remapBufferCount) == 0 47923<br></div><div style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><div>GIV(remapBufferCount) == 0 42469</div><div>100000</div><div>200000</div><div>300000</div><div>400000</div><div>500000</div><div>600000</div><div>700000</div><div>800000</div><div>900000</div><div>1000000</div><div>1100000</div><div>1200000</div><div>1300000</div><div>1400000</div><div>1500000</div><div><br></div><div>and updated contents of these files... yay!</div><div>    dist\stderr ==> #'EvaluateCommandLineHandler successfully finished'</div><div>    dist\stdout ==> 42</div></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">However the VM/Image keeps running.  

<span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Adding "--quit" to the command line didn't help.</span>

</div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">I'm not really familiar with the command line handlers. </div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">

<span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Doing... "Debug > Break All"</span>

<br></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">

<div style="text-decoration-style:initial;text-decoration-color:initial">bring me up some warnings like... </div><div style="text-decoration-style:initial;text-decoration-color:initial">  "winmm.pdb not loaded"</div><div style="text-decoration-style:initial;text-decoration-color:initial">  "winmm.pdb contains the debug information required to find the source for the module winmm.dll"</div><div style="text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="text-decoration-style:initial;text-decoration-color:initial">Never heard of a PDB, but loaded them by following these instructions...</div><div style="text-decoration-style:initial;text-decoration-color:initial">   "Specify Symbol (.pdb) and Source Files in the Visual Studio Debugger"</div><div style="text-decoration-style:initial;text-decoration-color:initial">   <a href="https://msdn.microsoft.com/en-us/library/ms241613.aspx" target="_blank" style="color:rgb(17,85,204)">https://msdn.microsoft.com/<wbr>en-us/library/ms241613.aspx</a><br></div><div style="text-decoration-style:initial;text-decoration-color:initial">and learnt a lot more about them...</div><div style="text-decoration-style:initial;text-decoration-color:initial">  "PDB Files: What Every Developer Must Know"</div><div style="text-decoration-style:initial;text-decoration-color:initial">  <a href="https://www.wintellect.com/pdb-files-what-every-developer-must-know/" target="_blank" style="color:rgb(17,85,204)">https://www.wintellect.com/<wbr>pdb-files-what-every-<wbr>developer-must-know/</a></div><div style="text-decoration-style:initial;text-decoration-color:initial">Now the next few times I started... 

<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">"x64-Debug" with "pharo.exe minImage+eval"</span>

</div><div style="text-decoration-style:initial;text-decoration-color:initial">it got hung up downloading the symbols.  I had to terminate & restart debugging it a few times</div><div style="text-decoration-style:initial;text-decoration-color:initial">as it progressed a bit each time. <br></div><div style="text-decoration-style:initial;text-decoration-color:initial"><br></div></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">When finally got running again and after 

<span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">1500000</span> printed I did... 

<span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">"Debug > Break All"</span><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span> </span></span>

</div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">and... "Debug > Windows > Threads" and now it shows the proper names rather than just addresses...</div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><div><img src="cid:ii_jkl4v8eg2_165199839decd29e" width="472" height="107"><br></div><br></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">A little surprised by the number of threads.</div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">No clue what ntdll.dll!NtWaitForWorkViaWorkerFactory </div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">or winmm.dll!timeThread are, but leave that for later.</div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></div>Now with all thread stopped, trying... "Debug > Windows > Parallel Stacks"... </div><div><div><div><img src="cid:ii_jkkodn6q1_16517f1a305e63ae" width="472" height="372"><br></div><br></div>shows the two application threads are "in external code" </div><div>invoked from  ioRelinquishProcessorForMicroseconds()  and  beatThreadStateMachine(). </div><div>Clicking on each of those displays their source code indicating the "external code"</div><div>for each is  MsgWaitForMultipleObjects()  and  WaitForSingleObject()  

<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">respectively<span> </span></span>

.</div><div><br></div><div>Its very easy to flip back and forth between the two application threads,</div><div>stepping-out of the "external code" with Shift-F11, to observe a tiny window of VM operation. </div><div><br></div><div>Well thats enough for one post!  </div><div>Success running a MSVC compiled Spur Stack "minheadless" VM.</div><div><br></div><div>Next I'll try... 

<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">  option(COG_JIT "Cog JIT" ON)</span>

</div><div><br></div><div>cheers -ben</div><div><br></div><div><br></div><div>P.S.  Definitions for the curious...</div><div><div><br></div><div>sqInt</div><div>ioRelinquishProcessorForMicroseconds(sqInt microSeconds)</div><div>{</div><div>    /* wake us up if something happens */</div><div>    ResetEvent(vmWakeUpEvent);</div><div>    MsgWaitForMultipleObjects(1, &vmWakeUpEvent, FALSE, microSeconds / 1000, QS_ALLINPUT);</div><div>    ioProcessEvents(); /* keep up with mouse moves etc. */</div><div>    return microSeconds;</div><div>}</div></div><div><br></div><div><br></div><div><div>static DWORD WINAPI</div><div>beatThreadStateMachine(void *careLess)</div><div>{</div><div><span style="white-space:pre">       </span>beatThreadState = active;</div><div><span style="white-space:pre">     </span>while (beatThreadState != condemned) {</div><div><span style="white-space:pre">                </span>DWORD res = WaitForSingleObject(beatSemaphore, beatThreadState == active ? beatMilliseconds : INFINITE);</div><div><span style="white-space:pre">              </span>if (res == WAIT_TIMEOUT)</div><div><span style="white-space:pre">                      </span>heartbeat();</div><div><span style="white-space:pre">          </span>else if (res == WAIT_FAILED)</div><div><span style="white-space:pre">                  </span>abortMessage(TEXT("Fatal: WaitForSingleObject(beatSemaphore) %ld"), GetLastError());</div><div><span style="white-space:pre">                </span>else</div><div><span style="white-space:pre">                  </span>printLastError(TEXT("beatThreadStateMachine WaitForSingleObject"));</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre">     </span>beatThreadState = dead;</div><div><span style="white-space:pre">       </span>return 0;</div><div>}</div></div><div><br></div><div><br></div></div></div></div>