Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Fixed block copy for structs containing gcrefs - #14559

Closed
rartemev wants to merge 2 commits into
dotnet:masterfrom
rartemev:issue_14383_1
Closed

rartemev wants to merge 2 commits into
dotnet:masterfrom
rartemev:issue_14383_1

Conversation

@rartemev

@rartemev rartemev commented Oct 18, 2017 •

Copy link
Copy Markdown

Issue #14383.
Fixed code generation for GT_STORE_OBJ node containing gcref. In case we have struct with both gcref non-gcref we may receive GC signal during copy code when temporary register holds non-ref value, but marked as gcref. So such situation obviously leds to gc hole.


We have a struct S

struct S
{
    public String str;  // reference
    public Pad pad;     // very big struct containing lot of doubles
    public String str2; // reference
}

And the which copies it
Before:

G_M833_IG03:

IN0009: 000038      nop     
IN000a: 00003A      add     r0, sp, 264	// [V06 loc0]
IN000b: 00003C      add     r1, sp, 528	// [V01 arg0]
IN000c: 00003E      ldr     r2, [r1!+4]
IN000d: 000042      str     r2, [r0!+4]
IN000e: 000046      ldr     r2, [r1!+4]
IN000f: 00004A      str     r2, [r0!+4]
IN0010: 00004E      ldr     r2, [r1!+4]
IN0011: 000052      str     r2, [r0!+4]

After:

G_M833_IG03:
000038  BF00           nop     
00003A  A842           add     r0, sp, 264	// [V06 loc0]
00003C  A984           add     r1, sp, 528	// [V01 arg0]
00003E  F242 6C11      movw    r12, 0x2611
000042  F6C6 1C65      movt    r12, 0x6965
000046  47E0           blx     r12		// CORINFO_HELP_ASSIGN_BYREF
000048  F242 6C11      movw    r12, 0x2611
00004C  F6C6 1C65      movt    r12, 0x6965
000050  47E0           blx     r12		// CORINFO_HELP_ASSIGN_BYREF
000052  F851 2B04      ldr     r2, [r1!+4]
000056  F840 2B04      str     r2, [r0!+4]
00005A  F851 2B04      ldr     r2, [r1!+4]

So you can see that 2 CORINFO_HELP_ASSIGN_BYREF was added which correspond to 2 references in the original struct.

@BruceForstall

Copy link
Copy Markdown

Can you give an example of before and after codegen, showing the fix?

@rartemev

Copy link
Copy Markdown
Author

@BruceForstall added

@BruceForstall

Copy link
Copy Markdown

@rartemev In the "after" code it looks like it thinks the very first two pointer slots of the struct are GC pointers, and the padding is after that. Is that correct? Shouldn't the padding be between the two pointer copies (via helper)?

@BruceForstall

Copy link
Copy Markdown

Also, you've eliminated the fast-pass (optimization) to avoid calling the write barrier for stack destinations. It seems like that's the wrong fix.

It seems like perhaps the real problem was that the "str" instruction (in the stack destination case, at least), when writing a EA_GCREF/EA_BYREF type, was not creating a GC info record. Thus, the stack slot we just wrote was becoming live (holding a GC ref), but the GC info didn't say that.

The interesting thing to show is not the raw generated code, but the generated code in the "Instructions as they come out of the scheduler " phase that shows GC info changes (or, raw instructions plus appropriate GC info).

@rartemev

rartemev commented Oct 18, 2017 •

Copy link
Copy Markdown
Author

@BruceForstall yes, it is.

houldn't the padding be between the two pointer copies (via helper)?

As far as I know we shouldn't rely on how the struct is defined in the source code. The actual layout is up to execution runtime and I think since we have 4 byte pointers and 8-byte aligned padding it is good idea to put both pointers together because we have an empty 4-byte hole between first pointer and first double.

@rartemev

Copy link
Copy Markdown
Author

No, the actual problem was that when we receive GC signal, the %r2 register marked as GCREF but contains the part of double which is not gcref for sure.

@BruceForstall

Copy link
Copy Markdown

As far as I know we shouldn't rely on how the struct is defined in the source code.

Sure; if the VM arranged them that way, then it is correct.

No, the actual problem was that when we receive GC signal, the %r2 register marked as GCREF but contains the part of double which is not gcref for sure.

So the GC info is wrong, not the codegen.

@rartemev

Copy link
Copy Markdown
Author

If I am correct the situation is like when within a single node GT_STORE_OBJ there are more then one state for the same register %r2. I am not sure what exactly wrong, but I think it much much more difficult to support splitting of GC info to handle such cases.

@BruceForstall

Copy link
Copy Markdown

GC info is on a per-instruction basis, based on the EA_GCREF/EA_BYREF type given when the instruction is generated. GC info is not on a per-IR-node basis.

@BruceForstall

Copy link
Copy Markdown

@rartemev What test are you looking at?

@rartemev

Copy link
Copy Markdown
Author

Updated here #14601

@rartemev rartemev closed this Oct 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants