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

Retracing foreign proxies #86

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ private - stepping
basicCalleeOf: aContext
"Answer the context whose sender is aContext."

^ self context findContextSuchThat: [:c | c sender == aContext]
^ self context findContextSuchThat: [:c | c sender tdbIdentical: aContext]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ doStepOver: aContext
ifTrue:
[self step ifNil: [^ self].
((self context tdbIdentical: aContext) not
and: [aContext in: [:ctx | self context hasSender: ctx]])
and: [self context hasSender: aContext tdbproxyYourself])
ifTrue: [self completeStep: self context]].
self stepToSendOrReturn].
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"allContextsDo:" : "ct 2/20/2022 21:00",
"allContextsGather:" : "ct 3/11/2022 19:14",
"assureTracingDuring:" : "ct 3/17/2022 19:47",
"basicCalleeOf:" : "ct 2/20/2022 21:12",
"basicCalleeOf:" : "ct 7/7/2022 17:01",
"basicStep" : "ct 3/16/2022 00:25",
"basicStepBack" : "ct 3/11/2022 16:11",
"calleeOf:" : "ct 3/17/2022 19:16",
Expand All @@ -45,7 +45,7 @@
"doStepInto" : "ct 3/11/2022 16:48",
"doStepInto:" : "ct 3/16/2022 16:41",
"doStepOver" : "ct 3/11/2022 16:48",
"doStepOver:" : "ct 3/16/2022 16:40",
"doStepOver:" : "ct 7/7/2022 17:04",
"doStepThrough" : "ct 3/11/2022 16:48",
"doStepThrough:" : "ct 3/11/2022 16:48",
"doStepThrough:until:" : "ct 3/17/2022 19:20",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
controlling
context: aContext doPrimitive: primitiveIndex method: aCompiledMethod receiver: receiver args: originalArguments do: aBlock
"Redirect primitives that read any state. If the relevant object's slot is defined in the historic memory, use the recorded state from there instead of the current state for the object in the image."
"Redirect primitives that read any state. If the relevant object's slot is defined in the historic memory, use the recorded state from there instead of the current state for the object in the image."

| arguments receiverAndArgs |
"Resolve proxy receiver/arguments for the same memory by replacing them with the original object. See TDBProxy>>#xxxtdbproxyForward: and senders."
arguments := nil.
originalArguments withIndexDo: [:argument :index |
((aContext objectClass: argument) isTdbProxyClass
and: [argument xxxtdbproxyMemory == memory])
ifTrue: [(arguments ifNil: [arguments := originalArguments copy])
at: index put: argument xxxtdbproxyObject]].
and: [argument xxxtdbproxyMemory == memory
and: [argument xxxtdbproxyTimeIndex = timeIndices]])
ifTrue: [(arguments ifNil: [arguments := originalArguments copy])
at: index put: argument xxxtdbproxyObject]].
arguments ifNil: [arguments := originalArguments].

self flag: #todo. "Handle missing arguments gracefully"
self flag: #optimize. "Do not combine unused arguments (e.g., for mirror primitives)"
self flag: #optimize. "Array lookup for primitives?"

(PrimitiveHandlers at: primitiveIndex) ifNotNil: [:handler |
^ self perform: handler withArguments: {aContext. primitiveIndex. aCompiledMethod. receiver. arguments. aBlock}].
| result |
lastPrimitive := primitiveIndex.
result := self perform: handler withArguments: {aContext. primitiveIndex. aCompiledMethod. receiver. arguments. aBlock}.
lastPrimitive := nil.
^ result].

receiverAndArgs := self
context: aContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ context: aContext send: selector super: superFlag numArgs: numArgs do: aBlock
numArgs to: 1 by: -1 do: [:i | arguments at: i put: aContext pop].
thisReceiver := aContext pop.

"Resolve proxy receiver for the same memory by replacing them with the original receiver. See TDBProxy>>#xxxtdbproxyForward: and senders."
((aContext objectClass: thisReceiver) isTdbProxyClass
and: [thisReceiver xxxtdbproxyMemory == memory
and: [thisReceiver xxxtdbproxyTimeIndex = timeIndices]])
ifTrue:
[thisReceiver := thisReceiver xxxtdbproxyObject].

