Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert 631 revert 629 instantiateclass primitivefail #634

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions smalltalksrc/VMMaker/InterpreterPrimitives.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2732,11 +2732,6 @@ InterpreterPrimitives >> primitiveNew [

(objectMemory instantiateClass: self stackTop)
ifNotNil: [ :obj | self pop: argumentCount + 1 thenPush: obj ]
ifNil: [
self primitiveFailFor: ((objectMemory isFixedSizePointerFormat:
(objectMemory instSpecOfClass: self stackTop))
ifTrue: [ PrimErrNoMemory ]
ifFalse: [ PrimErrBadReceiver ]) ]
]

{ #category : #'compiled methods' }
Expand Down Expand Up @@ -2802,13 +2797,6 @@ InterpreterPrimitives >> primitiveNewWithArg [
instantiateClass: (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 ]) ]
]

{ #category : #'object access primitives' }
Expand Down
11 changes: 8 additions & 3 deletions smalltalksrc/VMMaker/Spur32BitMemoryManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,10 @@ Spur32BitMemoryManager >> instantiateClass: classObj indexableSize: nElements is
<var: #nElements type: #usqInt>
"Allocate an instance of a variable class, excepting CompiledMethod."
| instSpec classFormat numSlots classIndex newObj fillValue |
classFormat := self formatOfClass: classObj.
classFormat := self formatOfClassSafe: classObj.
classFormat == -1 ifTrue:
[self primitiveFailFor: PrimErrBadReceiver. "no format"
^nil].
instSpec := self instSpecOfClassFormat: classFormat.
classIndex := self rawHashBitsOf: classObj.
fillValue := 0.
Expand Down Expand Up @@ -421,7 +424,8 @@ Spur32BitMemoryManager >> instantiateClass: classObj indexableSize: nElements is
this method.
Hence allow fixed classes to be instantiated here iff nElements = 0."
(nElements ~= 0 or: [instSpec > self lastPointerFormat]) ifTrue:
[^nil].
[coInterpreter primitiveFailFor: PrimErrBadReceiver.
^nil].
numSlots := self fixedFieldsOfClassFormat: classFormat.
fillValue := nilObj].
classIndex = 0 ifTrue:
Expand All @@ -442,7 +446,8 @@ Spur32BitMemoryManager >> instantiateClass: classObj indexableSize: nElements is
ifFalse:
[newObj := self allocateSlots: numSlots format: instSpec classIndex: classIndex].
newObj ifNotNil:
[self fillObj: newObj numSlots: numSlots with: fillValue].
[self fillObj: newObj numSlots: numSlots with: fillValue]
ifNil: [ self primitiveFailFor: PrimErrNoMemory ].
^newObj
]

Expand Down
11 changes: 8 additions & 3 deletions smalltalksrc/VMMaker/Spur64BitMemoryManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,10 @@ Spur64BitMemoryManager >> instantiateClass: classObj indexableSize: nElements is
<var: #nElements type: #usqInt>
"Allocate an instance of a variable class, excepting CompiledMethod."
| instSpec classFormat numSlots classIndex newObj fillValue |
classFormat := self formatOfClass: classObj.
classFormat := self formatOfClassSafe: classObj.
classFormat == -1 ifTrue:
[self primitiveFailFor: PrimErrBadReceiver. "no format"
^nil].
instSpec := self instSpecOfClassFormat: classFormat.
classIndex := self rawHashBitsOf: classObj.
fillValue := 0.
Expand Down Expand Up @@ -460,7 +463,8 @@ Spur64BitMemoryManager >> instantiateClass: classObj indexableSize: nElements is
this method.
Hence allow fixed classes to be instantiated here iff nElements = 0."
(nElements ~= 0 or: [instSpec > self lastPointerFormat]) ifTrue:
[^nil].
[coInterpreter primitiveFailFor: PrimErrBadReceiver.
^nil].
numSlots := self fixedFieldsOfClassFormat: classFormat.
fillValue := nilObj].
classIndex = 0 ifTrue:
Expand All @@ -481,7 +485,8 @@ Spur64BitMemoryManager >> instantiateClass: classObj indexableSize: nElements is
ifFalse:
[newObj := self allocateSlots: numSlots format: instSpec classIndex: classIndex].
newObj ifNotNil:
[self fillObj: newObj numSlots: numSlots with: fillValue].
[self fillObj: newObj numSlots: numSlots with: fillValue]
ifNil: [ self primitiveFailFor: PrimErrNoMemory ].
^newObj
]

Expand Down
26 changes: 23 additions & 3 deletions smalltalksrc/VMMaker/SpurMemoryManager.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5548,6 +5548,21 @@ SpurMemoryManager >> formatOfClass: classPointer [
^self integerValueOf: (self fetchPointer: InstanceSpecificationIndex ofObject: classPointer)
]

{ #category : #'object format' }
SpurMemoryManager >> formatOfClassSafe: oop [
"like formatOfClass: but check the existence of the format.
return -1 there is no format or a non integer format"
<api>
<inline: true>
| classObj classFormat |
classObj := self followMaybeForwarded: oop.
(self isNonImmediate: classObj) ifFalse: [ ^-1].
(self numSlotsOfAny: classObj) >= InstanceSpecificationIndex ifFalse: [^-1].
classFormat := self fetchPointer: InstanceSpecificationIndex ofObject: classObj.
(self isIntegerObject: classFormat) ifFalse: [^-1].
^self integerValueOf: classFormat
]

{ #category : #'object access' }
SpurMemoryManager >> formatOfHeader: header [
"0 = 0 sized objects (UndefinedObject True False et al)
Expand Down Expand Up @@ -6941,18 +6956,23 @@ SpurMemoryManager >> instantiateClass: classObj indexableSize: nElements isPinne
{ #category : #instantiation }
SpurMemoryManager >> instantiateClass: classObj isPinned: isPinned [
| instSpec classFormat numSlots classIndex newObj |
classFormat := self formatOfClass: classObj.
classFormat := self formatOfClassSafe: classObj.
classFormat == -1 ifTrue:
[self primitiveFailFor: PrimErrBadReceiver. "no format"
^nil].
instSpec := self instSpecOfClassFormat: classFormat.
(self isFixedSizePointerFormat: instSpec) ifFalse:
[^nil].
[self primitiveFailFor: PrimErrBadReceiver. "bad format"
^nil].
classIndex := self ensureBehaviorHash: classObj.
classIndex < 0 ifTrue:
[coInterpreter primitiveFailFor: classIndex negated.
^nil].
numSlots := self fixedFieldsOfClassFormat: classFormat.
newObj := self allocateSlots: numSlots format: instSpec classIndex: classIndex isPinned: isPinned.
newObj ifNotNil:
[self fillObj: newObj numSlots: numSlots with: nilObj].
[self fillObj: newObj numSlots: numSlots with: nilObj]
ifNil: [ self primitiveFailFor: PrimErrNoMemory ].
^newObj
]

Expand Down
56 changes: 56 additions & 0 deletions smalltalksrc/VMMakerTests/VMPrimitiveTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2864,6 +2864,37 @@ VMPrimitiveTest >> testPrimitiveNewWithArgWithInvalidClassFails [
self assert: interpreter primFailCode equals: PrimErrBadReceiver
]

{ #category : #'tests - primitiveNewWithArgs' }
VMPrimitiveTest >> testPrimitiveNewWithArgWithInvalidClassFails2 [
| class |

"class object with no slots, so no format"
class := self newObjectWithSlots: 0.

interpreter push: class.
interpreter push: (memory integerObjectOf: 256).

interpreter primitiveNewWithArg.

self assert: interpreter primFailCode equals: PrimErrBadReceiver
]

{ #category : #'tests - primitiveNewWithArgs' }
VMPrimitiveTest >> testPrimitiveNewWithArgWithInvalidClassFails3 [
| class |

"class with nil as format"
class := self newClassInOldSpaceWithSlots: 0 instSpec: memory nonIndexablePointerFormat.
memory storePointer: 2 ofObject: class withValue: memory nilObject.

interpreter push: class.
interpreter push: (memory integerObjectOf: 256).

interpreter primitiveNewWithArg.

self assert: interpreter primFailCode equals: PrimErrBadReceiver
]

{ #category : #'tests - primitiveNewWithArgs' }
VMPrimitiveTest >> testPrimitiveNewWithArgWithNegativeArgumentFails [
| class |
Expand All @@ -2889,6 +2920,31 @@ VMPrimitiveTest >> testPrimitiveNewWithInvalidClassFails [
self assert: interpreter primFailCode equals: PrimErrBadReceiver
]

{ #category : #'tests - primitiveNew' }
VMPrimitiveTest >> testPrimitiveNewWithInvalidClassFails2 [
| class |
"class object with no slots, so no format"
class := self newObjectWithSlots: 0.

interpreter push: class.
interpreter primitiveNew.

self assert: interpreter primFailCode equals: PrimErrBadReceiver
]

{ #category : #'tests - primitiveNew' }
VMPrimitiveTest >> testPrimitiveNewWithInvalidClassFails3 [
| class |
"class with nil used as format"
class := self newClassInOldSpaceWithSlots: 0 instSpec: memory nonIndexablePointerFormat.
memory storePointer: 2 ofObject: class withValue: memory nilObject.

interpreter push: class.
interpreter primitiveNew.

self assert: interpreter primFailCode equals: PrimErrBadReceiver
]

{ #category : #'tests - primitiveNotEqual' }
VMPrimitiveTest >> testPrimitiveNotEqualFailsWithFloat [

Expand Down