From 4fff7b9a71cdc4fcb71a456373a6b4748c6a5d62 Mon Sep 17 00:00:00 2001 From: Guille Polito Date: Thu, 7 Sep 2023 17:08:12 +0200 Subject: [PATCH] Renames, cleanups and comments --- .../MpMethodProxyTest.class.st | 18 ++--- src/MethodProxies/MpMethodProxy.class.st | 76 +++++++++---------- .../MpProfilingHandler.class.st | 2 +- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/MethodProxies-Tests/MpMethodProxyTest.class.st b/src/MethodProxies-Tests/MpMethodProxyTest.class.st index 56e7fa1..2c14d80 100644 --- a/src/MethodProxies-Tests/MpMethodProxyTest.class.st +++ b/src/MethodProxies-Tests/MpMethodProxyTest.class.st @@ -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 ] ] @@ -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 ] @@ -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 @@ -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 } @@ -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' } @@ -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 ] ] diff --git a/src/MethodProxies/MpMethodProxy.class.st b/src/MethodProxies/MpMethodProxy.class.st index 699393c..8b9d872 100644 --- a/src/MethodProxies/MpMethodProxy.class.st +++ b/src/MethodProxies/MpMethodProxy.class.st @@ -55,11 +55,11 @@ Class { #name : #MpMethodProxy, #superclass : #Object, #instVars : [ - 'proxyMethod', 'handler', 'hiddenSelector', 'trapMethod', - 'wrappedMethod' + 'wrappedMethod', + 'proxifiedMethod' ], #category : #MethodProxies } @@ -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 | @@ -162,7 +162,7 @@ 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" @@ -170,7 +170,7 @@ MpMethodProxy class >> trap [ | 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. @@ -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. @@ -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" @@ -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. @@ -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 ] @@ -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 ] ] diff --git a/src/MethodProxiesExamples/MpProfilingHandler.class.st b/src/MethodProxiesExamples/MpProfilingHandler.class.st index cea4355..d554e1b 100644 --- a/src/MethodProxiesExamples/MpProfilingHandler.class.st +++ b/src/MethodProxiesExamples/MpProfilingHandler.class.st @@ -75,7 +75,7 @@ MpProfilingHandler >> instrumentImplementorsOf: potentialSelector [ ] { #category : #accessing } -MpProfilingHandler >> wrappedMethod [ +MpProfilingHandler >> proxifiedMethod [ ^ wrappedMethod ]