VM Maker: VMMaker.oscog-cb.2374.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

VM Maker: VMMaker.oscog-cb.2374.mcz

commits-2
 
ClementBera uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-cb.2374.mcz

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

Name: VMMaker.oscog-cb.2374
Author: cb
Time: 26 April 2018, 1:04:16.030075 pm
UUID: 62a33f21-e764-413a-b544-289e012d498a
Ancestors: VMMaker.oscog-cb.2373

Improved comments & rename variables for Slang to C compilation not to complain (Shadowing globals with inlining cross-classes is a little bit tricky, let's not take any risks)

=============== Diff against VMMaker.oscog-cb.2373 ===============

Item was changed:
  SpurSweeper subclass: #SpurSelectiveCompactor
  instanceVariableNames: 'segmentToFill'
  classVariableNames: 'MaxOccupationForCompaction'
  poolDictionaries: ''
  category: 'VMMaker-SpurMemoryManager'!
 
+ !SpurSelectiveCompactor commentStamp: 'cb 4/26/2018 12:53' prior: 0!
- !SpurSelectiveCompactor commentStamp: 'cb 4/19/2018 08:49' prior: 0!
  SpurSelectiveCompactor compacts memory by selecting the memory segments with the most free space and compacting only those, to limit fragmentation while being really quick to perform. The algorithm is fast mostly because it does not update pointers: they are updated lazily during the next marking phase, so there is no need to read the fields of objects in other memory segments that the one compacted.
 
+ The algorithm works as follow. First, a global sweep pass iterates over the memory linearly, changing unmarked objects to free chunks and concatenating free chunks. During the global sweep phase, the segments of the heap are analysed to determine the percentage of occupation. Second, the least occupied segments are compacted by copying the remaining live objects into an entirely free segment, called regionToFill (we detail later in the paragraph where regionToFill comes from), changing their values to forwarding objects and marking the free chunks as unavailable (removed from free list and marked as data objects). Third, the next marking phase removes all forwarders. Fourth, at the beginning of the next compaction phase the compacted segments from the previous GC can be entirely marked as free space (No need to check anything inside, there were only forwarders and trash data). One of the compacted segment is then selected as the segmentToFill, others are just marked as free chunks.
 
- The algorithm works as follow. First, a global sweep pass iterates over the memory linearly, changing unmarked objects to free chunks and concatenating free chunks. During the global sweep phase, the segments of the heap are analysed to determine the percentage of occupation. Second, the least occupied segments are compacted by copying the remaining live objects into an entirely free segment, called regionToFill (we detail later in the paragraph where regionToFill comes from) and changing their values to forwarding objects. The rest of each segment being freed is removed from the freeList, it will be entirely freed at the beginning of the next compaction phase. Third, the next marking phase removes all forwarders. Fourth, at the beginning of the next compaction phase the compacted segments from the previous GC can be entirely marked as free space (No need to check anything inside, there were only forwarders that were removed and free chunks not on the free list). One of the freed s
 egment is then selected as the regionToFill, others are just marked as free space. The compaction is effectively partial, compacting only the most critical regions of the heap to limit fragmentation.
 
+ The compaction is effectively partial, compacting only the most critical segments of the heap to limit fragmentation. Compaction time is crazy low, since a low number of objects are moved and pointer updated is lazily done during the next marking phase, while still preventing memory fragmentation.
+
  Now this works well when biasForGC is true, but when performing a snapshot, the compactor is just total crap (we need to figure out a solution).
 
  segmentToFill <SegInfo> the segment that will be filled through the copying algorithm
 
  !

Item was changed:
  ----- Method: SpurSelectiveCompactor>>compactSegment:freeStart: (in category 'compaction') -----
  compactSegment: segInfo freeStart: initialFreeStart
  <var: 'segInfo' type: #'SpurSegmentInfo *'>
+ | currentEntity fillStart bytesInObject numSlots bridge |
+ fillStart := initialFreeStart.
- | currentEntity freeStart bytesInObject numSlots bridge |
- freeStart := initialFreeStart.
  bridge := manager segmentManager bridgeFor: segInfo.
  currentEntity := manager objectStartingAt: segInfo segStart.
  [self oop: currentEntity isLessThan: bridge] whileTrue:
  [(manager isFreeObject: currentEntity)
  ifTrue:
  ["To avoid confusing too much Spur (especially the leak/free checks), we mark the free chunk as a word object."
  manager detachFreeObject: currentEntity.
  manager set: currentEntity classIndexTo: manager wordSizeClassIndexPun formatTo: manager wordIndexableFormat]
  ifFalse:
  ["Copy the object in segmentToFill and replace it by a forwarder."
  self assert: (manager isPinned: currentEntity) not.
  numSlots := manager numSlotsOfAny: currentEntity.
  bytesInObject := manager bytesInObject: currentEntity.
  self assert: (manager objectBytesForSlots: numSlots) = (manager bytesInObject: currentEntity).
+ manager mem: fillStart asVoidPointer cp: (manager startOfObject: currentEntity) asVoidPointer y: bytesInObject.
+ self assert: (manager baseHeader: (manager objectStartingAt: fillStart)) = (manager baseHeader: currentEntity).
+ self assert: (manager fetchPointer: numSlots - 1 ofObject: (manager objectStartingAt: fillStart)) = (manager fetchPointer: numSlots - 1 ofObject: currentEntity).
+ manager forward: currentEntity to: (manager objectStartingAt: fillStart).
+ fillStart := fillStart + (manager objectBytesForSlots: numSlots).
- manager mem: freeStart asVoidPointer cp: (manager startOfObject: currentEntity) asVoidPointer y: bytesInObject.
- self assert: (manager baseHeader: (manager objectStartingAt: freeStart)) = (manager baseHeader: currentEntity).
- self assert: (manager fetchPointer: numSlots - 1 ofObject: (manager objectStartingAt: freeStart)) = (manager fetchPointer: numSlots - 1 ofObject: currentEntity).
- manager forward: currentEntity to: (manager objectStartingAt: freeStart).
- freeStart := freeStart + (manager objectBytesForSlots: numSlots).
  self assert: (manager isForwarded: currentEntity).
+ self assert: fillStart < (segmentToFill segLimit - manager bridgeSize)].
- self assert: freeStart < (segmentToFill segLimit - manager bridgeSize)].
  currentEntity := manager objectAfter: currentEntity limit: manager endOfMemory].
  self assert: currentEntity = bridge.
