[Vm-dev] VM Maker: VMMaker-oscog-dtl.59.mcz
Bert Freudenberg
bert at freudenbergs.de
Mon Apr 18 15:35:21 UTC 2011
On 18.04.2011, at 16:46, David T. Lewis wrote:
>
> On Mon, Apr 18, 2011 at 12:12:22PM +0200, Levente Uzonyi wrote:
>>
>> On Mon, 18 Apr 2011, Bert Freudenberg wrote:
>>
>>>
>>> On 18.04.2011, at 07:23, squeak-dev-noreply at lists.squeakfoundation.org
>>> wrote:
>>>
>>>> Add primitiveImageFormatVersion, an optional named primitive answering
>>>> the image format number of the current image. This is the value stored in
>>>> the first word of an image file header when the image is saved, and
>>>> possibly modified on image load if the VM adds or removes capabilities
>>>> for the running image. This primitive was added to VMMaker trunk in
>>>> VMMaker-dtl.169. Rationale: supports float word order handing for image
>>>> segments, reference
>>>> http://lists.squeakfoundation.org/pipermail/vm-dev/2011-April/007712.html
>>>
>>> Is there a way to detect if an image will be saved in a different format
>>> than it was loaded?
>>>
>>> In some images I want to avoid saving them accidentally as a Cog image. I
>>> have been doing this by adding a preference "warnAboutSavingAsCog" and
>>> checking the VM version string for "cog". With this new primitive I could
>>> more reliably detect Cog, but I guess no information about the loaded
>>> image is retained?
>>
>> Why don't you read the first four bytes from the image file to get the
>> image version? Also, there's SmalltalkImage >> #isRunningCog to check if
>> the current VM is a CogVM.
>>
>> imageFormat := (FileStream fileNamed: Smalltalk imageName do: [ :file |
>> file binary; next: 4 ]) unsignedLongAt: 1 bigEndian: false.
>> isCogVM := Smalltalk isRunningCog.
>
> The image format number in the file is not necessarily the same as the
> image format currently being used. For example, when an interpreter VM
> reads an image saved from Cog (i.e. format 6505), it converts the image
> to format 6504 prior to entering the interpreter. So the disk file will
> tell you that you are using a 6505 image, but the VM knows better and
> will report the current image format version as 6504.
Yes, that is precisely the use case here. I wanted to detect when an interpreter image was saved as cog image for the first time.
wasCog := self imageFormatVersionFromFile allMask: 1.
isCog := Smalltalk isRunningCog.
imageFormatVersionFromFile
| format |
format := self imageFormatVersionFromFileAsIs.
^format <= 16r00FFFFFF
ifTrue: [ "same endianness as VM"
format ]
ifFalse: [ "convert endianness"
((format bitAnd: 16rFF000000) >> 24)
+ ((format bitAnd: 16r00FF0000) >> 8)
+ ((format bitAnd: 16r0000FF00) << 8)
+ ((format bitAnd: 16r000000FF) << 24)]
imageFormatVersionFromFileAsIs
^(FileStream fileNamed: Smalltalk imageName do: [ :file | file binary; next: 4 ])
unsignedLongAt: 1 bigEndian: Smalltalk isBigEndian
- Bert -
More information about the Vm-dev
mailing list