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

Incremental boehm support #958

Merged
merged 19 commits into from
Jun 14, 2018
Merged

Incremental boehm support #958

merged 19 commits into from
Jun 14, 2018

Conversation

jechter
Copy link

@jechter jechter commented May 25, 2018

This PR:

-Updates Boehm GC subrepo to latest unity-master
-Implements write barriers needed for Boehm incremental GC in MANUAL_VDB mode
-Allows enabling incremental Boehm via environment variables

The write barriers should have no effect if incremental boehm is not enabled, so there should not be any risk from this. However, I see a risk in updating Boehm to the latest upstream (and not to an official release version). Not sure what kind of testing we should do to reduce such risk?

@jechter jechter requested a review from joncham May 25, 2018 08:53
@jechter
Copy link
Author

jechter commented Jun 8, 2018

Some relevant diffs in bdwgc repo:

Current bdwgc 7.4 vs unity changes:
Unity-Technologies/bdwgc@release-7_4...Unity-Technologies:unity-release-7_4

bdwgc master vs unity changes (what I want to update to):
Unity-Technologies/bdwgc@Unity-Technologies:master...unity-fixes-for-master

@jechter
Copy link
Author

jechter commented Jun 8, 2018

Unity branch with a mono builds.7z built from this branch: https://katana.bf.unity3d.com/projects/Unity/builders?unity_branch=platform/foundation/mono-boehm-testing

@jechter
Copy link
Author

jechter commented Jun 8, 2018

Corresponding PR for il2cpp: https://gitlab.internal.unity3d.com/vm/il2cpp/merge_requests/525

Since we want to keep bdwgc in sync between mono and il2cpp, we should probably consider the criteria for landing the two PRs together.

@@ -1227,8 +1227,12 @@ mono_domain_free (MonoDomain *domain, gboolean force)

domain->setup = NULL;

#if !HAVE_BDWGC_GC
Copy link
Member

Choose a reason for hiding this comment

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

I am asking upstream Mono about this issue.

/* This is not needed by sgen, as it does not seem
+ to need write barriers for uncollectable objects (like the vtables storing static
+ fields), but it is needed for incremental boehm. */
mono_gc_wbarrier_generic_nostore(t);
Copy link
Member

Choose a reason for hiding this comment

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

Let me look into this. Perhaps we should always be scanning the uncollectable regions of memory in Boehm but we are not.

Copy link
Author

Choose a reason for hiding this comment

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

I guess we could, if we wanted to match sgen's apparent behavior here. But I don't see a reason to do that. It seems more efficient to rescan the uncollectable objects only when they have changed, like everything else.

Copy link
Member

Choose a reason for hiding this comment

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

My main worry is making sure we don't miss any new places these are needed or any we didn't hit yet.

Copy link
Author

Choose a reason for hiding this comment

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

So, I discovered most of these in Unity and mono through my test coverage. I have a mode where I run patch the GC functions to perform tracking of memory and then verify all references match set write barriers at the end of the run. I then made sure that RuntimeTests would pass without any unaccounted references using this setup. I am currently going through the same process for il2cpp.

The patching of GC functions is done at runtime by injecting a jmp instruction at the beginning of the functions. That way I can add the patching code to our development builds, and enable it through some environment variable. That should make it relatively easy to add configs to katana to run these tests, as is should be possible to do this by just adding a new katana config for each test suite we want to run with write barrier verification, without requiring custom builds of Unity and mono to enable that. (At least that's the idea, some open questions remain)

@@ -634,6 +647,7 @@ mono_gc_weak_link_add (void **link_addr, MonoObject *obj, gboolean track)
{
/* libgc requires that we use HIDE_POINTER... */
*link_addr = (void*)HIDE_POINTER (obj);
GC_dirty(link_addr);
Copy link
Member

Choose a reason for hiding this comment

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

Nit, mono style is space between method name and parenthesis.

Copy link
Member

@joncham joncham 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 to me. Seems like all viable tests are passing.

@jechter jechter merged commit 7950418 into unity-master Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants