Skip to content

Commit

Permalink
Refactoring primitive new old space with args
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanmontt committed Oct 6, 2023
1 parent 4639c83 commit 2746e52
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 157 deletions.
20 changes: 13 additions & 7 deletions smalltalksrc/VMMaker/InterpreterPrimitives.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2816,15 +2816,21 @@ InterpreterPrimitives >> primitiveNewWithArg [
InterpreterPrimitives >> primitiveNewWithArgOldSpace [

| size instSpec |

size := self positiveMachineIntegerValueOf: self stackTop.

(objectMemory instantiateClassInOldSpace: (self stackValue: 1) indexableSize: size)
ifNotNil: [ :obj | self pop: argumentCount + 1 thenPush: obj ]
ifNil: [
instSpec := objectMemory instSpecOfClass: (self stackValue: 1).
self primitiveFailFor: (((objectMemory isIndexableFormat: instSpec) and: [
(objectMemory isCompiledMethodFormat: instSpec) not ]) ifTrue: [ PrimErrNoMemory ]
ifFalse: [ PrimErrBadReceiver ]) ]
(objectMemory
instantiateClass: (self stackValue: 1)
indexableSize: size
isPinned: false
isOldSpace: true)
ifNotNil: [ :obj | self pop: argumentCount + 1 thenPush: obj ]
ifNil: [ instSpec := objectMemory instSpecOfClass: (self stackValue: 1).
self primitiveFailFor:
(((objectMemory isIndexableFormat: instSpec)
and: [ (objectMemory isCompiledMethodFormat: instSpec) not ])
ifTrue: [ PrimErrNoMemory ]
ifFalse: [ PrimErrBadReceiver ]) ]
]

{ #category : #'object access primitives' }
Expand Down
74 changes: 2 additions & 72 deletions smalltalksrc/VMMaker/Spur32BitMemoryManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ Spur32BitMemoryManager >> initSegmentBridgeWithBytes: numBytes at: address [
]

{ #category : #instantiation }
Spur32BitMemoryManager >> instantiateClass: classObj indexableSize: nElements isPinned: isPinned [
Spur32BitMemoryManager >> instantiateClass: classObj indexableSize: nElements isPinned: isPinned isOldSpace: isOldSpace [
<api>
<var: #nElements type: #usqInt>
"Allocate an instance of a variable class, excepting CompiledMethod."
Expand Down Expand Up @@ -433,7 +433,7 @@ Spur32BitMemoryManager >> instantiateClass: classObj indexableSize: nElements is
classIndex < 0 ifTrue:
[coInterpreter primitiveFailFor: classIndex negated.
^nil]].
(numSlots > self maxSlotsForNewSpaceAlloc or: [isPinned])
(numSlots > self maxSlotsForNewSpaceAlloc or: [isPinned or: [isOldSpace ]])
ifTrue:
[numSlots > self maxSlotsForAlloc ifTrue:
[coInterpreter primitiveFailFor: PrimErrUnsupported.
Expand All @@ -451,76 +451,6 @@ Spur32BitMemoryManager >> instantiateClass: classObj indexableSize: nElements is
^newObj
]

{ #category : #instantiation }
Spur32BitMemoryManager >> instantiateClassInOldSpace: classObj indexableSize: nElements [
<api>
<var: #nElements type: #usqInt>
"Allocate an instance of a variable class, excepting CompiledMethod."
| instSpec classFormat numSlots classIndex newObj fillValue |
classFormat := self formatOfClassSafe: classObj.
classFormat == -1 ifTrue:
[self primitiveFailFor: PrimErrBadReceiver. "no format"
^nil].
instSpec := self instSpecOfClassFormat: classFormat.
classIndex := self rawHashBitsOf: classObj.
fillValue := 0.
instSpec caseOf: {
[self arrayFormat] ->
[numSlots := nElements.
fillValue := nilObj].
[self indexablePointersFormat] ->
[numSlots := (self fixedFieldsOfClassFormat: classFormat) + nElements.
fillValue := nilObj].
[self weakArrayFormat] ->
[numSlots := (self fixedFieldsOfClassFormat: classFormat) + nElements.
fillValue := nilObj].
[self sixtyFourBitIndexableFormat] ->
[nElements > (self maxSlotsForAlloc / 2) ifTrue:
[coInterpreter primitiveFailFor: PrimErrUnsupported.
^nil].
numSlots := nElements * 2].
[self firstLongFormat] ->
[(classIndex = ClassFloatCompactIndex and: [nElements ~= 2]) ifTrue:
[coInterpreter primitiveFailFor: PrimErrBadReceiver.
^nil].
numSlots := nElements].
[self firstShortFormat] ->
[numSlots := nElements + 1 // 2.
instSpec := instSpec + (nElements bitAnd: 1)].
[self firstByteFormat] ->
[numSlots := nElements + 3 // 4.
instSpec := instSpec + (4 - nElements bitAnd: 3)] }
otherwise: "non-indexable"
["Some Squeak images include funky fixed subclasses of abstract variable
superclasses. e.g. DirectoryEntry as a subclass of ArrayedCollection.
The (Threaded)FFIPlugin expects to be able to instantiate ExternalData via
this method.
Hence allow fixed classes to be instantiated here iff nElements = 0."
(nElements ~= 0 or: [instSpec > self lastPointerFormat]) ifTrue:
[coInterpreter primitiveFailFor: PrimErrBadReceiver.
^nil].
numSlots := self fixedFieldsOfClassFormat: classFormat.
fillValue := nilObj].
classIndex = 0 ifTrue:
[classIndex := self ensureBehaviorHash: classObj.
classIndex < 0 ifTrue:
[coInterpreter primitiveFailFor: classIndex negated.
^nil]].

numSlots > self maxSlotsForAlloc ifTrue:
[coInterpreter primitiveFailFor: PrimErrUnsupported.
^ nil].
newObj := self
allocateSlotsInOldSpace: numSlots
format: instSpec
classIndex: classIndex.

newObj ifNotNil:
[self fillObj: newObj numSlots: numSlots with: fillValue]
ifNil: [ self primitiveFailFor: PrimErrNoMemory ].
^newObj
]

{ #category : #instantiation }
Spur32BitMemoryManager >> instantiateCompiledMethodClass: classObj indexableSize: nElements [
<var: #nElements type: #usqInt>
Expand Down
73 changes: 2 additions & 71 deletions smalltalksrc/VMMaker/Spur64BitMemoryManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ Spur64BitMemoryManager >> initSegmentBridgeWithBytes: numBytes at: address [
]

{ #category : #instantiation }
Spur64BitMemoryManager >> instantiateClass: classObj indexableSize: nElements isPinned: isPinned [
Spur64BitMemoryManager >> instantiateClass: classObj indexableSize: nElements isPinned: isPinned isOldSpace: isOldSpace [
<api>
<var: #nElements type: #usqInt>
"Allocate an instance of a variable class, excepting CompiledMethod."
Expand Down Expand Up @@ -472,7 +472,7 @@ Spur64BitMemoryManager >> instantiateClass: classObj indexableSize: nElements is
classIndex < 0 ifTrue:
[coInterpreter primitiveFailFor: classIndex negated.
^nil]].
(numSlots > self maxSlotsForNewSpaceAlloc or: [isPinned])
(numSlots > self maxSlotsForNewSpaceAlloc or: [isPinned or: [isOldSpace]])
ifTrue:
[numSlots > self maxSlotsForAlloc ifTrue:
[coInterpreter primitiveFailFor: PrimErrUnsupported.
Expand All @@ -490,75 +490,6 @@ Spur64BitMemoryManager >> instantiateClass: classObj indexableSize: nElements is
^newObj
]

{ #category : #instantiation }
Spur64BitMemoryManager >> instantiateClassInOldSpace: classObj indexableSize: nElements [
<api>
<var: #nElements type: #usqInt>
"Allocate an instance of a variable class, excepting CompiledMethod."
| instSpec classFormat numSlots classIndex newObj fillValue |
classFormat := self formatOfClassSafe: classObj.
classFormat == -1 ifTrue:
[self primitiveFailFor: PrimErrBadReceiver. "no format"
^nil].
instSpec := self instSpecOfClassFormat: classFormat.
classIndex := self rawHashBitsOf: classObj.
fillValue := 0.
instSpec caseOf: {
[self arrayFormat] ->
[numSlots := nElements.
fillValue := nilObj].
[self indexablePointersFormat] ->
[numSlots := (self fixedFieldsOfClassFormat: classFormat) + nElements.
fillValue := nilObj].
[self weakArrayFormat] ->
[numSlots := (self fixedFieldsOfClassFormat: classFormat) + nElements.
fillValue := nilObj].
[self sixtyFourBitIndexableFormat] ->
[numSlots := nElements].
[self firstLongFormat] ->
[(classIndex = ClassFloatCompactIndex and: [nElements ~= 2]) ifTrue:
[coInterpreter primitiveFailFor: PrimErrBadReceiver.
^nil].
numSlots := nElements + 1 // 2.
instSpec := instSpec + (nElements bitAnd: 1)].
[self firstShortFormat] ->
[numSlots := nElements + 3 // 4.
instSpec := instSpec + (4 - nElements bitAnd: 3)].
[self firstByteFormat] ->
[numSlots := nElements + 7 // 8.
instSpec := instSpec + (8 - nElements bitAnd: 7)] }
otherwise: "non-indexable"
["Some Squeak images include funky fixed subclasses of abstract variable
superclasses. e.g. DirectoryEntry as a subclass of ArrayedCollection.
The (Threaded)FFIPlugin expects to be able to instantiate ExternalData via
this method.
Hence allow fixed classes to be instantiated here iff nElements = 0."
(nElements ~= 0 or: [instSpec > self lastPointerFormat]) ifTrue:
[coInterpreter primitiveFailFor: PrimErrBadReceiver.
^nil].
numSlots := self fixedFieldsOfClassFormat: classFormat.
fillValue := nilObj].

classIndex = 0 ifTrue:
[classIndex := self ensureBehaviorHash: classObj.
classIndex < 0 ifTrue:
[coInterpreter primitiveFailFor: classIndex negated.
^nil]].

numSlots > self maxSlotsForAlloc ifTrue:
[coInterpreter primitiveFailFor: PrimErrUnsupported.
^ nil].
newObj := self
allocateSlotsInOldSpace: numSlots
format: instSpec
classIndex: classIndex .

newObj ifNotNil:
[self fillObj: newObj numSlots: numSlots with: fillValue]
ifNil: [ self primitiveFailFor: PrimErrNoMemory ].
^newObj
]

{ #category : #instantiation }
Spur64BitMemoryManager >> instantiateCompiledMethodClass: classObj indexableSize: nElements [
<var: #nElements type: #usqInt>
Expand Down
14 changes: 7 additions & 7 deletions smalltalksrc/VMMaker/SpurMemoryManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6965,6 +6965,13 @@ SpurMemoryManager >> instantiateClass: classObj indexableSize: nElements [
SpurMemoryManager >> instantiateClass: classObj indexableSize: nElements isPinned: isPinned [
<api>

^ self instantiateClass: classObj indexableSize: nElements isPinned: isPinned isOldSpace: false
]

{ #category : #instantiation }
SpurMemoryManager >> instantiateClass: classObj indexableSize: nElements isPinned: isPinned isOldSpace: isOldSpace [
<api>

^ self subclassResponsibility
]

Expand Down Expand Up @@ -6997,13 +7004,6 @@ SpurMemoryManager >> instantiateClass: classObj isPinned: isPinned isOldSpace: i
^newObj
]

{ #category : #instantiation }
SpurMemoryManager >> instantiateClassInOldSpace: classObj indexableSize: nElements [
<api>

^ self subclassResponsibility
]

{ #category : #instantiation }
SpurMemoryManager >> instantiateCompiledMethodClass: classObj indexableSize: nElements [
<var: #nElements type: #usqInt>
Expand Down

0 comments on commit 2746e52

Please sign in to comment.