Skip to content

Commit

Permalink
Renames, cleanups and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
guillep committed Sep 7, 2023
1 parent e1ec3bc commit 4fff7b9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
18 changes: 9 additions & 9 deletions src/MethodProxies-Tests/MpMethodProxyTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ MpMethodProxyTest >> testInstallSetCompiledMethod [
mw install.
self assert: mw selector equals: #methodOne.
self assert: mw methodClass equals: MpClassA.
self assert: mw wrappedMethod equals: method ] ensure: [
self assert: mw proxifiedMethod equals: method ] ensure: [
mw uninstall ]
]

Expand Down Expand Up @@ -362,7 +362,7 @@ MpMethodProxyTest >> testUninstall [
mp install.
self assert:
(MpClassA compiledMethodAt: #methodOne) selector = #methodOne.
self assert: (MpClassA compiledMethodAt: #methodOne) == mp trap ]
self assert: (MpClassA compiledMethodAt: #methodOne) == mp trapMethod ]
ensure: [
mp uninstall.
self assert: (MpClassA compiledMethodAt: #methodOne) == method ]
Expand All @@ -386,11 +386,11 @@ MpMethodProxyTest >> testUninstallNestedInRightOrderIsOk [
[
self
assert: (MpClassA compiledMethodAt: #methodOne)
identicalTo: mp2 trap ] ensure: [
identicalTo: mp2 trapMethod ] ensure: [
mp2 uninstall.
self
assert: (MpClassA compiledMethodAt: #methodOne)
identicalTo: mp trap ] ] ensure: [ mp uninstall ].
identicalTo: mp trapMethod ] ] ensure: [ mp uninstall ].
self
assert: (MpClassA compiledMethodAt: #methodOne)
identicalTo: method
Expand All @@ -404,7 +404,7 @@ MpMethodProxyTest >> testUnwrappedMethodAtOneLevelIsTheWrappedMethod [
mp := MpMethodProxy onMethod: method handler: self handlerClass new.
self installMethodProxy: mp.

self assert: mp wrappedMethod equals: method
self assert: mp proxifiedMethod equals: method
]

{ #category : #tests }
Expand All @@ -422,7 +422,7 @@ MpMethodProxyTest >> testUnwrappedMethodOfNestedMethodWrapperInTheCompiledMethod
handler: MpMockMethodProxyHandler new.
self installMethodProxy: mp2.

self assert: mp2 wrappedMethod equals: mp trap.
self assert: mp2 proxifiedMethod equals: mp trapMethod.
]

{ #category : #'tests - safety' }
Expand Down Expand Up @@ -495,14 +495,14 @@ MpMethodProxyTest >> testWrappingTwiceIsPossible [

self assert: mp1 selector equals: #methodOne.
self assert: mp1 methodClass equals: MpClassA.
self assert: mp1 wrappedMethod equals: method.
self assert: mp1 proxifiedMethod equals: method.

self assert: mp2 selector equals: #methodOne.
self assert: mp2 methodClass equals: MpClassA.
self assert: mp2 wrappedMethod equals: mp1 trap ] ensure: [
self assert: mp2 proxifiedMethod equals: mp1 trapMethod ] ensure: [
[
mp2 uninstall.
self assert: (MpClassA methodDict at: #methodOne) equals: mp1 trap ]
self assert: (MpClassA methodDict at: #methodOne) equals: mp1 trapMethod ]
ensure: [
mp1 uninstall.
self assert: (MpClassA methodDict at: #methodOne) equals: method ] ]
Expand Down
76 changes: 38 additions & 38 deletions src/MethodProxies/MpMethodProxy.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ Class {
#name : #MpMethodProxy,
#superclass : #Object,
#instVars : [
'proxyMethod',
'handler',
'hiddenSelector',
'trapMethod',
'wrappedMethod'
'wrappedMethod',
'proxifiedMethod'
],
#category : #MethodProxies
}
Expand All @@ -77,7 +77,7 @@ MpMethodProxy class >> buildPrototypesUpToArguments: maxNumberOfArguments [
| originalAst trapSelector trapArguments |
originalAst := (self class >> #prototypeTrap) parseTree.

trapSelector := #trap.
trapSelector := #trapMethod.
1 to: numberOfArguments do: [ :i |
trapSelector := trapSelector , #with: ].
trapArguments := (1 to: numberOfArguments) collect: [ :i |
Expand Down Expand Up @@ -162,15 +162,15 @@ MpMethodProxy class >> proxyMethod: method handler: aHandler [
]

{ #category : #'as yet unclassified' }
MpMethodProxy class >> trap [
MpMethodProxy class >> trapMethod [
"The unwind handler should be the first temp, the complete flag should be the second temp.
Then this method is free to use as many extra temporaries and arguments as is wants"

<primitive: 198>
| deactivator complete result process wasMeta |
"Quick check, if we are in a meta-level do not instrument"
process := thisProcess.
process isMeta ifTrue: [ ^ self trap ].
process isMeta ifTrue: [ ^ self trapMethod ].

"Set the deactivator literal that will be later patched as exception handler"
deactivator := #deactivator.
Expand All @@ -187,7 +187,7 @@ MpMethodProxy class >> trap [
The core idea is that
- the original method is installed in the same method dictionary using a unique symbol
- this call is patched to use that symbol for the send"
result := self trap.
result := self trapMethod.

"Move to the meta level and call the after hooks.
Two after hooks are required.
Expand Down Expand Up @@ -1154,7 +1154,7 @@ MpMethodProxy >> install [

| deactivator newTrap index trapSelector |
thisProcess runInMetaLevel: [
(proxyMethod hasPragmaNamed: #noInstrumentation) ifTrue: [
(proxifiedMethod hasPragmaNamed: #noInstrumentation) ifTrue: [
^ MpCannotInstall signalWith: self ].

deactivator := [ "Execution handler for the slow path. An exception or a non local return happened during proxy execution"
Expand All @@ -1174,10 +1174,10 @@ MpMethodProxy >> install [
wasMeta ifTrue: [ thisProcess shiftLevelDown ].
].

newTrap := self trapMethodPrototype copy.
newTrap := self prototypeTrapMethod copy.
trapSelector := newTrap selector.
newTrap selector: proxyMethod selector.
newTrap methodClass: proxyMethod methodClass.
newTrap selector: proxifiedMethod selector.
newTrap methodClass: proxifiedMethod methodClass.

hiddenSelector := MpHiddenSelector new.

Expand All @@ -1193,14 +1193,14 @@ MpMethodProxy >> install [
"It could happen that a proxy wraps a proxy.
Remember the object that was installed at this moment.
This is the object to restore during uninstall"
wrappedMethod := proxyMethod methodClass methodDict
at: proxyMethod selector.
wrappedMethod := proxifiedMethod methodClass methodDict
at: proxifiedMethod selector.

proxyMethod methodClass methodDict
proxifiedMethod methodClass methodDict
at: hiddenSelector
put: proxyMethod.
proxyMethod methodClass methodDict
at: proxyMethod selector
put: proxifiedMethod.
proxifiedMethod methodClass methodDict
at: proxifiedMethod selector
put: newTrap.

trapMethod := newTrap ]
Expand All @@ -1211,55 +1211,55 @@ MpMethodProxy >> isInstalled [

trapMethod ifNil: [ ^ false ].

^ proxyMethod methodClass >> proxyMethod selector == trapMethod
^ proxifiedMethod methodClass >> proxifiedMethod selector == trapMethod
]

{ #category : #accessing }
MpMethodProxy >> methodClass [

^ proxyMethod methodClass
^ proxifiedMethod methodClass
]

{ #category : #installation }
MpMethodProxy >> prototypeTrapMethod [

^ self class class methods detect: [ :m |
m numArgs = proxifiedMethod numArgs and: [
m selector beginsWith: 'trap' ] ]
]

{ #category : #accessing }
MpMethodProxy >> proxifiedMethod [

^ proxifiedMethod
]

{ #category : #accessing }
MpMethodProxy >> proxyMethod: anObject [

proxyMethod := anObject
proxifiedMethod := anObject
]

{ #category : #accessing }
MpMethodProxy >> selector [

^ proxyMethod selector
^ proxifiedMethod selector
]

{ #category : #accessing }
MpMethodProxy >> trap [
MpMethodProxy >> trapMethod [

^ trapMethod
]

{ #category : #installation }
MpMethodProxy >> trapMethodPrototype [

^ self class class methods detect: [ :m |
m numArgs = proxyMethod numArgs and: [
m selector beginsWith: 'trap' ] ]
]

{ #category : #installation }
MpMethodProxy >> uninstall [

self isInstalled ifFalse: [ ^ self ].

thisProcess runInMetaLevel: [
proxyMethod methodClass methodDict
at: proxyMethod selector
proxifiedMethod methodClass methodDict
at: proxifiedMethod selector
put: wrappedMethod.
proxyMethod methodClass methodDict removeKey: hiddenSelector ]
]

{ #category : #accessing }
MpMethodProxy >> wrappedMethod [

^ proxyMethod
proxifiedMethod methodClass methodDict removeKey: hiddenSelector ]
]
2 changes: 1 addition & 1 deletion src/MethodProxiesExamples/MpProfilingHandler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ MpProfilingHandler >> instrumentImplementorsOf: potentialSelector [
]

{ #category : #accessing }
MpProfilingHandler >> wrappedMethod [
MpProfilingHandler >> proxifiedMethod [
^ wrappedMethod
]

Expand Down

0 comments on commit 4fff7b9

Please sign in to comment.