Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

[armel tizen] Implemented WriteBarriers.S stubs #4235

Merged
merged 12 commits into from
Aug 1, 2017

Conversation

sergign60
Copy link
Contributor

@sergign60 sergign60 commented Jul 27, 2017

Correctness was checked by comparing with execution of the portable variant on the test Simple/Hello

@sergign60
Copy link
Contributor Author

@Dmitri-Botcharnikov @BredPet @jkotas
please review

// r1 = value
LEAF_ENTRY RhpCheckedXchg, _TEXT
ALTERNATE_ENTRY RhpCheckedXchgAVLocation
ldr r2, [r0]
Copy link
Member

Choose a reason for hiding this comment

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

// r1 = value
// r2 = comparand
LEAF_ENTRY RhpCheckedLockCmpXchg, _TEXT
PROLOG_PUSH "{r4,lr}"
Copy link
Member

Choose a reason for hiding this comment

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

This does not need scratch registers - it should be like the Windows version: https://github.com/dotnet/corert/blob/master/src/Native/Runtime/arm/WriteBarriers.asm#L343

@jkotas
Copy link
Member

jkotas commented Jul 27, 2017

Could you please cross check your implementation with the Windows ARM implementation? The write barrier implementation should be pretty similar.

@sergign60
Copy link
Contributor Author

sergign60 commented Jul 28, 2017

@jkotas please review again. Thanks for your notes.

@@ -1,68 +1,378 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: extra space

// track this write. The location address is translated into an offset in the card table bitmap. We set
// an entire byte in the card table since it's quicker than messing around with bitmasks and we only write
// the byte if it hasn't already been done since writes are expensive and impact scaling.
lsr r2, #LOG2_CLUMP_SIZE
Copy link
Member

Choose a reason for hiding this comment

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

This shift should be done as part of address mode - look for add r12, r12, $DESTREG, lsr #10 in the Windows version

// track this write. The location address is translated into an offset in the card table bitmap. We set
// an entire byte in the card table since it's quicker than messing around with bitmasks and we only write
// the byte if it hasn't already been done since writes are expensive and impact scaling.
lsr r0, #LOG2_CLUMP_SIZE
Copy link
Member

Choose a reason for hiding this comment

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

This shift should be done as part of address mode - look for add r12, r12, $DESTREG, lsr #10 in the Windows version


// Export the canonical write barrier under unqualified name as well
.ifc \REFREG, r1
ALTERNATE_ENTRY RhpAssignRef
ALTERNATE_ENTRY RhpAssignRefAVLocation
Copy link
Member

Choose a reason for hiding this comment

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

The AV location needs to point to instruction that will AV, not dmb - to match https://github.com/dotnet/corert/blob/master/src/Native/Runtime/arm/WriteBarriers.asm#L307

// location is in one of the other general registers determined by the value of REFREG.

// WARNING: Code in EHHelpers.cpp makes assumptions about write barrier code, in particular:
// - Function "InWriteBarrierHelper" assumes an AV due to passed in null pointer will happen on the first instruction
Copy link
Member

Choose a reason for hiding this comment

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

Once the other issue is fixed, this comment should be updated accordingly - to match https://github.com/dotnet/corert/blob/master/src/Native/Runtime/arm/WriteBarriers.asm#L276

ldr r12, =C_FUNC(g_ephemeral_low)
ldr r12, [r12]
cmp \REFREG, r12
blo LOCAL_LABEL(\BASENAME\()_NoBarrierRequired_\REFREG)
Copy link
Member

Choose a reason for hiding this comment

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

The target of this conditional branch is unconditional branch. It can be short-circuited to branch directly to LOCAL_LABEL(\BASENAME\()_EXIT_\REFREG)


// Now check that the real heap location still contains the value we just wrote into the shadow heap. This
// read must be strongly ordered wrt to the previous write to prevent race conditions. We also need to
// recover the old value of DESTREG for the comparison so use an xchg instruction (which has an implicit lock
Copy link
Member

Choose a reason for hiding this comment

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

xchg is x64-specific instruction. It does not seem to be used here. Should this rather match https://github.com/dotnet/corert/blob/master/src/Native/Runtime/arm/WriteBarriers.asm#L82 ?

@sergign60
Copy link
Contributor Author

@jkotas please review once more

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thanks

@jkotas jkotas merged commit d84cae0 into dotnet:master Aug 1, 2017
@sergign60 sergign60 deleted the arm_build branch August 3, 2017 10:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants