[Vm-dev] what about image reading?

Tobias Pape Das.Linux at gmx.de
Thu Jan 20 17:37:00 UTC 2011


Am 2011-01-14 um 15:08 schrieb David T. Lewis:
> On Fri, Jan 14, 2011 at 12:10:23PM +0100, Tobias Pape wrote:
[…]
>>> 
>> 
>> Ah, the Windows vm does.
>> 
>> I did one grep of my own and found:
>> 
>> vm	has 512b-offset-support
>> Carbon	no
>> Risc	no
>> Cocoa	no
>> unix	no
>> Win32	yes
>> 
>> So, while only the win32-vm is _able_ to read the offset images, wouldn't it make sense
>> to drop this feature altogether?
> 
> You're misreading the code. This feature is not platform specific, and is
> implemented in the Smalltalk code. This is explained in the method comment
> of #readImageFromFile:HeapSize:StartingAt: and you'll find the implementation
> in #checkImageVersionFrom:startingAt: which is sent by
> #readImageFromFile:HeapSize:StartingAt:
> 
> So main() calls #readImageFromFile:HeapSize:StartingAt: to load the
> image file, and the 512 byte skip is implemented there.

Ah, I see. 
Why is the windows vm doing it manually, then?

> 
> You can also see how this works by loading an image file in the
> InterpreterSimulator. See class comment for InterpreterSimulator,
> and step through it in a debugger to see your image file being
> loaded.


Nice hint. Thank you.

I did that on a hand-crafted 512-byte offset file.
However, the InterpreterSimulator does not support 512byte offsetting:

InterpreterSimulator>>#openOn:extraMemory:
" .. snip .."

	["begin ensure block..."
	f := FileStream readOnlyFileNamed: fileName.
	imageName := f fullName.
	f binary.
" offset handling should be here
 --> "	version := self nextLongFrom: f.  "current version: 16r1966 (=6502)"
	versionToRun := version bitAnd: -2. "permit loading images with platform float ordering"
	hasPlatformFloatOrdering := version ~= (version bitAnd: -2). "is low order bit set?"
	(self readableFormat: versionToRun) "permit loading images with platform float ordering"
		ifTrue: [swapBytes := false]
		ifFalse: [(versionToRun := self byteSwapped: version) = self imageFormatVersion
					ifTrue: [swapBytes := true]
					ifFalse: [			
" or at least here -->"				self error: 'incompatible image format']].


I tested the same Image on the Carbon 4.2.5beta1U VM, but it does not load
either:
/Applications/Squeak\ 4.2.5beta1U.app/Contents/MacOS/Squeak\ VM\ Opt v39_le_32bit_off_clos_cog.SqueakLight.image 
This interpreter (vers. 0) cannot read image file (vers. 1966022947).
Press CR to quit...

Note that the 1966022947 = 0x752F2123 => 0x23 0x21 0x2F 0x75
corresponds to the beginning of the file: '#!/u'

Is anyone interested in the offset-image to test it her/himself?

So Long,
	-Tobias



More information about the Vm-dev mailing list