Skip to content

Fix calculation error in deepInstanceSize of BlockBuilderStatus#11710

Merged
sopel39 merged 1 commit intotrinodb:masterfrom
JackieTien97:SizeCalculationError
Apr 5, 2022
Merged

Fix calculation error in deepInstanceSize of BlockBuilderStatus#11710
sopel39 merged 1 commit intotrinodb:masterfrom
JackieTien97:SizeCalculationError

Conversation

@JackieTien97
Copy link
Contributor

Currently, in the deepInstanceSize function of BlockBuilderStatus class, we recursively calculate the size of one BlockBuilderStatus instance. However, we should exclude the static field which is not the size for one instance, it's the size for the whole class and is shared by each intance.

Besides, we should also exclude the synthetic field in this class, especially if you use something like jacoco in maven which is used to calculate code coverage. jacoco in maven will add some synthetic fields in class, and if we use the current deepInstanceSize function of BlockBuilderStatus class, we will get some errors like the following picture:

image

I was confused about this error at first, I didn't explicitly declare boolean[] in this class. Then I print all the fields for the class, I got the following:

image

The last one field: boolean[] $jacocoData is not declared in my class which is a synthetic field and generated by jacoco in maven, so when I iterate the fields in this class using Class<?>.getDeclaredFields() method, we will get this unexpected one. When we keep recursively calling deepInstanceSize function for this boolean[] $jacocoData field, we will get the IllegalArgumentException in the first picture.

@cla-bot cla-bot bot added the cla-signed label Mar 30, 2022
@findepi findepi requested a review from sopel39 March 30, 2022 10:37
Copy link
Member

@sopel39 sopel39 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that this deepInstanceSize is only used in BlockBuilderStatus, which seems overly complicated for

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that this deepInstanceSize is only used in BlockBuilderStatus, which seems overly complicated to just compute instance size. Could we BlockBuilderStatus.INSTANCE_SIZE as we do in every other place, e.g:

ClassLayout.parseClass(BlockBuilderStatus.class).instanceSize() + PageBuilderStatus.INSTANCE_SIZE

@JackieTien97 JackieTien97 requested a review from sopel39 April 1, 2022 01:18
Copy link
Member

@sopel39 sopel39 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please squash commits

@JackieTien97 JackieTien97 force-pushed the SizeCalculationError branch from 7bd0b69 to 037bde0 Compare April 1, 2022 08:25
@JackieTien97
Copy link
Contributor Author

please squash commits

I've already squashed the commits, PTAL :)

@sopel39 sopel39 merged commit 199c017 into trinodb:master Apr 5, 2022
@sopel39
Copy link
Member

sopel39 commented Apr 5, 2022

merged, thanks!

@github-actions github-actions bot added this to the 376 milestone Apr 5, 2022
@JackieTien97 JackieTien97 deleted the SizeCalculationError branch April 6, 2022 06:59
v-jizhang added a commit to v-jizhang/presto that referenced this pull request Apr 11, 2022
Cherry-pick of trinodb/trino#11710
Currently, in the deepInstanceSize function of BlockBuilderStatus
class, we recursively calculate the size of one BlockBuilderStatus
instance. However, we should exclude the static field which is not
the size for one instance, it's the size for the whole class and is
shared by each intance.

Co-authored-by: JackieTien97 <jackietien97@gmail.com>
highker pushed a commit to prestodb/presto that referenced this pull request Apr 20, 2022
Cherry-pick of trinodb/trino#11710
Currently, in the deepInstanceSize function of BlockBuilderStatus
class, we recursively calculate the size of one BlockBuilderStatus
instance. However, we should exclude the static field which is not
the size for one instance, it's the size for the whole class and is
shared by each intance.

Co-authored-by: JackieTien97 <jackietien97@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants