Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@xmcclure
Copy link
Contributor

This patch adds a small number of mempool-reference audit points to functions in class.c and then performs a large refactor without which those audit points would fail on the standard tests. The goal of the refactor is to remove ambiguities in what image owns or should own any particular generic parameter object. Previously, there were four options for specifying a MonoGenericParam’s image:
1. klass/method union in MonoGenericContainer.
2. image field in MonoGenericContainer.
3. image field in MonoGenericParam.
4. No field; “image” passed in to methods in at time of usage.
This patch removes 3 and 4; it preserves the image field from (2), but merges it into the union from (1). It adds a new field, “is_anonymous”, to indicate when the image member of the union should be used. The single source of the “owner" union now always points to the generic param’s image, directly or indirectly.

A further change is made to support this: Previously, containers were optional, and the presence or absence of container was incidentally used to determine whether an object was a MonoGenericParam or a MonoGenericParamFull. Now, containers are mandatory for all MonoGenericParams, so a new “is_small_size” bit in the container tracks this information.

Some changes were made to checked builds to support all this: there's a g_assert_checked now which asserts but only on checked builds, and a bunch of little changes to the mempool audit feature (see commit #1)

This change opens some sources of risk:
⁃ Code which creates MonoGenericParams now must make sure to allocate a container early.
⁃ Code that accesses the MonoGenericContainer::owner field must all be correctly updated to look for is_anonymous or there will be a crash. (Much of this code would have previously used a NULL container as the flag for “anonymous”).
⁃ Code that casts MonoGenericParams to MonoGenericParamFull must use the is_small_size field.
⁃ Some generic containers will now exist with NULL type_params and 0 type_argc. Code which reads the type param array must either not receive objects from these containers, or must handle it.
⁃ If code by users of the embedding API exists which somehow depends on particular behavior related to the now-unused image argument of mono_class_from_generic_parameter, it will break.
I have audited code around, at least, the first three of these cases and fixed what problems I found.

Monodis is probably completely broken now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was removed under Zoltan's supervision but I'm actually sort of confused-- why did this need to be removed? Is this okay to remove? With all the other changes the assert now fails if it is left in.

@kumpera
Copy link
Contributor

kumpera commented Nov 23, 2015

Avoid merge commits in PR as much as possible, most git tools suck at presenting those merges in any usable way, making offline reviews a lot harder as it's no longer the case that the PR is made out of the top X commits.

Copy link
Contributor

Choose a reason for hiding this comment

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

Images don't need to be disk-loaded, there are other ways to load them besides disk files that will in turn produce non-dynamic images. mkbundle'd assemblies and Assembly.Load (byte[]) are two examples of that.

@kumpera
Copy link
Contributor

kumpera commented Nov 23, 2015

The first commit, 2bcb4f001309feed42447f04b340df8018f15999, needs some minor edits, but LGTM otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

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

"except during container creation" Why? For how long? How will code witness this transitory state?

Please expand this comment on what's the issue around container creation.
Doing it while the knowledge is fresh will save us from a lot of trouble down the line.

Copy link
Contributor

Choose a reason for hiding this comment

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

Use g_error with a message.

- New audit-point macro for atomic writes
- Check imageset list directly (instead of indirectly through image
  list)
- Check dynamic images and have special rules for them (for the time
  being we will allow dynamic images to point to non-dynamic ones
  without auditing, long-term this is a FIXME)
- Print image names out with more detail (image sets get full names)
- Remove some #if CHECKED_BUILDs
- New g_assert_checked asserts for checked builds only
This patch fixes rule violations found by the first batch of
mempool-reference audit points. The fix is to remove ambiguities in
what image owns or should own any particular generic parameter object.
Previously, there were four options for specifying a
MonoGenericParam’s image:

 1. klass/method union in MonoGenericContainer.
 2. image field in MonoGenericContainer.
 3. image field in MonoGenericParam.
 4. No field; “image” passed in to methods in at time of usage.

This patch removes 3 and 4; it preserves the image field from (2), but
merges it into the union from (1). It adds a new field,
“is_anonymous”, to indicate when the image member of the union should
be used. The single source of the “owner" union now always points to
the generic param’s image, directly or indirectly.

A further change is made to support this: Previously, containers were
optional, and the presence or absence of container was incidentally
used to determine whether an object was a MonoGenericParam or a
MonoGenericParamFull. Now, containers are mandatory for all
MonoGenericParams, so a new “is_small_size” bit in the container
tracks this information.

This change opens some sources of risk:

 ⁃ Code which creates MonoGenericParams now must make sure to
allocate a container early.
 ⁃ Code that accesses the MonoGenericContainer::owner field
must all be correctly updated to look for is_anonymous or there will
be a crash. (Much of this code would have previously used a NULL
container as the flag for “anonymous”).
 ⁃ Code that casts MonoGenericParams to MonoGenericParamFull
must use the is_small_size field.
 ⁃ Some generic containers will now exist with NULL type_params
and 0 type_argc. Code which reads the type param array must either not
receive objects from these containers, or must handle it.
 ⁃ If code by users of the embedding API exists which somehow
depends on particular behavior related to the now-unused image
argument of mono_class_from_generic_parameter, it will break.

I have audited code around, at least, the first three of these cases
and fixed what problems I found.
Comments, variable initialization, formatting. No functional changes.
@xmcclure
Copy link
Contributor Author

Rebased, made changes for all comments above (unless I specifically commented to say otherwise), split out the changes into four clearly delineated commits instead of two.

@xmcclure
Copy link
Contributor Author

Converted those macros to static inlines as Zoltan suggested

@xmcclure
Copy link
Contributor Author

xmcclure commented Dec 2, 2015

builddeb

@lewurm
Copy link
Contributor

lewurm commented Dec 3, 2015

@lewurm
Copy link
Contributor

lewurm commented Dec 3, 2015

kumpera added a commit that referenced this pull request Dec 7, 2015
Unambiguous ownership of generic param objects
@kumpera kumpera merged commit 761a84f into mono:master Dec 7, 2015
kumpera added a commit that referenced this pull request Dec 7, 2015
This reverts commit 761a84f, reversing
changes made to d565a22.

Corlib compilation was broken with the PR in so I'm reverting it until it can be worked out.
@kumpera
Copy link
Contributor

kumpera commented Dec 7, 2015

Uggg, I had to manually revert this PR as it broke corlib compilation is some weird way I could not easily debug. Sorry. :(

vargaz added a commit that referenced this pull request Dec 7, 2015
    Unambiguous ownership of generic param objects
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.

3 participants