Skip to content

Conversation

@BruceForstall
Copy link
Contributor

superpmi.py collect has a new --crossgen2 option that specifies
to run crossgen2 on all the assemblies specified with the
-assemblies option.

For example:

py c:\rt\src\coreclr\scripts\superpmi.py collect --crossgen2 -output_mch_path c:\win-x64-cg2.mch -assemblies c:\rt\artifacts\tests\coreclr\windows.x64.Checked\Tests\Core_Root\System.Private.CoreLib.dll

There are currently quite a few failures during the replay
"cleaning" phase with a System.Private.CoreLib collection:
5654 compilation failures out of 14705 functions, including 100
JIT asserts.

In contrast, the crossgen(1) collection has 3 failures out
of 20165 functions.

So, there is some work to be done to make SuperPMI collection
of crossgen2 compilations work well.

The change in spmirecordhelper.h is to work around what appears to
be a crossgen2 bug: when the JIT calls getCallInfo, sometimes crossgen2
sets sig.sigInst.methInstCount in the result CORINFO_CALL_INFO to non-zero,
but it sets sig.sigInst.methInst to nullptr, which should be illegal:
the count indicates how many elements are in the array, so you can?t have a
null array with a non-zero count. Maybe the JIT doesn?t look at these fields in this
scenario for some reason, but SPMI tries to serialize/de-serialize the array,
and was crashing.

Fixes #45909

`superpmi.py collect` has a new `--crossgen2` option that specifies
to run crossgen2 on all the assemblies specified with the
`-assemblies` option.

For example:
```
py c:\rt\src\coreclr\scripts\superpmi.py collect --crossgen2 -output_mch_path c:\win-x64-cg2.mch -assemblies c:\rt\artifacts\tests\coreclr\windows.x64.Checked\Tests\Core_Root\System.Private.CoreLib.dll
```

There are currently quite a few failures during the replay
"cleaning" phase with a System.Private.CoreLib collection:
5654 compilation failures out of 14705 functions, including 100
JIT asserts.

In contrast, the crossgen(1) collection has 3 failures out
of 20165 functions.

So, there is some work to be done to make SuperPMI collection
of crossgen2 compilations work well.

The change in spmirecordhelper.h is to work around what appears to
be a crossgen2 bug: when the JIT calls `getCallInfo`, sometimes crossgen2
sets sig.sigInst.methInstCount in the result CORINFO_CALL_INFO to non-zero,
but it sets sig.sigInst.methInst to `nullptr`, which should be illegal:
the count indicates how many elements are in the array, so you can?t have a
null array with a non-zero count. Maybe the JIT doesn?t look at these fields in this
scenario for some reason, but SPMI tries to serialize/de-serialize the array,
and was crashing.

Fixes dotnet#45909
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jan 27, 2021
@BruceForstall
Copy link
Contributor Author

cc @dotnet/jit-contrib @dotnet/crossgen-contrib

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for setting this up.

Copy link
Member

@trylek trylek left a comment

Choose a reason for hiding this comment

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

Looks good, thanks Bruce! I'll discuss the NotImplemented exceptions at our today Crossgen2 weekly sync-up meeting, these definitely need fixing.

@MichalStrehovsky
Copy link
Member

he change in spmirecordhelper.h is to work around what appears to
be a crossgen2 bug: when the JIT calls getCallInfo, sometimes crossgen2
sets sig.sigInst.methInstCount in the result CORINFO_CALL_INFO to non-zero,
but it sets sig.sigInst.methInst to nullptr, which should be illegal:

FWIW, this is a "feature":

sig->sigInst.methInst = null; // Not used by the JIT
sig->sigInst.methInstCount = (uint)signature.GenericParameterCount;

Populating this array is not cheap since we don't have unmanaged pointers to hand out as handles (like CoreCLR does). We need to actually make a handle and a pinned array and it's useless work if JIT is not going to look at them. If JIT starts to use them, we'll need to fix that, but for now we just don't do the work.

Copy link
Contributor

@sandreenko sandreenko left a comment

Choose a reason for hiding this comment

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

LGTM

rsp_file_handle, rsp_filepath = tempfile.mkstemp(suffix=".rsp", prefix=root_output_filename, dir=self.temp_location)
with open(rsp_file_handle, "w") as rsp_write_handle:
rsp_write_handle.write(assembly + "\n")
rsp_write_handle.write("-o:" + crossgen2_output_assembly_filename + "\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to include all these assemblies for each test/library? Is R2R test doing the same?

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 added the same set of references that the one example test wrapper script I looked at was adding. I'm not really sure what the best minimal set is, or whether it needs to change per-scenario.

@sandreenko
Copy link
Contributor

There are currently quite a few failures during the replay
"cleaning" phase with a System.Private.CoreLib collection:
5654 compilation failures out of 14705 functions, including 100
JIT asserts.

they could be not spmi specific, #47308

@BruceForstall BruceForstall merged commit e8ffbad into dotnet:master Jan 27, 2021
@BruceForstall BruceForstall deleted the SpmiCrossgen2 branch January 27, 2021 19:37
@ghost ghost locked as resolved and limited conversation to collaborators Feb 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

superpmi: simplify collection of crossgen2 of assets

6 participants