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

Fix array constructor for Object Lists #17503

Merged
merged 1 commit into from Jun 1, 2023

Conversation

amicic
Copy link
Contributor

@amicic amicic commented Jun 1, 2023

new[]() not supported on older compilers. Instead, just calling
new() in a loop for every element of the array.

@amicic amicic added the comp:gc label Jun 1, 2023
`new[]()` not supported on older compilers. Instead, just calling
`new()` in a loop for every element of the array.

Signed-off-by: Aleksandar Micic <Aleksandar_Micic@ca.ibm.com>
@dmitripivkine
Copy link
Contributor

Jenkins compile pLinux jdk8

@dmitripivkine
Copy link
Contributor

real testing has been done in the internal build http://vmfarm.rtp.raleigh.ibm.com/build_info.php?build_id=52180

@dmitripivkine dmitripivkine merged commit 91c8570 into eclipse-openj9:master Jun 1, 2023
4 checks passed
for (uintptr_t index = 0; index < arrayElements; index++) {
new(&continuationObjectLists[index]) MM_ContinuationObjectList();
Copy link
Contributor

Choose a reason for hiding this comment

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

Paretheses should not be used after the class name (and there should be a space after new):

			new (&continuationObjectLists[index]) MM_ContinuationObjectList;

Same comment applies to other files included in this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I personally like space between new and open bracket, but no-space is already very much adopted in J9 GC code (there are dozens of examples without space and barely any with).

As far as I know, the oval brackets are needed at the end - it's an indication that (in this case default) constructor should be invoked.

Copy link
Contributor

Choose a reason for hiding this comment

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

They are not needed; their presence represents a possible ambiguity.
Here we want the compiler to invoke the (user-defined) default constructor.
Using parentheses is a request for zero-initialization instead.
There's a discussion of this at https://stackoverflow.com/questions/620137/do-the-parentheses-after-the-type-name-make-a-difference-with-new.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the reference to the discussion. But from what I can see, our case resembles to 'C' class (non-POD, with user defined ctor), and in both older/newer versions of compilers, calling it with '()', will call default ctor, what we want. I don't understand from where you get that it will do zero-init?

BTW, we have this pattern at a couple of 100 of spots, already. If we are indeed calling it wrong we are really lucky (that default ctor is just pretty much zero-init).

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps an analogy will help. You wouldn't write

    MM_ContinuationObjectList local();

to declare an initialize a local variable (the snippet declares a function which returns MM_ContinuationObjectList). Instead you would say

    MM_ContinuationObjectList local;

Along the same lines, I'm suggesting we should write new (where) T instead of new (where) T(). I believe there's potential to create ambiguity when a suitable call operator (operator()()) is available (although I haven't yet had luck constructing a concrete example).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I somewhat buy that analogy and from that perspective, it would more consistent to do new (where) T instead of new (where) T(). But I don't see the reason to use the former to reduce/remove ambiguity. We probably always have default ctor (so it will be called over zero-init), and even if we don't I don't see a problem (it will call zero-init, what was likely the intention).

In presence of overloaded operator()(), yes, there could be ambiguity problems, but I don't want to go there. We have never overloaded it, and pretty sure never will. It's just such an extreme operator to overload.

So, do we want to go and change 10s of spots just for this analogy argument? I'd be ok if we are writing the code from scratch, but now, it's a tougher call. I'll think about it more...

Copy link
Contributor

Choose a reason for hiding this comment

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

It may not be worth fixing the existing instances of this, but I think it's something to keep in mind going forward: let's not make it worse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants