Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
78633d5
Extracting stack state into separate struct
guillep Jun 23, 2026
360c455
Move simSpillBase
guillep Jun 23, 2026
0e1308a
Extracting simStackPtr
guillep Jun 23, 2026
74505f9
Add CogCompileTimeStackState to anciliary classes
guillep Jun 23, 2026
139ffe6
Specify type of simSpillBase
guillep Jun 23, 2026
030e39f
Remove cmacro:
guillep Jun 23, 2026
a8f367b
remove cmacro: for simSelf
guillep Jun 23, 2026
fd01877
Fix type errors due to extraction
guillep Jun 23, 2026
a557f5f
cleanup dead code
guillep Jun 23, 2026
072024f
more dead code
guillep Jun 23, 2026
67c0790
More dead code
guillep Jun 23, 2026
335c1d7
Add compile time state struct
guillep Jun 23, 2026
8a45fc4
Extract state into compileTimeState
guillep Jun 23, 2026
33e0d49
Rename compile time state class
guillep Jun 24, 2026
9a61cab
Remove clickConfim
guillep Jun 24, 2026
fb3a265
Remove constituents
guillep Jun 24, 2026
93ce626
Remove exclusion superseeded by unit testing
guillep Jun 24, 2026
5fd7765
BytecodeSetHasExtensions and BytecodeSetHasDirectedSuperSend are alwa…
guillep Jun 24, 2026
aae5f34
Remove simulation guardPageSize superseeded by unicorn's mappings
guillep Jun 24, 2026
780bd01
Remove lastNInstructions
guillep Jun 24, 2026
4294a0f
Cleanup debugging code
guillep Jun 24, 2026
8590e3c
Remove debugging code
guillep Jun 24, 2026
43c8a1c
Cleanup tracing
guillep Jun 24, 2026
98bf4c6
Remove unused variables
guillep Jun 24, 2026
8b93bed
Make CogStackToRegisterCompilationState extraction compile
guillep Jun 24, 2026
be821de
More type declarations
guillep Jun 24, 2026
c2c70f1
Declare aCompileTimeState
guillep Jun 24, 2026
7ae2718
Undo debugging leftovers
guillep Jun 24, 2026
f3a6b1b
Undo rename
guillep Jul 10, 2026
0876158
Fix tests:
guillep Jul 10, 2026
8d55ecd
Fix after refactoring
guillep Jul 10, 2026
ad619b3
Access ssTop through cogit compileTimeState simStackStateField
guillep Jul 10, 2026
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
1 change: 0 additions & 1 deletion smalltalksrc/Melchor/VMBasicConstants.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Class {
#superclass : 'SharedPool',
#classVars : [
'BaseHeaderSize',
'BytecodeSetHasExtensions',
'BytesPerOop',
'BytesPerWord',
'COGVM',
Expand Down
7 changes: 0 additions & 7 deletions smalltalksrc/Melchor/VMClass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,6 @@ VMClass class >> writeVMHeaderTo: aStream bytesPerWord: bytesPerWord generator:
aStream newLine
]

