-
Notifications
You must be signed in to change notification settings - Fork 732
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
Refactor SuperclassTest generators on Z #20906
base: master
Are you sure you want to change the base?
Refactor SuperclassTest generators on Z #20906
Conversation
37c9204
to
f845b5b
Compare
Commons out code in genTestIsSuper and genInstanceOfOrCheckCastSuperClassTest into 3 helpers (genTestRuntimeFlags, genLoadAndCompareClassDepth, genCheckSuperclassArray) Replaces calls to the old generators with calls to the 3 new methods Signed-off-by: Matthew Hall <[email protected]>
f845b5b
to
b5b2cd2
Compare
@r30shah please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Matthew, I was under impression that genInstanceOfOrCheckcastSuperClassTest
can be refactored/updated to something like genSuperClassTest
which handles the cases for all three - instanceOf/ CHeckCast / isAssignableFrom to ensure that if there are any changes that happens in the future to class structure, we can make sure that only one place is changed and we do not need to go through all three places where super class test is generated to mae sure.
Please share the reason behind this (As you are using assignableFrom, may be some code that makes it difficult to use the single SuperClassTest function). so would like to know.
That being said, if we are going down the path of having SuperClassTest changed into three function, we should write a good comment explaining what it is doing, and also have properName to the helper function (May be testClassFlagsForSuperClassTest, testClassDepthForSuperClassTest).
/** | ||
* generates code to branch to <callHelperLabel> if any of the J9ROMClass modifier flags match the given flags <flags> | ||
*/ | ||
static void genTestRuntimeFlags(TR::CodeGenerator *cg, TR::Node *node, TR::Register *classReg, int32_t toClassDepth, TR::LabelSymbol *callHelperLabel, TR_S390ScratchRegisterManager *srm, int32_t flags, const char *callerName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I wonder how are you using this function. The runtime check for interface or abstract class is used when the other tests in the checkcast / instance of fails and it is a safeguard to do so before loading the class from super class array. I would think of this test is always coming with super class test. That being said, can you share the logic behind this ?
Also genTestRuntimeFlags
is not very suitable name for what it is doing (Rather misleading actually) as it is doing test to ensure that it is not interface / array before doing super class test.
* Loads the class depth of the toClass (if needed) as well as the depth of the fromClass. | ||
* Genereates code to compare the 2 depths and branch to the failLabel if fromClassDepth <= toClassDepth | ||
*/ | ||
static TR::Register *genLoadAndCompareClassDepth(TR::CodeGenerator *cg, TR::Node *node, TR::Register *toClassReg, int32_t toClassDepth, TR::Register *fromClassReg, TR::LabelSymbol *failLabel, TR_S390ScratchRegisterManager *srm, const char *callerName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above. Everything that it is doing is specific to Super Class test where some of the core-login behind class depth and array/interface should be the same. So would appreciate if you can share the reason behing this.
@r30shah This change does handle all 3 cases. Did I miss a spot where Regarding #20906 (comment), For example, if we still want the CHelper call for Array Classes for isAssignableFrom, but want to inline the test for interfaces, we can do something like
But if we want to keep CheckCast the way it is right now, we just use
Additionally, the runtime check for an Interface or Array Class is not just a safeguard. Only To sum it up the overall idea was to allow for greater expandability. For #20906 (comment), similar to above, the idea behind separating it was so it could be used if we decide to inline all or part of the superclass test for Array Classes. This would allow us to do a similar class-depth-check shortcut. |
Thanks a lot @matthewhall2 for the explanation. Do we have a potential test that we would be doing when doing the if it is interface or not. Existing code for
That is incorrect. Code that prepares the list of test to be generated at compile time for instance Of and checkCast [1] does that. It would be very inefficient if we do not check the information which is available at compile time and go all out with test to be performed at runtime. If we know that the cast class is not regular class at compile time, why do we even do super class test ? Only case where we would actually check class is interface or array class at runtime is when we have a dynamic cast class (Which will be result of when cast class is not compile time constant - which I think you can generate this test with [1].
|
Thank you for the clarification @r30shah . For abstract class, I want to add the skip over the class equality test and add the existing I was also planning on looking into the same tests we already have but for Array Classes. For example, the inline superclass test it not generated for any of instanceof, checkcast, isassignableFrom for Array Classes. |
Are these tests you are talking about, you are planning to add for Class.isAssignableFrom ? or checkCast / instanceOf (The iTable walk routine was already something I think we should implement and thing about reducing the inline code we are generated) But that IMO is beyond the scope of improving the Class.isAssignableFrom from the current implementation. If this approach is allowing you to make progress, I am OK with you separating the Super Class test generation to different helper function if that makes sense to you with the current implementation state. But I would factor in the places where we may need to change - Currently, it is only the genSuperClassTest that is needed to be changed and also you more relatable names for the function. |
Commons out code in
genTestIsSuper
andgenInstanceOfOrCheckCastSuperClassTest
into 3 helpers (genTestRuntimeFlags
,genLoadAndCompareClassDepth
,genCheckSuperclassArray
)Replaces calls to the old generators with calls to the 3 new
java8 zos, zLinux
Jenkins personal