<div dir="ltr">Hi Hannes,<div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 23, 2018 at 4:15 AM, H. Hirzel <span dir="ltr"><<a href="mailto:hannes.hirzel@gmail.com" target="_blank">hannes.hirzel@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hello<br>
<br>
this is a follow up mail on loading a project file (*.pr) saved in<br>
Squeak 3.10.2 [1] into Squeak 6.0a-#18000  [2]<br>
<br>
The code breaks at<br>
<br>
    ImageSegmentLoader>>readObject [3]<br>
<br>
I'd like to find out which class causes this problem.<br>
<br>
<br>
readObject<br>
        | header oop nWords class format |<br>
        header := self readUint32.<br>
        (header bitAnd: HeaderTypeMask) caseOf: {<br>
                [HeaderTypeSizeAndClass] -><br>
                        [nWords := header >> 2. class := self readUint32. header := self readUint32].<br>
                [HeaderTypeClass] -><br>
<br>
<br>
The header is a 32 bit integer denoting the class, I assume.<br>
I'd like to know which class causes the problem.<br>
<br>
How can I find out which class this 32 bit integer refers to?<br></blockquote><div><br></div><div>There are three header formats, selected by a two bit field, the fourth value identifying free objects, and hence never seen in an image segment.  The formats are</div><div><br></div><div>HeaderTypeSizeAndClass (0) The header is three words; the first is a size field, the second is the class up, and the third is the header (containing format, GC bits, etc)<br></div><div><br></div><div>HeaderTypeClass (1) The header is two words; the first is the class oop, the second is the header (containing format, GC bits, etc, and in this case a 6 bit word size field)</div><div><br></div><div>(HeaderTypeFree (2))</div><div><br></div><div>HeaderTypeShort (3): The header is one word, being the header including a 5 bit field (31 bitShift: 12) that is a zero-relative index into an array of 32 possible compact classes that in pre-Spur Squeaks are held in Smalltalk compactClasses.  In ImageSegmentLoader they are in CompactClasses, initialized in the class-side initialize method.  I would be willing to bet real money that this is the kind of header that is failing, and that the issue is missing compact classes such as MethodProperties.<br></div><div><br></div><div>Here's the layout of the header word in all three cases (taken from ObjectMemory's class comment in the VMMaker/VMMaker.oscog package):</div><div><br></div><div><div><span class="gmail-Apple-tab-span" style="white-space:pre">MSB</span><span style="white-space:pre">     3 bits  reserved for gc (mark, root, unused)</span></div></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">               12 bits object hash (for HashSets)
                5 bits  compact class index
                4 bits  object format
                6 bits  object size in 32-bit words
LSB:    2 bits  header type (0: 3-word, 1: 2-word, 2: forbidden, 3: 1-word)
</span></div><div><span class="gmail-Apple-tab-span" style="white-space:pre"><br></span></div><div><br></div><div>Here's the initialization of CompactClasses from ImageSegmentLoader class>>initialize:</div><div><br></div><div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>CompactClasses := {CompiledMethod. nil. Array. nil.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">            </span>LargePositiveInteger. Float. MethodDictionary. Association.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">            </span>Point. Rectangle. ByteString. nil.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">             </span>nil "was BlockContext; needs special handling". Context. nil. Bitmap. </div><div><span class="gmail-Apple-tab-span" style="white-space:pre">              </span>nil. nil. nil. nil. nil. nil. nil. nil. nil. nil. nil. nil. nil. nil. nil}.</div></div><div><br></div><div>Looking at the V39 sources I can't see an initialization of the compactClassesArray; recreateSpecialObjectsArray simply copies the existing compactClassesArray.  Each image can have its own compact classes (Behavior>>becomeCompact).  Therefore there has to be a copy of the compact classes array saved in the image segment.  I can see traces of this but don't know how the code works.  Look for compactClassesArray in the 3.9/3.10 sources and you may be able to find where the compact classes are in an image segment.</div><div><br></div><div>Once you've located the compact classes you'll have to decide how to handle the mapping.  The most important two things that have changed from 3.10 to Spur are</div><div><br></div><div>1. the bytecode set and block implementation; 3.10 used Smalltalk-80 style non-reentrant BlockContexts; as of Cog (4.0? 4.1?) we moved to reentrant BlockClosure, where MethodContext (now Context) is used for block and method activations.  There are 6 new byte codes used to implement closures; see the class comment of EncoderForV3PlusClosures</div><div><br></div><div>2. 3.10 had an instance of MethodProperties as the penultimate literal in all methods.  As of Cog (but this has nothing to do with the VM) methods either have a selector in the penultimate literal, or an instance of AdditionalMethodState (if the method has a pragma or properties), hence saving considerable space.</div><div><br></div><div><br></div><div>To map from BlockContext to BlockClosure you'll have to revive the decompiler for pre-closure bytecodes, decompile the block's method, recompile to closure byte codes, and map PCs and temp vars appropriately.  This isn't easy in general, but it is possible, at least in theory, and simple blocks may be simple (e.g. blocks that only take arguments).  (Think about the problem as you would in understanding how the Debugger maps from a context's pc and temporary variables to its display of the currently executing expression, and the temporary variables and back.  At least in 4.0 and/or 4.1 we had the pc/variable mapping system working for both, and we still have remnants of this; see DebuggerMethodMap's two subclasses, DebuggerMethodMapForBlueBookMethods & DebuggerMethodMapForClosureCompiledMethods.  You should be able to use these to perform the mapping.</div><div><br></div><div>To map from MethodProperties to AdditionalMethodState in a CompiledMethod is essentially trivial.  See if the MethodProperties has only a selector and then simply use the selector in place of the MethodProperties.  If there are additional properties, create an equivalent AdditionalMethodState, copying across the properties, and use that in place of the MethodProperties.</div><div><br></div><div>This is low-level enough that you may want to pair or at least consult with myself or Bert.  I was the one who wrought all this change.  I apologise for the severe inconvenience, but the current relative performance between Cog and the 3.10 interpreter in part depends on these changes.</div><div><br></div><div><br></div><div>HTH</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
Regards<br>
<br>
Hannes<br>
<br>
<br>
------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>--------<br>
<br>
[1] The project file has a workspace in it in addition to some<br>
RectangleMorphs and SimpleButtonMorphs which were loaded succesfully<br>
in another test.<br>
<br>
<a href="http://forum.world.st/The-Trunk-Morphic-kfr-1435-mcz-tp5077266p5077476.html" rel="noreferrer" target="_blank">http://forum.world.st/The-<wbr>Trunk-Morphic-kfr-1435-mcz-<wbr>tp5077266p5077476.html</a><br>
The reference has a test project *.pr file attached.<br>
<br>
[2]<br>
<a href="http://lists.squeakfoundation.org/pipermail/squeak-dev/2018-May/198848.html" rel="noreferrer" target="_blank">http://lists.squeakfoundation.<wbr>org/pipermail/squeak-dev/2018-<wbr>May/198848.html</a><br>
<br>
New method added<br>
<br>
SmartRefStream  >> in the conversion protocol<br>
<br>
methodPropertiespps0<br>
<br>
       ^ AdditionalMethodState<br>
<br>
<br>
<br>
<br>
[3] readObject<br>
        | header oop nWords class format |<br>
        header := self readUint32.<br>
        (header bitAnd: HeaderTypeMask) caseOf: {<br>
                [HeaderTypeSizeAndClass] -><br>
                        [nWords := header >> 2. class := self readUint32. header := self readUint32].<br>
                [HeaderTypeClass] -><br>
                        [class := header - 1. header := self readUint32. nWords := header<br>
>> 2 bitAnd: 63].<br>
                [HeaderTypeShort] -><br>
                        [nWords := header >> 2 bitAnd: 63. class := header >> 12 bitAnd: 31].<br>
        } otherwise: [self error: 'unexpected free chunk'].<br>
        nWords := nWords - 1.   "nWords includes 1 header word"<br>
        oop := position.<br>
        ^[oopMap at: oop ifAbsentPut:<br>
                [format := header >> 8 bitAnd: 15.<br>
                "hash := header >> 17 bitAnd: 4095."<br>
                self allocateObject: format class: class size: nWords]]<br>
                        ensure: [position := oop + (nWords * 4)]<br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>
</div></div>