+ ^ fillStart!
- ^ freeStart!

Item was changed:
  ----- Method: SpurSelectiveCompactor>>compactSegmentsToCompact (in category 'compaction') -----
  compactSegmentsToCompact
  "Forwards all objects in segments to compact and removes their freechunks"
+ | fillStart |
+ fillStart := segmentToFill segStart.
- | freeStart |
- freeStart := segmentToFill segStart.
 
  "Removes initial free chunk in segment to fill... (Segment is entirely free)"
+ manager detachFreeObject: (manager objectStartingAt: fillStart).
- manager detachFreeObject: (manager objectStartingAt: freeStart).
 
  "Compact each segment to compact..."
  0 to: manager numSegments - 1 do:
  [:i| | segInfo |
  segInfo := self addressOf: (manager segmentManager segments at: i).
  (self isSegmentBeingCompacted: segInfo)
+ ifTrue: [fillStart := self compactSegment: segInfo freeStart: fillStart ]].
- ifTrue: [freeStart := self compactSegment: segInfo freeStart: freeStart ]].
 
  "Final free chunk in segment to fill..."
  manager
+ addFreeChunkWithBytes: segmentToFill segSize - manager bridgeSize + segmentToFill segStart - fillStart
+ at: fillStart.
- addFreeChunkWithBytes: segmentToFill segSize - manager bridgeSize + segmentToFill segStart - freeStart
- at: freeStart.
 
  "Follow stack zone and caches..."
  self postForwardingAction
  !