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

Fix vm #161

Merged
merged 11 commits into from
Feb 6, 2025
16 changes: 16 additions & 0 deletions Druid-Tests/DRBytecodeCompilationTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ DRBytecodeCompilationTest >> makeFrame: aReceiver arguments: arguments method: a

]

{ #category : #'as yet unclassified' }
DRBytecodeCompilationTest >> popAndReturn: reg [

self isSimpleStack
ifTrue: [ cogit PopR: reg ]
ifFalse: [ cogit ssPopTopToReg: reg ].
cogit genUpArrowReturn
]

{ #category : #helpers }
DRBytecodeCompilationTest >> prepareStackForPrimitiveReceiver: aReceiver arguments: arguments method: aMethod [

Expand All @@ -148,3 +157,10 @@ DRBytecodeCompilationTest >> prepareStackForSendReceiver: aReceiver arguments: a
self pushAddress: memory nilObject ]

]

{ #category : #helpers }
DRBytecodeCompilationTest >> setUp [

super setUp.
cogit useTwoPaths: false
]
3 changes: 3 additions & 0 deletions Druid-Tests/DRCustomisedCompilerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ DRCustomisedCompilerTest >> testAddsPreambleToGeneratedCode [
DRCustomisedCompilerTest >> testIsMappedShouldAnnotateBytecode [

| cfg |
"Now the annotateBytecode: is introduced during code generation, it is not in the CFG anymore."
self skip.

compiler := self newBytecodeCompiler.
cfg := self generateDruidIRFor: #extUnconditionalJump.

Expand Down
2 changes: 1 addition & 1 deletion Druid-Tests/DRDruidTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ DRDruidTest >> jitCompilerClass [
DRDruidTest >> jitOptions [

^ super jitOptions
at: #bytecodeTableInitializer put: #initializeBytecodeTableForSistaV1;
at: #IMMUTABILITY put: true;
yourself
]

Expand Down
92 changes: 87 additions & 5 deletions Druid-Tests/DRProductionBytecodeTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ DRProductionBytecodeTest >> setUp [

"Set a random methodObj and bytecodePC to avoid nil errors"
cogit methodObj: method.
cogit bytecodePC: 1.
cogit bytecodePC: 1
]

{ #category : #tests }
Expand Down Expand Up @@ -397,6 +397,7 @@ DRProductionBytecodeTest >> testBytecodeExtendedUnconditionalJump [

self assert: machineSimulator receiverRegisterValue equals: memory trueObject.

self flag: #TODO. "Force bytecode annotation on staged branches!"
self assert: (cogit hasAnnotatedAbstractInstructions: cogit getIsBytecodePCReference)
]

Expand Down Expand Up @@ -1180,7 +1181,7 @@ DRProductionBytecodeTest >> testBytecodePushLiteralVariableDoesOverrideTopAlloca
{ #category : #tests }
DRProductionBytecodeTest >> testBytecodePushLiteralVariableDoesOverrideTopAllocatedRegister: n [

| method x |
| method |
method := methodBuilder newMethod
literals:
(((1 to: 16) collect: [ :e | nil -> (e + 16rFF - 1) ])
Expand Down Expand Up @@ -1223,6 +1224,46 @@ DRProductionBytecodeTest >> testBytecodePushLiteralVariableDoesOverrideTopAlloca
equals: 1
]

{ #category : #tests }
DRProductionBytecodeTest >> testBytecodePushNewArray [

| size |
size := 1.
cogit ceDeoptimiseFrameTrampoline: fakeTrampoline.
cogit byte1: size.

self compileBytecode: 231 selector: #pushNewArrayBytecode thenDo: [ :generator |
generator value.
self popAndReturn: ReceiverResultReg ].

self executePrimitiveWithReceiver: memory nilObject.


self assert: (memory isArray: machineSimulator receiverRegisterValue).
self assert: (memory numSlotsOf: machineSimulator receiverRegisterValue) equals: size.
self assert: (memory fetchPointer: 0 ofObject: machineSimulator receiverRegisterValue) equals: memory nilObject

]

{ #category : #tests }
DRProductionBytecodeTest >> testBytecodePushNewArrayBig [

| size |
size := 10.
cogit ceDeoptimiseFrameTrampoline: fakeTrampoline.
cogit byte1: size.

"Allocation touch the threshold"
memory scavengeThreshold: memory freeStart + 1.

self compileBytecode: 231 selector: #pushNewArrayBytecode thenDo: [ :generator |
generator value.
self popAndReturn: ReceiverResultReg ].

"Deoptimize to run the scavenge"
self runFrom: cogInitialAddress until: fakeTrampoline
]

{ #category : #tests }
DRProductionBytecodeTest >> testBytecodePushReceiverDoesNotOverridePreviousPush [

Expand Down Expand Up @@ -2277,6 +2318,46 @@ DRProductionBytecodeTest >> testExtBBytecode3 [
self assert: cogit numExtB equals: 1
]

{ #category : #tests }
DRProductionBytecodeTest >> testExtPushFullClosure [
"Fake test, only assert the correct generation of the method."

self
compileBytecode: 249
selector: #extPushFullClosureBytecode
thenDo: [ :generator | self flag: #TODO "Test the execution of compiled code" ]
]

{ #category : #tests }
DRProductionBytecodeTest >> testExtStoreAndPopReceiverVariableBytecode [

| object index |
cogit ceStoreCheckTrampoline: fakeTrampoline.
cogit ceDeoptimiseFrameTrampoline: fakeTrampoline.
cogit bytecodePC: 87.
cogit byte1: (index := 1).

self
compileBytecode: 240
selector: #extStoreAndPopReceiverVariableBytecode
thenDo: [ :generator |
cogit ssPushRegister: TempReg.

"Execute the druid's compiled code"
generator value.

"Then return without druid's compiled code"
cogit genUpArrowReturn ].

object := self newObjectWithSlots: index + 1.

machineSimulator temporaryRegisterValue: memory trueObject.
self executePrimitiveWithReceiver: object.

self assert: machineSimulator receiverRegisterValue equals: object.
self assert: (memory fetchPointer: index ofObject: object) equals: memory trueObject
]

{ #category : #tests }
DRProductionBytecodeTest >> testExtStoreLiteralVariableBytecode [

Expand Down Expand Up @@ -2844,7 +2925,7 @@ DRProductionBytecodeTest >> testStoreAndPopReceiverVariableBytecodeCallImmutable

object := self newObjectWithSlots: 1.
memory setIsImmutableOf: object to: true.

value := self newObjectWithSlots: 0.

machineSimulator temporaryRegisterValue: value.
Expand All @@ -2856,8 +2937,9 @@ DRProductionBytecodeTest >> testStoreAndPopReceiverVariableBytecodeCallImmutable

"Should arrive to trampoline to put the object in the remembered set"
self runFrom: cogInitialAddress until: immutableTrampoline.

self assert: machineSimulator receiverRegisterValue equals: bytecodePC

self assert: machineSimulator receiverRegisterValue equals: bytecodePC.
self assert: machineSimulator smalltalkStackPointerValue equals: value
]

{ #category : #tests }
Expand Down
22 changes: 22 additions & 0 deletions Druid-Tests/DRProductionPrimitiveCompilationTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,28 @@ DRProductionPrimitiveCompilationTest >> testCompilePrimitiveAtPut [
equals: (memory integerObjectOf: 42)
]

{ #category : #'tests-object-modify' }
DRProductionPrimitiveCompilationTest >> testCompilePrimitiveAtPutImmutable [

| class array |
self timeLimit: (Duration minutes: 5).
cogit ceStoreCheckTrampoline: fakeTrampoline.

self compileDruidPrimitive: #primitiveAtPut.

class := self newClassInOldSpaceWithSlots: 0 instSpec: memory arrayFormat.
array := memory instantiateClass: class indexableSize: 1.

memory setIsImmutableOf: array to: true.


self executeUntilStopPrimitiveWithReceiver: array withArguments: {
(memory integerObjectOf: 1).
(memory integerObjectOf: 42) }.

self assert: (memory fetchPointer: 0 ofObject: array) equals: memory nilObject
]

{ #category : #'tests-object-access' }
DRProductionPrimitiveCompilationTest >> testCompilePrimitiveClass [

Expand Down
Loading
Loading