[Vm-dev] VM Maker: VMMaker.oscog-eem.3112.mcz

commits at source.squeak.org commits at source.squeak.org
Tue Nov 30 18:14:40 UTC 2021


Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.3112.mcz

==================== Summary ====================

Name: VMMaker.oscog-eem.3112
Author: eem
Time: 30 November 2021, 10:14:30.520037 am
UUID: 3e7ff69c-fd43-4366-836f-2349427152f0
Ancestors: VMMaker.oscog-eem.3111

Image file i/o. Check result of sqImageFile:Open: with invalidSqImageFile:, instead of assming nill is the invalid value. This allows unix to write images to stdout.

=============== Diff against VMMaker.oscog-eem.3111 ===============

Item was changed:
  ----- Method: StackInterpreter>>dumpImage: (in category 'image save/restore') -----
  dumpImage: fileName
  	"Dump the entire image out to the given file. Intended for debugging only.  Doesn't work for Spur."
  	<notOption: #SpurObjectMemory>
  	<export: true>
+ 	| f result |
+ 	<var: 'f' type: #sqImageFile>
- 	<var: #f type: #sqImageFile>
  
+ 	f := self sqImageFile: (self pointerForOop: fileName) Open: 'wb'.
+ 	(self invalidSqImageFile: f)
+ 		ifTrue: [^-1]
+ 		ifFalse:
+ 			[result := self sq: (self pointerForOop: objectMemory startOfMemory)
- 	(self sqImageFile: (self pointerForOop: fileName) Open: 'wb')
- 		ifNil: [^-1]
- 		ifNotNil:
- 			[:f| | result |
- 			result := self sq: (self pointerForOop: objectMemory startOfMemory)
  						Image: (self sizeof: #'unsigned char')
  						File: objectMemory endOfMemory - objectMemory startOfMemory
  						Write: f.
  			self sqImageFileClose: f.
  			^result]!

Item was changed:
  ----- Method: StackInterpreter>>writeImageFileIO (in category 'image save/restore') -----
  writeImageFileIO
  	"Write the image header and heap contents to imageFile for snapshot. c.f. writeImageFileIOSimulation.
  	 The game below is to maintain 64-bit alignment for all putLong:toFile: occurrences."
  	<inline: #never>
  	| imageName headerStart headerSize f imageBytes bytesWritten sCWIfn okToWrite |
+ 	<var: 'f' type: #sqImageFile>
+ 	<var: 'headerStart' type: #squeakFileOffsetType>
+ 	<var: 'sCWIfn' type: #'void *'>
+ 	<var: 'imageName' declareC: 'extern char imageName[]'>
- 	<var: #f type: #sqImageFile>
- 	<var: #headerStart type: #squeakFileOffsetType>
- 	<var: #sCWIfn type: #'void *'>
- 	<var: #imageName declareC: 'extern char imageName[]'>
  
  	self cCode: [] inSmalltalk: [imageName := 'sooth compiler'. ^self writeImageFileIOSimulation].
  
  	"If the security plugin can be loaded, use it to check for write permission.
  	 If not, assume it's ok"
  	sCWIfn := self ioLoadFunction: 'secCanWriteImage' From: 'SecurityPlugin'.
  	sCWIfn ~= 0 ifTrue:
  		[okToWrite := self cCode: '((sqInt (*)(void))sCWIfn)()'.
  		 okToWrite ifFalse:[^self primitiveFail]].
+ 
- 	
  	"local constants"
  	headerStart := 0.  
+ 	headerSize := objectMemory wordSize * 16. "64 or 128; header size in bytes; do not change!!"
- 	headerSize := objectMemory wordSize = 4 ifTrue: [64] ifFalse: [128].  "header size in bytes; do not change!!"
  
  	f := self sqImageFile: imageName Open: 'wb'.
+ 	(self invalidSqImageFile: f) ifTrue: "could not open the image file for writing"
+ 		[^self primitiveFailFor: PrimErrOperationFailed].
- 	f = nil ifTrue: "could not open the image file for writing"
- 		[^self primitiveFail].
  
  	imageBytes := objectMemory imageSizeToWrite.
  	headerStart := self sqImage: f File: imageName StartLocation: headerSize + imageBytes.
  	self cCode: '/* Note: on Unix systems one could put an exec command here, padded to 512 bytes */'.
  	"position file to start of header"
  	self sqImageFile: f Seek: headerStart.
  
  	self putWord32: self imageFormatVersion toFile: f.
  	self putWord32: headerSize toFile: f.
  	self putLong: imageBytes toFile: f.
  	self putLong: objectMemory baseAddressOfImage toFile: f.
  	self putLong: objectMemory specialObjectsOop toFile: f.
  	self putLong: objectMemory newObjectHash toFile: f.
  	self putLong: self getSnapshotScreenSize toFile: f.
  	self putLong: self getImageHeaderFlags toFile: f.
  	self putWord32: extraVMMemory toFile: f.
  	self putShort: desiredNumStackPages toFile: f.
  	self putShort: self unknownShortOrCodeSizeInKs toFile: f.
  	self putWord32: desiredEdenBytes toFile: f.
  	self putShort: (maxExtSemTabSizeSet ifTrue: [self ioGetMaxExtSemTableSize] ifFalse: [0]) toFile: f.
  	self putShort: the2ndUnknownShort toFile: f.
  	objectMemory hasSpurMemoryManagerAPI
  		ifTrue:
  			[self putLong: objectMemory firstSegmentBytes toFile: f.
  			 self putLong: objectMemory bytesLeftInOldSpace toFile: f.
  			 2 timesRepeat: [self putLong: 0 toFile: f]	"Pad the rest of the header."]
  		ifFalse:
  			[4 timesRepeat: [self putLong: 0 toFile: f]].  "Pad the rest of the header."
  
  	 objectMemory wordSize = 8 ifTrue:
  		[3 timesRepeat: [self putLong: 0 toFile: f]]. "Pad the rest of the header."
  
  	self assert: headerStart + headerSize = (self sqImageFilePosition: f).
  	"position file after the header"
  	self sqImageFile: f Seek: headerStart + headerSize.
  
  	self successful ifFalse: "file write or seek failure"
  		[self sqImageFileClose: f.
  		 ^nil].
  
  	"write the image data"
  	objectMemory hasSpurMemoryManagerAPI
  		ifTrue:
  			[bytesWritten := objectMemory writeImageSegmentsToFile: f]
  		ifFalse:
  			[bytesWritten := self sq: (self pointerForOop: objectMemory baseAddressOfImage)
  								Image: (self sizeof: #char)
  								File: imageBytes
  								Write: f].
  	self success: bytesWritten = imageBytes.
  	self sqImageFileClose: f!

Item was changed:
  ----- Method: StackInterpreter>>writeImageFileIOSimulation (in category 'image save/restore') -----
  writeImageFileIOSimulation
  	"Write the image header and heap contents to imageFile for snapshot.
  	 c.f. writeImageFileIO.  The game below is to maintain 64-bit alignment
  	 for all putLong:toFile: occurrences."
  	<doNotGenerate>
  	| headerSize file |
+ 	headerSize := objectMemory wordSize * 16.
- 	headerSize := objectMemory wordSize = 4 ifTrue: [64] ifFalse: [128].
  
  	(file := FileStream fileNamed: self imageName) ifNil:
  		[self primitiveFail.
  		 ^nil].
  	[file binary.
  	 self putWord32: self imageFormatVersion toFile: file.
  	 self putWord32: headerSize toFile: file.
  	 {
  		objectMemory imageSizeToWrite.
  		objectMemory baseAddressOfImage.
  		objectMemory specialObjectsOop.
  		objectMemory lastHash.
  		self ioScreenSize.
  		self getImageHeaderFlags
  	 }
  		do: [:long | self putLong: long toFile: file].
  
  	 self putWord32: (extraVMMemory ifNil: [0]) toFile: file.
  	 {	desiredNumStackPages. self unknownShortOrCodeSizeInKs } do:
  		[:short| self putShort: short toFile: file].
  
  	 self putWord32: desiredEdenBytes toFile: file.
  
  	 {	maxExtSemTabSizeSet ifTrue: [self ioGetMaxExtSemTableSize] ifFalse: [0]. 0 } do:
  		[:short| self putShort: short toFile: file].
  
  	 objectMemory hasSpurMemoryManagerAPI
  		ifTrue:
  			[| bytesWritten |
  			 self putLong: objectMemory firstSegmentBytes toFile: file.
  			 self putLong: objectMemory bytesLeftInOldSpace toFile: file.
  			 2 timesRepeat: [self putLong: 0 toFile: file] "Pad the rest of the header.".
  			 objectMemory wordSize = 8 ifTrue:
  				[3 timesRepeat: [self putLong: 0 toFile: file]].
  
  			 self assert: file position = headerSize.
+ 
- 			"Position the file after the header."
- 			file position: headerSize.
  			bytesWritten := objectMemory writeImageSegmentsToFile: file.
  			self assert: bytesWritten = objectMemory imageSizeToWrite]
  		ifFalse:
  			["Pad the rest of the header."
  			 4 timesRepeat: [self putLong: 0 toFile: file].
  			 objectMemory wordSize = 8 ifTrue:
  				[3 timesRepeat: [self putLong: 0 toFile: file]].
  
  			 self assert: file position = headerSize.
- 			 "Position the file after the header."
- 			 file position: headerSize.
  
  			 "Write the object memory."
+ 			 file
+ 				next: objectMemory imageSizeToWrite // objectMemory memory bytesPerElement
+ 				putAll: objectMemory memory
+ 				startingAt: objectMemory baseAddressOfImage // objectMemory memory bytesPerElement].
- 			 objectMemory baseAddressOfImage // 4 + 1
- 				to: objectMemory baseAddressOfImage + objectMemory imageSizeToWrite // 4
- 				do: [:index |
- 					self
- 						putLong: (objectMemory memory at: index)
- 						toFile: file]].
  	 file truncate: file position.
  	 self success: true]
  		 ensure: [file ifNotNil: [file close]]!



More information about the Vm-dev mailing list