Making allocations through a dynamic variable #16749
Draft
+117
−31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduced a DynamicVariable to make the allocations instead of directly calling
basicNew
. The reason behind this is that now Pharo has 3 allocator methods (new
,newPinnned
, andnewTenured
). Like described in issue #16731 there are around 154 re-definitions of the methodnew
. This causes problems since if the user calls another allocator method for those classes that have re-definednew
, the object will be not be initialized properly. Fixes #16731.This PR changes the way allocations are made by using a DynamicVariable. Now, no matter will allocator method is called, the objects will be always be properly initialized even when re-defining the
new
method.Let's take
OrderedCollection
as an example. Currently in Pharo, if one does:OrderedCollection newPinned add: 1
this will raised an exception since theOrderedCollection
object was not initialized because of the re-definition ofnew
.With this PR: doing
OrderedCollection newPinned add: 1
or evenOrderedCollection newTenured add: 1
works as excepted.About performance
I ran some performance benches and this PR increases the allocation time.
So, this means that making the allocation through the DynamicVariable reduces performance:
Object new
OrderedCollection new
Array new: 10