-
Notifications
You must be signed in to change notification settings - Fork 78
Fix meta try primitive #968
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
Open
guillep
wants to merge
7
commits into
pharo-project:pharo-12
Choose a base branch
from
guillep:fix-meta-try-primitive
base: pharo-12
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
08c7c63
Cleanup debugging code
guillep c3f8170
Add a first positive test for primitiveDoPrimitiveWithArgs
guillep 8215715
Add tests for reentrant meta primitive (try primitive) in normal and …
guillep 968bad3
Remove debugging leftover
guillep cf9fa52
Fix assertion failing for meta-primitives (wrong order of check)
guillep f7e0ce0
Fix reentrant try-primitive primitive, storing global state locally
guillep 979199c
Refactor try-primitive tests into a separate test class
guillep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -953,71 +953,77 @@ StackInterpreterPrimitives >> primitiveDoPrimitiveWithArgs [ | |
or Context>>receiver: anObject tryPrimitive: primIndex withArgs: argArray. | ||
If this primitive fails, arrange that its error code is a negative integer, to | ||
distinguish between this failing and the primitive it invokes failing." | ||
| argumentArray arraySize index primIdx savedNumArgs rcvr | | ||
|
||
| argumentArray arraySize index primIdx savedNumArgs rcvr savedTempOop savedTempOop2 | | ||
"See checkForAndFollowForwardedPrimitiveState" | ||
metaAccessorDepth := -2. | ||
(argumentCount between: 2 and: 3) ifFalse: | ||
[^self primitiveFailFor: PrimErrUnsupported negated]. | ||
(argumentCount between: 2 and: 3) ifFalse: [ | ||
^ self primitiveFailFor: PrimErrUnsupported negated ]. | ||
argumentArray := self stackTop. | ||
primIdx := self stackValue: 1. | ||
((objectMemory isArray: argumentArray) | ||
and: [objectMemory isIntegerObject: primIdx]) ifFalse: | ||
[^self primitiveFailFor: PrimErrBadArgument negated]. | ||
((objectMemory isArray: argumentArray) and: [ | ||
objectMemory isIntegerObject: primIdx ]) ifFalse: [ | ||
^ self primitiveFailFor: PrimErrBadArgument negated ]. | ||
arraySize := objectMemory numSlotsOf: argumentArray. | ||
(self roomToPushNArgs: arraySize) ifFalse: | ||
[^self primitiveFailFor: PrimErrLimitExceeded negated]. | ||
(self roomToPushNArgs: arraySize) ifFalse: [ | ||
^ self primitiveFailFor: PrimErrLimitExceeded negated ]. | ||
|
||
primIdx := objectMemory integerValueOf: primIdx. | ||
primitiveFunctionPointer := self functionPointerFor: primIdx. | ||
primitiveFunctionPointer = 0 ifTrue: | ||
[primitiveFunctionPointer := #primitiveDoPrimitiveWithArgs. | ||
^self primitiveFailFor: PrimErrBadIndex negated]. | ||
primitiveFunctionPointer = 0 ifTrue: [ | ||
primitiveFunctionPointer := #primitiveDoPrimitiveWithArgs. | ||
^ self primitiveFailFor: PrimErrBadIndex negated ]. | ||
|
||
"Pop primIndex and argArray, then push args in place..." | ||
(savedNumArgs := argumentCount) = 3 | ||
ifTrue: "...and receiver if the three arg form" | ||
[tempOop2 := self stackValue: 4. "actual receiver" | ||
rcvr := self stackValue: 3. "receiver for primitive" | ||
(objectMemory isOopForwarded: rcvr) ifTrue: | ||
[rcvr := objectMemory followForwarded: rcvr]. | ||
self pop: 4; push: rcvr] "use first arg as receiver" | ||
ifFalse: | ||
[self pop: 2]. | ||
ifTrue: [ "use first arg as receiver""...and receiver if the three arg form" | ||
savedTempOop2 := tempOop2. | ||
tempOop2 := self stackValue: 3. "actual receiver" | ||
rcvr := self stackValue: 2. "receiver for primitive" | ||
(objectMemory isOopForwarded: rcvr) ifTrue: [ | ||
rcvr := objectMemory followForwarded: rcvr ]. | ||
Comment on lines
+980
to
+984
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a nice side effect, fixing the indexes here (0 based) "fixes" the following test in Pharo:
|
||
self | ||
pop: 4; | ||
push: rcvr ] | ||
ifFalse: [ self pop: 2 ]. | ||
argumentCount := arraySize. | ||
index := 1. | ||
[index <= arraySize] whileTrue: | ||
[self push: (objectMemory fetchPointer: index - 1 ofObject: argumentArray). | ||
index := index + 1]. | ||
|
||
self isPrimitiveFunctionPointerAnIndex ifTrue: | ||
[self executeQuickPrimitive. | ||
tempOop2 := 0. | ||
^nil]. | ||
[ index <= arraySize ] whileTrue: [ | ||
self push: | ||
(objectMemory fetchPointer: index - 1 ofObject: argumentArray). | ||
index := index + 1 ]. | ||
|
||
self isPrimitiveFunctionPointerAnIndex ifTrue: [ | ||
self executeQuickPrimitive. | ||
tempOop2 := savedTempOop2. | ||
^ nil ]. | ||
"We use tempOop instead of pushRemappableOop:/popRemappableOop here because in | ||
the Cogit primitiveEnterCriticalSection, primitiveSignal, primitiveResume et al longjmp back | ||
to either the interpreter or machine code, depending on the process activated. So if we're | ||
executing one of these primitives, control won't actually return here and the matching | ||
popRemappableOop: wouldn't occur, potentially overflowing the remap buffer. | ||
Note that while recursion could occur (nil tryPrimitive: 118 withArgs: #(118 #(110 #()))) | ||
it counts as shooting oneself in the foot." | ||
savedTempOop := tempOop. | ||
tempOop := argumentArray. "prim might alloc/gc" | ||
|
||
"Run the primitive (sets primFailCode)" | ||
"See checkForAndFollowForwardedPrimitiveState" | ||
metaAccessorDepth := primitiveAccessorDepthTable at: primIdx. | ||
self slowPrimitiveResponse. | ||
|
||
self successful ifFalse: "If primitive failed, then restore state for failure code" | ||
[self pop: arraySize. | ||
savedNumArgs = 3 ifTrue: | ||
[rcvr := self stackTop. | ||
self stackTopPut: tempOop2. | ||
self push: rcvr]. | ||
self pushInteger: primIdx. | ||
self push: tempOop. | ||
primitiveFunctionPointer := #primitiveDoPrimitiveWithArgs. | ||
argumentCount := savedNumArgs]. | ||
tempOop := tempOop2 := 0 | ||
self successful ifFalse: [ "If primitive failed, then restore state for failure code" | ||
self pop: arraySize. | ||
savedNumArgs = 3 ifTrue: [ | ||
rcvr := self stackTop. | ||
self stackTopPut: tempOop2. | ||
tempOop2 := savedTempOop2. | ||
self push: rcvr ]. | ||
self pushInteger: primIdx. | ||
self push: tempOop. | ||
primitiveFunctionPointer := #primitiveDoPrimitiveWithArgs. | ||
argumentCount := savedNumArgs. | ||
tempOop := savedTempOop ] | ||
] | ||
|
||
{ #category : 'control primitives' } | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
Class { | ||
#name : 'VMBasicPrimitiveTest', | ||
#superclass : 'VMInterpreterTests', | ||
#category : 'VMMakerTests-InterpreterTests', | ||
#package : 'VMMakerTests', | ||
#tag : 'InterpreterTests' | ||
} | ||
|
||
{ #category : 'asserting' } | ||
VMBasicPrimitiveTest >> assert: anOop contentEquals: oopToCompare [ | ||
|
||
| numSlotOop numSlotOopToCompare | | ||
numSlotOop := memory numSlotsOf: anOop. | ||
numSlotOopToCompare := (memory numSlotsOf: anOop). | ||
self assert: numSlotOop equals: numSlotOopToCompare. | ||
|
||
0 to: numSlotOop do: [:index | | ||
self assert: (memory fetchByte: index ofObject: anOop) equals: (memory fetchByte: index ofObject:oopToCompare) | ||
] | ||
|
||
] | ||
|
||
{ #category : 'as yet unclassified' } | ||
VMBasicPrimitiveTest >> fillNewSpace [ | ||
|
||
"Allocate enough space to generate a full new space" | ||
|
||
self assert: (memory | ||
allocateSlots: (memory scavengeThreshold - memory freeStart | ||
- (2 * memory baseHeaderSize) roundDownTo: 8) // self wordSize | ||
format: memory arrayFormat | ||
classIndex: memory arrayClassIndexPun) isNotNil | ||
] | ||
|
||
{ #category : 'instance creation' } | ||
VMBasicPrimitiveTest >> newArrayWith: aCollection [ | ||
| array | | ||
array := self newObjectWithSlots: aCollection size format: memory arrayFormat classIndex: memory arrayClassIndexPun. | ||
aCollection withIndexDo: [ :item :index | | ||
memory storePointer: index - 1 ofObject: array withValue: item | ||
]. | ||
^ array | ||
|
||
] | ||
|
||
{ #category : 'running' } | ||
VMBasicPrimitiveTest >> setUp [ | ||
"taken from VMSimpleStackBasedCogitBytecodeTest >> #setup" | ||
|
||
| newMethod ctx page | | ||
super setUp. | ||
|
||
"Create the root context with a valid method" | ||
"Let's create a method with enough size. It should have at least a literal (4 or 8 bytes depending the word size) and some bytecodes, so we can put the IP inside the method" | ||
newMethod := methodBuilder newMethod buildMethod. | ||
|
||
"The context has 5 (in 32 bits) or 9 (in 64 bits) as initial IP, as method has at least one literal" | ||
ctx := self | ||
newSmallContextReceiver: memory nilObject | ||
method: newMethod | ||
arguments: #( ) | ||
temporaries: #( ) | ||
ip: self wordSize + 1. | ||
|
||
page := interpreter makeBaseFrameFor: ctx. | ||
interpreter setStackPointersFromPage: page. | ||
interpreter setStackPageAndLimit: page | ||
] | ||
|
||
{ #category : 'tests - primitiveIdentical' } | ||
VMBasicPrimitiveTest >> setUpForwardedObjects [ | ||
| class1 class2 object1 object2 array1 array2 | | ||
|
||
class1 := self newClassInOldSpaceWithSlots: 1 instSpec: memory nonIndexablePointerFormat. | ||
class2 := self newClassInOldSpaceWithSlots: 2 instSpec: memory nonIndexablePointerFormat. | ||
|
||
object1 := memory instantiateClass: class1. | ||
object2 := memory instantiateClass: class2. | ||
|
||
array1 := self newArrayWith: { object1 }. | ||
array2 := self newArrayWith: { object2 }. | ||
|
||
interpreter push: array1. | ||
interpreter push: array2. | ||
|
||
interpreter primitiveArrayBecome. | ||
|
||
self assert: (memory isForwarded: object1) equals: true. | ||
self assert: (memory isForwarded: object2) equals: true. | ||
|
||
^ object1. | ||
] |
2 changes: 1 addition & 1 deletion
2
smalltalksrc/VMMakerTests/VMPrimitiveChangeClassParametrizedTest.class.st
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This first comment got moved by the reformatting, I'll put it back