lookupClass := self context: aContext combineArguments: {thisReceiver} collect: [:eachReceiver |
aContext objectClass: eachReceiver first].
(self context: aContext isVector: lookupClass) ifTrue:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,23 @@
"initializePrimitiveHandlers" : "ct 6/1/2022 11:41" },
"instance" : {
"context:combineArguments:collect:" : "ct 6/18/2022 15:29",
"context:doPrimitive:method:receiver:args:do:" : "ct 6/18/2022 15:53",
"context:doPrimitive:method:receiver:args:do:" : "ct 7/5/2022 16:47",
"context:doReadPrimitive:method:receiver:args:do:" : "ct 7/3/2022 01:39",
"context:doWritePrimitive:method:receiver:args:do:" : "ct 7/3/2022 01:40",
"context:isVector:" : "ct 5/28/2022 22:48",
"context:jump:if:do:" : "ct 5/28/2022 21:21",
"context:okToStore:inBits:" : "ct 6/2/2022 13:54",
"context:primitiveBitBlt:method:receiver:arguments:do:" : "ct 6/3/2022 00:35",
"context:pushReceiverVariable:do:" : "ct 6/2/2022 10:41",
"context:return:from:do:" : "ct 5/30/2022 14:49",
"context:return:from:do:" : "ct 7/2/2022 19:36",
"context:runPrimitive:method:receiver:args:" : "ct 6/1/2022 11:57",
"context:runSimulated:contextAtEachStep:do:" : "ct 7/5/2022 17:47",
"context:send:super:numArgs:do:" : "ct 6/2/2022 10:41",
"context:send:super:numArgs:do:" : "ct 7/5/2022 16:47",
"context:sendSpecial:numArgs:do:" : "ct 5/28/2022 22:42",
"context:simulatedObject:basicAt:ifHit:" : "ct 6/3/2022 18:09",
"context:simulatedObject:basicAt:ifHit:" : "ct 7/7/2022 15:05",
"context:simulatedObject:instVarAt:ifHit:" : "ct 6/3/2022 18:09",
"context:simulatedObject:instVarAt:put:do:" : "ct 7/5/2022 10:39",
"contextCleanVectors:arguments:" : "ct 7/5/2022 19:13",
"contextCopies" : "ct 5/26/2022 17:56",
"contextCopies:" : "ct 5/26/2022 17:57",
"contextForceRetracingFork:arguments:" : "ct 6/1/2022 16:49",
Expand All @@ -55,6 +56,5 @@
"matchesSimulator:" : "ct 5/28/2022 19:37",
"memorySliceClass" : "ct 6/2/2022 15:02",
"postFork" : "ct 6/3/2022 18:09",
"timeIndex" : "ct 7/7/2022 15:07",
"timeIndices" : "ct 5/12/2022 12:31",
"timeIndices:" : "ct 5/28/2022 19:24" } }
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ context: aContext doPrimitive: primitiveIndex method: aCompiledMethod receiver:
arguments := nil.
originalArguments withIndexDo: [:argument :index |
((aContext objectClass: argument) isTdbProxyClass
and: [argument xxxtdbproxyMemory == memory])
ifTrue: [(arguments ifNil: [arguments := originalArguments copy])
at: index put: argument xxxtdbproxyObject]].
and: [argument xxxtdbproxyMemory == memory
and: [argument xxxtdbproxyTimeIndex = self timeIndex]])
ifTrue: [(arguments ifNil: [arguments := originalArguments copy])
at: index put: argument xxxtdbproxyObject]].
arguments ifNil: [arguments := originalArguments].

^ super
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ context: aContext send: selector to: originalReceiver with: arguments lookupIn:
| receiver lookupClass |
"Resolve proxy receiver for the same memory by replacing them with the original receiver. See TDBProxy>>#xxxtdbproxyForward: and senders."
((aContext objectClass: (receiver := originalReceiver)) isTdbProxyClass
and: [originalReceiver xxxtdbproxyMemory == memory])
ifTrue:
[receiver := originalReceiver xxxtdbproxyObject.
lookupClass := aContext objectClass: receiver].
and: [originalReceiver xxxtdbproxyMemory == memory
and: [originalReceiver xxxtdbproxyTimeIndex = self timeIndex]])
ifTrue:
[receiver := originalReceiver xxxtdbproxyObject.
lookupClass := aContext objectClass: receiver].