{ #category : 'translation support' }
VMClass >> addressOf: anObject [
<doNotGenerate>
"Translates into &anObject in C."
^anObject
]

{ #category : 'translation support' }
VMClass >> addressOf: anObject put: aBlock [
<doNotGenerate>
Expand Down
19 changes: 19 additions & 0 deletions smalltalksrc/Slang-Tests/SlangBasicTranslationTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6378,6 +6378,25 @@ SlangBasicTranslationTest >> testSendWordSize [
self assert: translation equals: 'BytesPerWord'
]

{ #category : 'tests-structs' }
SlangBasicTranslationTest >> testStructCastToPointer [

| translation tMethod |
tMethod := self getTMethodFrom: #methodAccessStructPointer.
translation := self translate: tMethod.
self
assert: translation
equals: '/* SlangBasicTranslationTestClass>>#methodAccessStructPointer */
static Struct *
methodAccessStructPointer(void)
{
Struct _t;

return somethingWithStructPointer(&_t);
}
'
]

{ #category : 'tests-builtins' }
SlangBasicTranslationTest >> testStructFieldIsRenamedWithReservedWord [
"Tests if the struct field is renamed when it's a reserved word"
Expand Down
18 changes: 18 additions & 0 deletions smalltalksrc/Slang-Tests/SlangBasicTranslationTestClass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ SlangBasicTranslationTestClass >> initializationOptions [
^ nil
]

{ #category : 'inline' }
SlangBasicTranslationTestClass >> methodAccessStructPointer [

| t |
<var: #t type: #Struct >

"This should automatically extract the pointer from t
somethingWithStructPointer(&t)"
^ self somethingWithStructPointer: (self addressOf: t)
]

{ #category : 'inline' }
SlangBasicTranslationTestClass >> methodCallingCFunction [

Expand Down Expand Up @@ -373,6 +384,13 @@ SlangBasicTranslationTestClass >> methodWithoutReturn [
<returnTypeC: #sqInt>
]

{ #category : 'inline' }
SlangBasicTranslationTestClass >> somethingWithStructPointer: t [

<var: #t type: #'Struct *'>
^ t
]

{ #category : 'inline-comment' }
SlangBasicTranslationTestClass >> switchInReturn [

Expand Down
1 change: 0 additions & 1 deletion smalltalksrc/Slang/CCodeGenerator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5114,7 +5114,6 @@ CCodeGenerator >> typeForDereference: sendNode in: aTMethod [
{ #category : 'C code generator' }
CCodeGenerator >> typeOfVariable: varName [
"<String>"

self assert: varName isString.
scopeStack reverseDo: [ :scope |
(scope declarations includesKey: varName) ifTrue: [
Expand Down
7 changes: 7 additions & 0 deletions smalltalksrc/Slang/SlangClass.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ SlangClass class >> typeForSelf [
^nil
]

{ #category : 'translation support' }
SlangClass >> addressOf: anObject [
<doNotGenerate>
"Translates into &anObject in C."
^anObject
]

{ #category : 'translation support' }
SlangClass >> cCall: function [
"Support for Smalltalk-to-C translation.
Expand Down
97 changes: 2 additions & 95 deletions smalltalksrc/VMMaker/CoInterpreter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ Class {
'MinBackwardJumpCountForCompile',
'PrimTraceLogSize',
'RumpCStackSize',
'TraceBlockActivation',
'TraceBlockCreation',
'TraceBufferSize',
'TraceCodeCompaction',
'TraceContextSwitch',
Expand All @@ -113,9 +111,7 @@ Class {
'TracePrimitiveFailure',
'TracePrimitiveRetry',
'TraceSources',
'TraceStackOverflow',
'TraceVMCallback',
'TraceVMCallbackReturn'
'TraceStackOverflow'
],
#pools : [
'CogMethodConstants',
Expand Down Expand Up @@ -285,13 +281,9 @@ CoInterpreter class >> initializeMiscConstants [
PrimTraceLogSize := 256. "Room for 256 selectors. Must be 256 because we use a byte to hold the index"
TraceBufferSize := 256 * 3. "Room for 256 events"
TraceContextSwitch := self objectMemoryClass basicNew integerObjectOf: 1.
TraceBlockActivation := self objectMemoryClass basicNew integerObjectOf: 2.
TraceBlockCreation := self objectMemoryClass basicNew integerObjectOf: 3.
TraceIncrementalGC := self objectMemoryClass basicNew integerObjectOf: 4.
TraceFullGC := self objectMemoryClass basicNew integerObjectOf: 5.
TraceCodeCompaction := self objectMemoryClass basicNew integerObjectOf: 6.
TraceVMCallback := self objectMemoryClass basicNew integerObjectOf: 11.
TraceVMCallbackReturn := self objectMemoryClass basicNew integerObjectOf: 12.
TraceStackOverflow := self objectMemoryClass basicNew integerObjectOf: 13.
TracePrimitiveFailure := self objectMemoryClass basicNew integerObjectOf: 14.
TracePrimitiveRetry := self objectMemoryClass basicNew integerObjectOf: 15.
Expand All @@ -315,7 +307,6 @@ CoInterpreter class >> initializePrimitiveTable [
[:pidx| self assert: (PrimitiveTable at: pidx + 1) = #primitiveFail].
self assert: (PrimitiveTable at: 215 + 1) = #primitiveFlushCacheByMethod.
PrimitiveTable
at: 253 + 1 put: #primitiveCollectCogCodeConstituents;
at: 215 + 1 put: #primitiveVoidVMStateForMethod;
at: 216 + 1 put: #primitiveMethodXray;
at: 217 + 1 put: #primitiveMethodProfilingData
Expand Down Expand Up @@ -1100,8 +1091,6 @@ CoInterpreter >> ceCheckAndMaybeRetryPrimitive: primIndex [
CoInterpreter >> ceCheckForInterrupts [
<api>
| switched |
self cCode: [] inSmalltalk:
[self maybeCheckStackDepth: 0 sp: stackPointer pc: instructionPointer].
switched := self checkForEventsMayContextSwitch: true.
self returnToExecutive: false postContextSwitch: switched
]
Expand Down Expand Up @@ -1440,7 +1429,6 @@ CoInterpreter >> ceSend: maybeForwardedSelector above: methodClass to: receiver
<api>
<story: #pic>
<inline: false>
<option: #BytecodeSetHasDirectedSuperSend>
| classTag classObj |
self assert: (objectMemory addressCouldBeOop: receiver).

Expand All @@ -1467,7 +1455,6 @@ CoInterpreter >> ceSend: selector aboveClassBinding: methodClassBinding to: rcvr
args
head sp -> sender return pc"
<api>
<option: #BytecodeSetHasDirectedSuperSend>
self ceSend: selector
above: (self fetchPointer: ValueIndex
ofObject: (objectMemory followMaybeForwarded: methodClassBinding))
Expand Down Expand Up @@ -1726,48 +1713,6 @@ CoInterpreter >> ceStackOverflow: contextSwitchIfNotNil [

]

{ #category : 'debug support' }
CoInterpreter >> ceTraceBlockActivation [
<api>
cogit recordBlockTrace ifTrue:
[self recordTrace: TraceBlockActivation
thing: (self mframeHomeMethod: framePointer) methodObject
source: TraceIsFromMachineCode.
cogit printOnTrace ifTrue:
[self printActivationNameFor: (self mframeHomeMethod: framePointer) methodObject
receiver: (self frameReceiver: framePointer)
isBlock: true
firstTemporary: nil.
self cr]]
]

{ #category : 'debug support' }
CoInterpreter >> ceTraceLinkedSend: theReceiver [
| cogMethod |
<api>
<var: #cogMethod type: #'CogMethod *'>
cogMethod := self cCoerceSimple: (self stackTop - cogit traceLinkedSendOffset)
to: #'CogMethod *'.
self cCode: [] inSmalltalk:
[cogit checkStackDepthOnSend ifTrue:
[self maybeCheckStackDepth: (cogMethod cmNumArgs > cogit numRegArgs
ifTrue: [cogMethod cmNumArgs + 1]
ifFalse: [0])
sp: stackPointer + objectMemory wordSize
pc: (self stackValue: 1)]].
"cogit recordSendTrace ifTrue: is implicit; wouldn't compile the call otherwise."
self recordTrace: (objectMemory fetchClassOf: theReceiver)
thing: cogMethod selector
source: TraceIsFromMachineCode.
cogit printOnTrace ifTrue:
[self printActivationNameFor: cogMethod methodObject
receiver: theReceiver
isBlock: false
firstTemporary: (self cCode: [nil] inSmalltalk: [0]);
cr].
self sendBreakpoint: cogMethod selector receiver: theReceiver
]

{ #category : 'trampolines' }
CoInterpreter >> ceTraceStoreOf: aValue into: anObject [
<api>
Expand Down Expand Up @@ -2145,18 +2090,6 @@ CoInterpreter >> divorceSomeMachineCodeFramesWithMethod: cogMethod [
^ divorcedSome
]

{ #category : 'send bytecodes' }
CoInterpreter >> doRecordSendTrace [

<inline: true>
cogit recordSendTrace ifTrue: [
self
recordTrace: (objectMemory classForClassTag: lkupClassTag)
thing: messageSelector
source: TraceIsFromInterpreter.
super doRecordSendTrace ]
]

{ #category : 'debug support' }
CoInterpreter >> dumpPrimTraceLog [
"The prim trace log is a circular buffer of entries. If there is
Expand Down Expand Up @@ -3604,16 +3537,6 @@ CoInterpreter >> maybeReturnToMachineCodeFrame [
instructionPointer := self pointerForOop: (self iframeSavedIP: framePointer) ]
]

{ #category : 'stack bytecodes' }
CoInterpreter >> maybeTraceBlockCreation: newClosure [

cogit recordSendTrace ifTrue: [
self
recordTrace: TraceBlockCreation
thing: newClosure
source: TraceIsFromInterpreter ]
]

{ #category : 'debug support' }
CoInterpreter >> maybeTraceStackOverflow [
cogit recordOverflowTrace ifTrue:
Expand Down Expand Up @@ -4329,20 +4252,12 @@ CoInterpreter >> printLogEntryAt: i [
[self print: 'stack overflow'].
intOrClass = TraceContextSwitch ifTrue:
[self print: 'context switch from '; printHex: selectorMethodOrProcess].
intOrClass = TraceBlockActivation ifTrue:
[self print: ' [] in '; printHex: selectorMethodOrProcess].
intOrClass = TraceBlockCreation ifTrue:
[self print: 'create [] '; printHex: selectorMethodOrProcess].
intOrClass = TraceIncrementalGC ifTrue:
[self print: 'incrementalGC'].
intOrClass = TraceFullGC ifTrue:
[self print: 'fullGC'].
intOrClass = TraceCodeCompaction ifTrue:
[self print: 'compactCode'].
intOrClass = TraceVMCallback ifTrue:
[self print: 'callback'].
intOrClass = TraceVMCallbackReturn ifTrue:
[self print: 'return from callback']]
[self print: 'compactCode'] ]
ifFalse:
[self space; printNameOfClass: intOrClass count: 5; print: '>>'; printStringOf: selectorMethodOrProcess].
source > TraceIsFromInterpreter ifTrue:
Expand Down Expand Up @@ -4447,12 +4362,6 @@ CoInterpreter >> printPrimLogEntryAt: i [
ifFalse: [objectMemory safePrintStringOf: intOrSelector]]
]

{ #category : 'debug printing' }
CoInterpreter >> printSends [
<inline: true>
^cogit printOnTrace
]

{ #category : 'cog jit support' }
CoInterpreter >> quickPrimitiveConstantFor: aQuickPrimitiveIndex [
<api>
Expand Down Expand Up @@ -4692,8 +4601,6 @@ CoInterpreter >> returnToMachineCodeFrame [
line: #__LINE__.
self stackTopPut: instructionPointer.
self push: localReturnValue.
self cCode: '' inSmalltalk: [
self maybeCheckStackDepth: 1 sp: stackPointer pc: instructionPointer ].
self callEnilopmart: #ceEnterCogCodePopReceiverReg.
self unreachable
]
Expand Down
21 changes: 0 additions & 21 deletions smalltalksrc/VMMaker/CoInterpreterPrimitives.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,6 @@ CoInterpreterPrimitives >> primitiveAllMethodsCompiledToMachineCode [
self pop: 1 thenPush: arrayObj
]

{ #category : 'process primitives' }
CoInterpreterPrimitives >> primitiveCollectCogCodeConstituents [
"Answer the contents of the code zone as an array of pair-wise element, address in ascending
address order. Answer a string for a runtime routine or abstract label (beginning, end, etc),
a CompiledMethod for a CMMethod, or a selector (presumably a Symbol) for a PIC.
If there is an argument and it is true, then collect inner information about the CogMethod."
| constituents withDetails |
argumentCount = 0
ifTrue: [withDetails := false]
ifFalse:
[withDetails := self stackTop.
(withDetails = objectMemory trueObject
or: [withDetails = objectMemory falseObject]) ifFalse:
[^self primitiveFailFor: PrimErrBadArgument].
withDetails := withDetails = objectMemory trueObject].
constituents := cogit cogCodeConstituents: withDetails.
constituents ifNil:
[^self primitiveFailFor: PrimErrNoMemory].
self pop: argumentCount + 1 thenPush: constituents
]

{ #category : 'indexing primitives' }
CoInterpreterPrimitives >> primitiveContextXray [
"Lift the veil from a context and answer an integer describing its interior state.
Expand Down
2 changes: 0 additions & 2 deletions smalltalksrc/VMMaker/CogBytecodeFixup.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ CogBytecodeFixup class >> instVarNamesAndTypesForTranslationDo: aBinaryBlock [
['mergeSimStack'] -> [#'SimStackEntry *'].
['instructionIndex'] -> [#'unsigned short'].
['simStackPtr'] -> [#'unsigned char'].
['simNativeStackPtr'] -> [#'short'].
['simNativeStackSize'] -> [#'unsigned short'].
['isTargetOfBackwardBranch'] -> [#char] }])]
]

Expand Down
Loading