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

Implement truncated return bytecodes #1831

Merged
merged 1 commit into from
Oct 17, 2018

Conversation

dnakamura
Copy link
Contributor

Add code which emmits the new bytecodes for truncated return types.
See #999

Signed-off-by: Devin Nakamura [email protected]

@fjeremic
Copy link
Contributor

I had a comment on the PR which enabled JIT support before I knew this PR existed here (#1943 (comment)). @dnakamura would it be possible to add some unit tests which generate these new bytecodes to this PR?

returnType = BCV_BASE_TYPE_INT_BIT;
break;
default:
//TODO mark unreachable
Copy link
Member

Choose a reason for hiding this comment

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

Can you add an Assert unreachable here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we have a common solution for that? I tried doing a quick search of the code and It looks like its usually a module or function specific tracepoint. Wasn't sure if there was a more generic solution, hence the TODO

Copy link
Member

Choose a reason for hiding this comment

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

usually a module or function specific tracepoint

That's the generic solution :) Most (many?) tdf files have the basic asserts in them at this point. Copying over an existing one if it isn't present already should be fairly straightforward

break;
default:
if (romMethod->modifiers & J9AccSynchronized) {
return JBsyncReturn0 + (U_8) *returnSlots;
Copy link
Member

Choose a reason for hiding this comment

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

This change introduces multiple return points - can we keep it to a single return?

//TODO mark unreachable
break;
}
inconsistentStack |= ( returnType == baseTypeCharConversion[returnChar - 'A']);
Copy link
Member

Choose a reason for hiding this comment

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

Does this match the RIs behaviour? Some of the primitives can be automatically converted to others as long as the conversion doesn't lose info. ie: byte -> int. Will this fail verification in those cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this actually matter, since these return bytecodes are only generated internally?

Copy link
Member

Choose a reason for hiding this comment

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

I think you're right here - the check that the return type is compatible is already handled above this code so all this is doing is validating we put the right bytecode in for the signature.

break;

case JBreturn1:
case JBsyncReturn1:
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment here that the synchronized {b,c,s,z} will always be handled by JBgenericReturn? It will make it more obvious to anyone debugging through the verifier that this is correct without requiring them to check how the bytecodes are written

@DanHeidinga
Copy link
Member

Can you also look into why the copyright check is failing?

@dnakamura dnakamura changed the title WIP: Implement truncated return bytecodes Implement truncated return bytecodes May 31, 2018
@DanHeidinga
Copy link
Member

Thanks for fixing the copyright check. There's one remaining review comment and some unit tests required. When do you think this could be completed?

@dnakamura
Copy link
Contributor Author

Hope to get it done by the end of the week, I have a standalone test case that needs to be polished a bit and integrated with the test framework

@dnakamura
Copy link
Contributor Author

Currently hitting an issue with shared classes. I believe the issue is that there is an old shared class cache which has the old bytecodes.

@DanHeidinga
Copy link
Member

@pshipton @hangshao0 What's the process for incrementing the SCC version number when the ROMClass format changes?

@pshipton
Copy link
Member

In OSCache.hpp, you'll find the following define:

#define OSCACHE_CURRENT_CACHE_GEN

To add a new generation, increment the OSCACHE_CURRENT_CACHE_GEN by 2. There are 3 case statements which need to be updated with the old generation numbers, search for "case OSCACHE_CURRENT_CACHE_GEN".

The cache generation number is appended to the cache file name. The effect of changing the generation number is that the JVM will create a new cache file, rather than trying to open the old one. We'll have to document / release note this, as it leaves a extra file in the file system, until the cache is destroyed (which destroys older generations as well).

@dnakamura
Copy link
Contributor Author

@pshipton Is there any reason the switch statement are not re-structured as ifs ? Would make life easier since they wont need to be changed every time the version is bumped

@hangshao0
Copy link
Contributor

Re-structure to if...else should be fine.

@dnakamura
Copy link
Contributor Author

@DanHeidinga this should be good to go

@pshipton
Copy link
Member

@dnakamura there are some conflicts to be resolved.
What happened about changing the shared cache version?

} else if (isConstructor) {
newBytecode = JBreturnFromConstructor;
/* are we dealing with a case where we should use a truncated return bytecode? */
if(truncatedReturnBytecode != 0){
Copy link
Member

Choose a reason for hiding this comment

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

There is a missing space after the if

Copy link
Member

Choose a reason for hiding this comment

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

and also before the curly bracket.

} else if (isConstructor) {
newBytecode = JBreturnFromConstructor;
/* are we dealing with a case where we should use a truncated return bytecode? */
if (truncatedReturnBytecode != 0){
Copy link
Member

Choose a reason for hiding this comment

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

Missing space before the curly bracket here too.


/* check methods that return char, byte, short, or bool use the right opcode */
if (BCV_BASE_TYPE_INT == type){
switch(bc){
Copy link
Member

Choose a reason for hiding this comment

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

nitpicks on the spacing here as well. Between the ){ here and line above.

@DanHeidinga DanHeidinga added this to the Release 0.11.0 milestone Oct 11, 2018
@dnakamura
Copy link
Contributor Author

@pshipton looking at the conflicts and comments now. There turned out to be a bug in my earlier code which caused issues with the shared classes cache. However this shouldn't break compatibility, since all returns are converted to the generic return opcode before being put in the cache

@DanHeidinga
Copy link
Member

since all returns are converted to the generic return opcode before being put in the cache

@dnakamura that's backwards actually. We run fixreturns to ensure that genericReturn is never present in the sharedclasses cache (apart from contstructors). Otherwise, the returns are subject to patching - see:

https://github.com/eclipse/openj9/blob/f031ac4012794306c16a6ba8fcc9907ca6fbcf90/runtime/vm/BytecodeInterpreter.hpp#L7662-L7672

@DanHeidinga
Copy link
Member

No, this isn't ready to go yet. Some of the review comments haven't been addressed and I believe this will leave JBgenericReturn bytecodes in romclasses from the sharedcache which we'll try to fix at runtime.

The bytecode patching in JBgenericReturn in the interpreter will need to be modified if we're genericreturns in SCC romclasses

@pshipton
Copy link
Member

Then it seems it should be removed from the 0.11.0 plan and deferred to 0.12.0

@dnakamura dnakamura force-pushed the ret_op3 branch 2 times, most recently from a13e67b to eec7ffb Compare October 15, 2018 19:40
@dnakamura
Copy link
Contributor Author

dnakamura commented Oct 15, 2018

IT looks like I forgot to push the changes to the branch (or maybe pushed them to the wrong branch). Latest changes with fixes for comments should be there

@dnakamura that's backwards actually. We run fixreturns to ensure that genericReturn is never present in the sharedclasses cache (apart from contstructors). Otherwise, the returns are subject to patching - see:

Oh yeah, thats right. I knew there was some issue involving patching generic returns and the shared classes cache. The problem is addressed in these changes
https://github.com/eclipse/openj9/pull/1831/files#diff-5ca144eb3d6b1334698c9840002b59c3R7671

@pshipton
Copy link
Member

@DanHeidinga ^

Copy link
Member

@DanHeidinga DanHeidinga left a comment

Choose a reason for hiding this comment

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

@smlambert @sophia-guo Can one of you give the tests a look? It looks OK to me

__LINE__);
break;
}
inconsistentStack |= !( returnType == baseTypeCharConversion[returnChar - 'A']);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this just inconsistentStack |= (returnType != baseTypeCharConversion[returnChar - 'A']); or is there some other reason to negate the whole expression?

@DanHeidinga
Copy link
Member

Jenkins test sanity plinux,win,zlinux jdk8

@@ -30,6 +30,7 @@
<test name="generalTest">
<classes>
<class name="org.openj9.test.gpu.SortTest" />
<class name="org.openj9.test.truncatedReturn.TestTruncatedReturn" />
Copy link
Contributor

Choose a reason for hiding this comment

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

We are planning to rename the generalTest to GPUSortTest to be more straightforward. Each testname could indicate kind of its feature just like all other tests. So probably adding a new test naming truncateReturn would be better.

@@ -27,7 +27,7 @@
<test>
<testCaseName>generalSanityTest</testCaseName>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) \
-cp $(Q)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)GeneralTest.jar$(Q) \
-cp $(Q)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(LIB_DIR)$(D)asm-all.jar$(P)$(TEST_RESROOT)$(D)GeneralTest.jar$(Q) \
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as comment for testng.xml. Adding a separate testcase would be better.

@DanHeidinga
Copy link
Member

@sophia-guo Are you ok with the updated tests?

Add code which emmits the new bytecodes for truncated return types.
See eclipse-openj9#999

Signed-off-by: Devin Nakamura <[email protected]>
Copy link
Contributor

@sophia-guo sophia-guo left a comment

Choose a reason for hiding this comment

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

LGTM

@DanHeidinga
Copy link
Member

Jenkins test sanity plinux,xlinux,win jdk8

@DanHeidinga
Copy link
Member

Jenkins test extended xlinux jdk8

@DanHeidinga DanHeidinga self-assigned this Oct 16, 2018
@DanHeidinga DanHeidinga merged commit 8c6d5e2 into eclipse-openj9:master Oct 17, 2018
@dnakamura dnakamura deleted the ret_op3 branch November 13, 2018 19:08
DanHeidinga added a commit to DanHeidinga/openj9 that referenced this pull request Apr 9, 2019
When new bytecodes were added in eclipse-openj9#1831 for the truncated returns,
the SCC generation number wasn't incremented which can lead to
crashes.

Currently the VM will attempt to destroy and recreate the SCC
if the SHA in the header is different but if can't, it will
continue to use the cache.

The only sure way (today) to prevent this issue is to increment
the cache generation.

Do this now to prevent VerifyErrors due to unknown bytecodes
while we work out the right behaviour.

issue: eclipse-openj9#5380

Signed-off-by: Dan Heidinga <[email protected]>
DanHeidinga added a commit to DanHeidinga/openj9 that referenced this pull request Apr 15, 2019
When new bytecodes were added in eclipse-openj9#1831 for the truncated returns,
the SCC generation number wasn't incremented which can lead to
crashes.

Currently the VM will attempt to destroy and recreate the SCC
if the SHA in the header is different but if can't, it will
continue to use the cache.

The only sure way (today) to prevent this issue is to increment
the cache generation.

Do this now to prevent VerifyErrors due to unknown bytecodes
while we work out the right behaviour.

issue: eclipse-openj9#5380

Signed-off-by: Dan Heidinga <[email protected]>
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.

6 participants