^ super
context: aContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
"forMemory:atTime:" : "ct 5/12/2022 12:22",
"forMemory:atTimes:" : "ct 5/12/2022 12:30" },
"instance" : {
"context:doPrimitive:method:receiver:args:do:" : "ct 5/28/2022 19:22",
"context:primitiveTraceDebugger:receiver:arguments:" : "ct 6/1/2022 18:56",
"context:send:to:with:lookupIn:do:" : "ct 5/2/2022 22:24",
"context:doPrimitive:method:receiver:args:do:" : "ct 7/5/2022 16:46",
"context:primitiveTraceDebugger:receiver:arguments:" : "ct 7/5/2022 19:07",
"context:send:to:with:lookupIn:do:" : "ct 7/7/2022 15:39",
"contextForceRetracingFork:arguments:" : "ct 6/1/2022 18:56",
"contextPushRetracingTimeIndex:" : "ct 7/5/2022 16:45",
"contextPushRetracingTimeIndex:" : "ct 6/1/2022 18:56",
"initialize" : "ct 5/10/2022 23:30",
"memory" : "ct 5/2/2022 13:53",
"memory:" : "ct 5/2/2022 13:53",
"printOn:" : "ct 7/5/2022 16:45",
"sideEffects" : "ct 6/18/2022 16:00",
"sideEffects:" : "ct 6/18/2022 16:00",
"timeIndex" : "ct 7/5/2022 16:44",
"wantsToControlReads" : "ct 5/10/2022 21:18" } }
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ failures
expectedFailures

^ super expectedFailures ,
{#testAutomaticCoalescion flag: #gc}
{#testAutomaticCoalescion flag: #gc.
#testForeignProxy "Nested range retracing is not possible because the outer simulator cannot distinguish between vectors and actual TDBMemorySlice instances created by the inner simulator"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tests
testForeignProxy

| proxy |
simulator timeIndices: (2 to: 3).
proxy := memory object: object atTimes: (2 to: 4) withSideEffects: nil.
self assertQuery: [proxy griffle] values: #(3). "intersection of (2 to: 4) and (2 to: 3)"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tests
testOwnProxy

| proxy |
simulator timeIndices: (3 to: 4).
proxy := memory object: object atTimes: (3 to: 4) withSideEffects: nil.
self assertQuery: [proxy griffle] values: #(3 2).
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"assertSlice:times:values:" : "ct 7/7/2022 16:35",
"classUnderTest" : "ct 5/26/2022 15:37",
"denyForkDuring:" : "ct 5/27/2022 15:25",
"expectedFailures" : "ct 6/2/2022 15:10",
"expectedFailures" : "ct 7/7/2022 15:48",
"memorySliceClass" : "ct 6/1/2022 13:01",
"newSimulator" : "ct 5/26/2022 15:40",
"testAutomaticCoalescion" : "ct 5/26/2022 19:03",
Expand All @@ -23,14 +23,17 @@
"testCloneObject" : "ct 7/3/2022 23:08",
"testCombineArgumentsCollect" : "ct 6/2/2022 10:28",
"testContextPrimitives" : "ct 7/3/2022 01:30",
"testCutVectorFromSideEffect" : "ct 7/7/2022 16:44",
"testDebugForks" : "ct 6/2/2022 10:27",
"testError" : "ct 6/2/2022 10:41",
"testForeignProxy" : "ct 7/7/2022 15:41",
"testIsolateState" : "ct 5/26/2022 15:45",
"testIsolatedForks" : "ct 5/26/2022 20:04",
"testJump" : "ct 5/26/2022 19:05",
"testMaintainSlices" : "ct 6/2/2022 18:05",
"testMessageSend" : "ct 5/27/2022 15:18",
"testNonLocalReturn" : "ct 5/27/2022 16:14",
"testOwnProxy" : "ct 7/7/2022 15:35",
"testPrimitive118" : "ct 6/18/2022 15:40",
"testPrimitiveExecuteMethod" : "ct 7/7/2022 16:54",
"testPrimitiveStringAtPut" : "ct 7/2/2022 23:42",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tests
testForeignProxy

| proxy |
proxy := memory object: object atTime: 4.
self assert: 3 equals: (simulator evaluate: [proxy griffle]).
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tests
testOwnProxy

| proxy |
proxy := memory object: object atTime: 3.
self assert: 3 equals: (simulator evaluate: [proxy griffle]).
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"instance" : {
"newSimulator" : "ct 5/10/2022 21:54",
"testContextPrimitives" : "ct 7/3/2022 01:53",
"testForeignProxy" : "ct 7/7/2022 15:35",
"testIsolatePrimitives" : "ct 5/26/2022 16:01",
"testIsolateState" : "ct 5/26/2022 16:03",
"testOwnProxy" : "ct 7/7/2022 15:33",
"testPrimitive118" : "ct 6/18/2022 15:40",
"testPrimitiveExecuteMethod" : "ct 7/7/2022 16:54",
"testReadYourOwnWrites" : "ct 5/10/2022 21:46",
Expand Down