<div dir="ltr">Hi Phil,<div><br></div><div>answers in-line.<br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Nov 27, 2013 at 1:34 PM, <a href="mailto:phil@highoctane.be">phil@highoctane.be</a> <span dir="ltr">&lt;<a href="mailto:phil@highoctane.be" target="_blank">phil@highoctane.be</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> <br><div dir="ltr"><span style="font-family:arial,sans-serif;font-size:12.666666984558105px">Hello,</span><div style="font-family:arial,sans-serif;font-size:12.666666984558105px">
<br></div><div style="font-family:arial,sans-serif;font-size:12.666666984558105px">

I gave it a shot based on the generator.image that PharoVM uses to generate the VM.</div><div style="font-family:arial,sans-serif;font-size:12.666666984558105px"><br></div><div style="font-family:arial,sans-serif;font-size:12.666666984558105px">


But none of :</div><div style="font-family:arial,sans-serif;font-size:12.666666984558105px"><br></div><div style="font-family:arial,sans-serif;font-size:12.666666984558105px"><div>(| vm |</div><div>vm := StackInterpreterSimulator newWithOptions: #().</div>


<div>vm openOn: &#39;/Users/eliot/Cog/startreader.image&#39;.</div><div>vm openAsMorph; run)</div><div><br></div><div>and</div><div><br></div><div>(| vm |</div><div>vm := CogVMSimulator newWithOptions: #(ObjectMemory Spur32BitCoMemoryManager</div>


<div><span style="white-space:pre-wrap">                                                                </span>Cogit StackToRegisterMappingCogit).</div><div>vm desiredNumStackPages: 8.</div><div>vm objectMemory setCheckForLeaks: 1.</div><div>vm openOn: &#39;/Users/eliot/Cog/spurreader.image&#39;.</div>


<div>vm openAsMorph; toggleTranscript; halt; run)</div><div><br></div><div>is going to work right away as newWithOptions: isn&#39;t there in that image.</div></div></div></blockquote><div><br></div><div>If you try and load e.g. VMMaker.oscog-eem.527 into a Squeak trunk image do you get further?  i.e. if you follow the instructions on <a href="http://www.mirandabanda.org/cogblog/build-image/">http://www.mirandabanda.org/cogblog/build-image/</a> do you get further?</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div style="font-family:arial,sans-serif;font-size:12.666666984558105px">
<div><span style="font-size:12.666666984558105px">So, there is a initializeWithOptions: #().</span><br></div>

<div><br></div><div>When trying out that one, I do get another error.</div><div><br></div><div>In fact, the initializeWithOptions: method is wrong:<br></div><div><br></div><div><div>initializeWithOptions: optionsDictionary</div>


<div><span style="white-space:pre-wrap">        </span>&quot;ObjectMemory initializeWithOptions: Dictionary new&quot;</div><div><br></div><div><span style="white-space:pre-wrap">        </span>self initBytesPerWord: (optionsDictionary at: #BytesPerWord ifAbsent: [4]).</div>


</div><div><br></div><div>...</div><div><br></div><div>the thing is doing #BytesPerWork ifAbsent: ... :-(</div><div><br></div><div>Of course, as #() is an Array an not a Dictionary.</div><div><br></div><div>So, I tried:</div>


<div><br></div><div><div>StackInterpreterSimulator initializeWithOptions: Dictionary new.</div><div>vm := StackInterpreterSimulator new.</div></div><div><br></div><div>Which got the ball rolling.</div><div><br></div><div>


But then, of course, same story as here:</div><div><br></div><div><a href="http://forum.world.st/Got-quot-Error-basicNew-failed-quot-when-running-InterpreterSimulator-td3835723.html" target="_blank">http://forum.world.st/Got-quot-Error-basicNew-failed-quot-when-running-InterpreterSimulator-td3835723.html</a><br>


</div><div><br></div><div><br></div><div>Well, based on Clement&#39;s comments, I fiddled a bit with the TranscriptStream, which I turned into a simple Transcript and let go of the local image name for the display window.</div>


<div><br></div><div>Also, did </div><div><br></div><div>transcript := Transcript.</div><div>displayForm := (ImageMorph fromString: &#39;Display has not yet been installed&#39;) form.</div><div><br></div><div>in StackInterpreterSimulator initialize.</div>


<div><br></div><div><br></div><div>So, here is the current stance:</div><div><br></div><div><div>| vm |</div><div>StackInterpreterSimulator initializeWithOptions: Dictionary new.</div><div>vm := StackInterpreterSimulator new.</div>


<div>vm openOn: &#39;C:\MinGW\msys\1.0\home\User\pharo\pharo.image&#39;.</div><div>vm openAsMorph.</div><div>vm run.</div></div><div><br></div><div><br></div><div>the morph opens.</div><div><br></div><div>Now, when I do run, I do get a problem in:</div>


<div><br></div><div>InterpreterStackPage&gt;&gt;headFP: pointer</div><div><br></div><div><br></div><div>There is an self assert: (pointer = 0 or: [pointer &lt; baseAddress and: [realStackLimit - (LargeContextBytes / 2) &lt;= pointer]]).</div>


<div><br></div><div>And LargeContextBytes is nil.</div><div><br></div><div>I looked around for initialization for that one.</div><div><br></div><div>It is only in the InterpreterStackPage class &gt;&gt; initialize</div></div>
</div></blockquote><div><br></div><div>Hmmm, that&#39;s an initialization order problem.  The code assumes LargeContextSize is initialized first.  It might not be.  I&#39;ve just changed the code so that it refers to LargeContextSize directly and I&#39;ve removed LargeContextBytes.  I recommend you do the same. </div>
<div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div style="font-family:arial,sans-serif;font-size:12.666666984558105px">
<div><span style="font-size:12.666666984558105px">So I did;</span><br></div><div><br></div><div><div>| vm |</div><div>StackInterpreterSimulator initializeWithOptions: Dictionary new.</div><div>vm := StackInterpreterSimulator new.</div>
<div>InterpreterStackPage initialize.</div>

<div>vm openOn: &#39;C:\MinGW\msys\1.0\home\User\pharo\pharo.image&#39;.</div><div>vm openAsMorph.</div><div>vm run.</div></div><div><br></div><div>Then I got a blinking square running in the top corner.</div><div><br></div>


<div>No amount of stopping processes would interrupt it.</div></div></div></blockquote><div><br></div><div>Use the process browser.  That is a good sign.  It is being produced by either StackInterpreterSimulator&gt;&gt;ioRelinquishProcessorForMicroseconds: or CogVMSimulator&gt;&gt;ioRelinquishProcessorForMicroseconds: and means the VM&#39;s idle process is running.  Looks like the system is working to some degree.</div>
<div><br></div><div>You&#39;ll probably find that a few plugin primitives are failing on start-up, and that the start-up sequence has tried to open a notifier before the GUi is initialized.  In this case I&#39;ve tried to either a) make the relevant primitives simulate correctly, or b) used an egregious hack to not perform certain initializations.  e.g. in this launch script the initializations of ObjectiveCAlien, ObjectiveCClass et al are not executed in the launch of a Newspeak image:</div>
<div><br></div><div><div>| cos |</div><div>cos := CogVMSimulator newWithOptions: #(NewspeakVM true MULTIPLEBYTECODESETS true Cogit StackToRegisterMappingCogit).</div><div>cos desiredNumStackPages: 8.</div><div>cos openOn: &#39;/Users/eliot/Newspeak/newsqueakV4/absentSendBug.image&#39;.</div>
<div>cos setBreakSelector: #testNewCompiler.</div><div>cos</div><div><span class="" style="white-space:pre">        </span>openAsMorph;</div><div><span class="" style="white-space:pre">        </span>&quot;toggleTranscript;&quot;</div>
<div><span class="" style="white-space:pre">        </span>forShortPrintString: &#39;class ObjectiveCAlien&#39; filterPerformMessages: #(startUp:);</div><div><span class="" style="white-space:pre">        </span>forShortPrintString: &#39;class ObjectiveCClass&#39; filterPerformMessages: #(startUp:);</div>
<div><span class="" style="white-space:pre">        </span>forShortPrintString: &#39;class BlackMarket&#39; filterPerformMessages: #(startUp:);</div><div><span class="" style="white-space:pre">        </span>forShortPrintString: &#39;class ThisOSProcess&#39; filterPerformMessages: #(startUp:);</div>
<div><span class="" style="white-space:pre">        </span>halt;</div><div><span class="" style="white-space:pre">        </span>run</div></div><div><br></div><div>This works by hacking perform in CogVMSimulator.  You&#39;ll have to port the code to StackInterpreterSimulator to get it to work there.</div>
<div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div style="font-family:arial,sans-serif;font-size:12.666666984558105px">
<div><span style="font-size:12.666666984558105px">So the simulator is running the run loop:</span><br></div><div><br></div><div><div>self fetchNextBytecode.</div><div><span style="white-space:pre-wrap">        </span>[true] whileTrue:</div>


<div><span style="white-space:pre-wrap">                </span>[self assertValidExecutionPointers.</div><div><span style="white-space:pre-wrap">                </span> atEachStepBlock value. &quot;N.B. may be nil&quot;</div><div><span style="white-space:pre-wrap">                </span> self dispatchOn: currentBytecode in: BytecodeTable.</div>


<div><span style="white-space:pre-wrap">                </span> self incrementByteCount].</div></div><div><br></div><div>and relinquishing processor every once in a while and this square is shown (Display reverse below] ...</div><div>

<br>
</div><div>(which is where I end up when interrupting)<br></div><div><br></div><div><div>ioRelinquishProcessorForMicroseconds: microseconds</div><div><span style="white-space:pre-wrap">        </span>&quot;In the simulator give an indication that we&#39;re idling and check for input.&quot;</div>


<div><span style="white-space:pre-wrap">        </span>Display reverse: (0@0 extent: 16@16).</div><div><span style="white-space:pre-wrap">        </span>Sensor peekEvent ifNotNil:</div><div><span style="white-space:pre-wrap">                </span>[self forceInterruptCheck].</div>


<div><span style="white-space:pre-wrap">        </span>Processor activeProcess == UIManager default uiProcess ifTrue:</div><div><span style="white-space:pre-wrap">                </span>[World doOneCycle].</div><div><span style="white-space:pre-wrap">        </span>microseconds &gt;= 1000</div>


<div><span style="white-space:pre-wrap">                </span>ifTrue: [(Delay forMilliseconds: microseconds + 999 // 1000) wait]</div><div><span style="white-space:pre-wrap">                </span>ifFalse: [Processor yield]</div></div><div><br></div>


<div>If one could tell me how to get the display to show, it would be welcome.</div><div><br></div><div>The display instVar contains stuff in the debugger but isn&#39;t ok to open with something like:</div><div><br></div>


<div>In the transcript, I do see things related to initialization:</div><div><br></div><div><div>(56) Looking for primitiveSetGCBiasToGrowGCLimit in vm</div><div>Looking for module  ... not found</div><div>(3751) Looking for primitiveFileWrite in FilePlugin</div>


<div>Looking for module FilePlugin</div><div>(3751) Looking for secCanCreatePathOfSize in SecurityPlugin</div><div>Looking for module SecurityPlugin ... loaded</div><div>(3751) Looking for secCanDeletePathOfSize in SecurityPlugin</div>


<div>(3751) Looking for secCanGetFileTypeOfSize in SecurityPlugin</div><div>(3751) Looking for secCanListPathOfSize in SecurityPlugin</div><div>(3751) Looking for secCanSetFileTypeOfSize in SecurityPlugin</div><div>(3751) Looking for secDisableFileAccess in SecurityPlugin</div>


<div>(3751) Looking for secCanDeleteFileOfSize in SecurityPlugin</div><div>(3751) Looking for secCanOpenFileOfSizeWritable in SecurityPlugin</div><div>(3751) Looking for secCanRenameFileOfSize in SecurityPlugin</div><div>


(3751) Looking for secHasFileAccess in SecurityPlugin ... loaded</div><div>(3774) Looking for primitiveFileSize in FilePlugin</div><div>(4390) Looking for primitiveCompareString in MiscPrimitivePlugin</div><div>Looking for module MiscPrimitivePlugin ... loaded</div>


<div>(4623) Looking for primitiveDirectoryDelimitor in FilePlugin</div><div>(7806) Looking for primitiveIndexOfAsciiInString in MiscPrimitivePlugin</div><div>(57216) Looking for primitiveStringHash in MiscPrimitivePlugin</div>


<div>(177977) Looking for primitiveFindFirstInString in MiscPrimitivePlugin</div><div>(179055) Looking for primitiveFileOpen in FilePlugin</div><div>(179815) Looking for primitiveFileGetPosition in FilePlugin</div><div>(179832) Looking for primitiveFileAtEnd in FilePlugin</div>


<div>(179873) Looking for primitiveFileRead in FilePlugin</div><div>(182837) Looking for primitiveFileSize in FilePlugin</div><div>(182868) Looking for primitiveFileSetPosition in FilePlugin</div><div>(186627) Looking for primDigitCompare in LargeIntegers</div>


<div>Looking for module LargeIntegers ... loaded</div><div>(186688) Looking for primDigitMultiplyNegative in LargeIntegers</div><div>(186884) Looking for primNormalizeNegative in LargeIntegers</div><div>(186985) Looking for primDigitAdd in LargeIntegers</div>


<div>(186986) Looking for primNormalizePositive in LargeIntegers</div><div>(187038) Looking for primDigitSubtract in LargeIntegers</div></div></div></div></blockquote><div><br></div><div>This is great.  The system&#39;s working.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div style="font-family:arial,sans-serif;font-size:12.666666984558105px">
<div><span style="font-size:12.666666984558105px">Is there a way to stop the interpreter in order to debug things?</span><br></div></div></div></blockquote><div><br></div><div>Lots of ways.</div><div>1. put a halt before &quot;run&quot;, and interact with the VM via the bottom right simulator window&#39;s utilities menu to</div>
<div>     a) set a bytecode breakpoint</div><div>     b) set a selector breakpoint</div><div><br></div><div>2. add or modify methods in the interpreter simulators (StackInterpreterSimulator, CogVMSimulator) or memory simulators (NewObjectMemorySimualtor, NewCoObjectMemorySimulator) to add conditional breakpoints.  e.g. comment-out and modify</div>
<div><br></div><div><div>longAt: byteAddress put: a32BitValue</div><div><span class="" style="white-space:pre">        </span>&quot;Note: Adjusted for Smalltalk&#39;s 1-based array indexing.&quot;</div><div><span class="" style="white-space:pre">        </span>&quot;(byteAddress = 16r183FB00 and: [a32BitValue = 16r3FFFFC]) ifTrue:</div>
<div><span class="" style="white-space:pre">                </span>[self halt].&quot;</div><div><span class="" style="white-space:pre">        </span>&quot;(byteAddress between: 16r33FBB8 and: 16r33FBCF) ifTrue:</div><div><span class="" style="white-space:pre">                </span>[self halt].&quot;</div>
<div><span class="" style="white-space:pre">        </span>byteAddress \\ 4 ~= 0 ifTrue: [self unalignedAccessError].</div><div><span class="" style="white-space:pre">        </span>^memory at: byteAddress // 4 + 1 put: a32BitValue</div>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div style="font-family:arial,sans-serif;font-size:12.666666984558105px">


<div><br></div><div>I saw: runAtEachStep: aBlock</div><div><span style="white-space:pre-wrap">        </span>self initStackPages.</div><div><span style="white-space:pre-wrap">        </span>self loadInitialContext.</div><div><span style="white-space:pre-wrap">        </span>self internalizeIPandSP.</div>


<div><span style="white-space:pre-wrap">        </span>self fetchNextBytecode.</div><div><span style="white-space:pre-wrap">        </span>[true] whileTrue:</div><div><span style="white-space:pre-wrap">                </span>[self assertValidExecutionPointers.</div>


<div><span style="white-space:pre-wrap">                </span> aBlock value: currentBytecode.</div><div><span style="white-space:pre-wrap">                </span> self dispatchOn: currentBytecode in: BytecodeTable.</div><div><span style="white-space:pre-wrap">                </span> self incrementByteCount].</div>


<div><span style="white-space:pre-wrap">        </span>localIP := localIP - 1.</div><div><span style="white-space:pre-wrap">        </span>&quot;undo the pre-increment of IP before returning&quot;</div><div><span style="white-space:pre-wrap">        </span>self externalizeIPandSP</div>


<div><br></div><div>How to use that?</div></div></div></blockquote><div><br></div><div>You can use the block to do what you want, e.g. collect bytecode stats, compare the stream of bytecodes in a buggy VM with those from a correct VM to find out where they diverge, etc.  But &quot;run&quot; uses the atEachStepBlock, and that is used to implement breakpoints at specific bytecodes or bytecode counts, etc.  See utlitiesMenu: in the interpreter simulators.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div style="font-family:arial,sans-serif;font-size:12.666666984558105px">
<div><span style="font-size:12.666666984558105px">Why do I not see the display in the sim?</span></div></div></div></blockquote><div><br></div><div>Dunno.  That you have to fix.  It works in Squeak.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div style="font-family:arial,sans-serif;font-size:12.666666984558105px"><div><span style="font-size:12.666666984558105px">I saw a &quot;quitBlock&quot;. What is this about?</span></div></div></div></blockquote>
<div><br></div><div>It connects the exit routines such as ioExit, ioExitWithErrorCode: to closing of the simulator window.  Browse inst var refs.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div style="font-family:arial,sans-serif;font-size:12.666666984558105px"><div><span style="font-size:12.666666984558105px">I am not far from getting this working...</span></div></div></div></blockquote><div>
<br></div><div>Indeed.  In fact it is already working to a large extent.  Stick with it, you;re nearly there.  Good luck!</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div style="font-family:arial,sans-serif;font-size:12.666666984558105px"><div><br></div>

<div><br></div><div>Thanks for some clues!</div><div><br></div><div>Phil</div></div><div><div dir="ltr"><div>---</div><div>Philippe Back</div><div>Dramatic Performance Improvements</div><div>Mob: <a href="tel:%2B32%280%29%20478%20650%20140" value="+32478650140" target="_blank">+32(0) 478 650 140</a> | Fax: <a href="tel:%2B32%20%280%29%2070%20408%20027" value="+3270408027" target="_blank">+32 (0) 70 408 027</a></div>


<div><a href="mailto:Mail%3Aphil@highoctane.be" target="_blank">Mail:phil@highoctane.be</a> | Web: <a href="http://philippeback.eu" target="_blank">http://philippeback.eu</a></div><div>Blog: <a href="http://philippeback.be" target="_blank">http://philippeback.be</a> | Twitter: @philippeback</div>


<div>Youtube: <a href="http://www.youtube.com/user/philippeback/videos" target="_blank">http://www.youtube.com/user/philippeback/videos</a></div><div><br></div><div>High Octane SPRL</div><div>rue cour Boisacq 101 | 1301 Bierges | Belgium</div>


<div><br></div><div>Pharo Consortium Member - <a href="http://consortium.pharo.org/" target="_blank">http://consortium.pharo.org/</a></div><div>Featured on the Software Process and Measurement Cast - <a href="http://spamcast.libsyn.com" target="_blank">http://spamcast.libsyn.com</a><br>


</div><div>Sparx Systems Enterprise Architect and Ability Engineering EADocX Value Added Reseller</div><div> </div><div><br></div></div></div>
</div>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div>
</div></div></div>