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

Enable detection for overlapping reference and non-reference fields #1142

Open
wants to merge 764 commits into
base: unity-main
Choose a base branch
from

Conversation

joncham
Copy link
Member

@joncham joncham commented Feb 15, 2019

No description provided.

realek and others added 30 commits November 7, 2018 10:30
…ash table.

changed code so we avoid an extra lookup
Add bee script to pull down required mono-build-deps from stevedore
…ono-build-deps

Update external build-deps tools paths (MBE)
…urn-struct

Use mono_mb_emit_op for CEE_LDOBJ to ensure wrapper data is added for indirect load of a ref return value. (case 1096820)
…ture_static_field_byte_reporting_bugfix

Scripting memory capture - static field byte reporting fix
…tstack-2

update bdwgc to handle suspend on altstack
…s-extra

Move the location of mono-build-tools-extra
*reverted filtering uninitialized classes out to avoid crashes
…ture_metadata_crawling_fix

[Memory Snapshot] Metadata crawling, use only initialized types
Changing unity's vprintf adapters to use the va_list param instead of always passing NULL.
… to be properly setup before calling our_vprintf. Also fixed some code formatting.
…ty-vprintf-redirect

Add ability to redirect mono stdout logging to unity's vprintf function.
…ty-vprintf-redirect

Fix build for missing implicit define
UnityAlex and others added 27 commits July 24, 2019 16:20
)

* improve mempool chunk reporting in order to get exact range for each chunk

* added mono_unity_class_for_each in order to allow for simple iteration logic over all initialized classes in the VM

* added mono_type_get_name_chunked in order to report type names in null terminated chunks.
A good example for this can be using a preallocated instance of core::string as user_data for the callback which will then append onto the preallocated string

* added mono_unity_image_set_mempool_chunk_foreach in order to report memory blocks from the VM heap
added mono_unity_domain_mempool_chunk_foreach in order to report memory blocks inside the current domain's memory pool
added mono_unity_root_domain_mempool_chunk_foreach in order to report memory blocks inside the root domain's memory pool
added mono_unity_assembly_mempool_chunk_foreach in order to report memory blocks inside an assembly's image's memory pool
added mono_unity_class_get_data_size in order to return static field data size for a MonoClass
added mono_unity_class_get_static_field_data in order to access static fields memory for a given MonoClass
added mono_unity_class_field_is_literal in order to find out if the attributes
added mono_unity_start/stop_gc_world() in order to control the GC world state
added mono_unity_gc_heap_foreach in order to report each allocated GC heap section
added mono_unity_gchandles_foreach_get_target in order to report all gc handle targets tracked by the garbage collector
added mono_unity_object_header_size in order to report mono object header size
added mono_unity_array_object_header_size in order to report mono array object header size
added mono_unity_offset_of_array_length/bounds_in_array_object_header in order to report the offset of the length/bounds of the array within the header
added mono_unity_allocation_granularity in order to report the minimum allocation granulariy inside the vm
added mono_unity_get_name_full_chunked in order to extract a types name in chunks
added mono_unity_type_is_static in order to report if the given type is static
added mono_unity_type_is_pointer_type in order to report if the given type is a pointer type

* added missing include

* fixed up missing user_data assignment during context initialization for mono_unity_class_for_each

* move type name streaming utility out of class.h/.c
Previously, 5174f7e was an attempt to
correct this issue. However, the `#define` scheme for Mono changed since
then, so `PLATFORM_MACOSX` became `HOST_DARWIN`.

This change uses the proper define to correct Unity case 1166108.
…le-proper-define

Handle the empty file inode on macOS and FAT32 (with the proper define)
…raint aren't blittlable. (mono#15761)

* [metadata] Fields whose types are gparams with a reference type constraint
aren't blittlable.
Don't try to layout the field to find out if it's blittable.
For gshared gparams, follow the blittability of the constraint.

Fixes certain recursive examples.

```
using System;

namespace TestRecursiveType
{
    class Program
    {
        static void Main(string[] args)
        {
            SubClass subC = new SubClass();
            Console.WriteLine(subC.GetTest());
        }
    }

    public struct ValueTest<U>
    {
        // When U is instantiated with T, from BaseClass, we know it'll be a
	// reference field, so we know the instantiation ValueTest<T> won't
	// be blittable.
        public readonly U value;
    }

    public abstract class BaseClass<T> where T : BaseClass<T>
    {
        public ValueTest<T> valueTest = default(ValueTest<T>);
    }

    public class SubClass : BaseClass<SubClass>
    {
        private String test = "test";

        public string GetTest()
        {
            return test;
        }
    }
}
```

Fixes mono#15760

---

The failure is happening when we are doing mono_class_setup_fields ("BaseClass<T>") which needs to decide for each field whether it is blittable or not. So therefore we are trying to decide if ValueTest<T> (that is: the ValueTest<U> field inside BaseClass<T>) is blittable or not.

So we instantiate U with T.
Now to decide whether VaueTest<T> is blittable or not, we look at every field.
So then we look at T value.
To decide if T is blittable we first check if it's a reference type.

That check is currently inadequate for generic parameters - what the PR adds is the ability to see if theres a T : class constraint or a T : C constraint - where C is some class. As soon as we know that T's constraint will force it to be a reference type we can definitely say that T won't be blittable without having to initialize C, at all.

Previously, Mono would see that T is some kind of type for which it couldn't definitively decide that it's a reference type and it would call: mono_class_setup_fields (field_class) which would then try to setup the fields of the parent class BaseClass<T>. And that would hit the recursion check.

Unity cherry-pick note: Needed to bring MONO_CLASS_IS_INTERFACE_INTERNAL
and mono_class_get_valuetype_class forward
…numbers

Swap bytes for tcp port number (case 1165578)
create_event_list() in the debugger agent was sending in a pointer for a
source file but then never using or freeing it.  If we just send in a
NULL, the memory won't be allocated.
…-leak

Mono debugger agent memory leak fix, case 1170031
Download dependencies based on platform
TimeZoneNotFoundException. Added a catch to allow mono to try the WinRT
fallback which appears to work even when there is an invalid timezone
value in the registry.
…timezone-exception

Fixing a corner case where an invalid timezone on windows would throw a
…xception

[metadata] Fields whose types are gparams with a reference type const…
To make it work JNI_OnLoad method should be called from runtime
While JNI_OnLoad is not called, standard Posix variant is being used, so it should work exactly like before.
[Android] Getting current locale using JNI
- Fix mono_debugger_disconnect method so it disconnects the debugger
client instead of trying to stop the debugger thread.
- Move method declaration to top of the file
…r-agent-mono-debugger-disconnect-fix

[debugger-agent] Fix mono_debugger_disconnect implementation
On WebGL, this large method hits a nested loop processing limit in the
browsers. Break it up into 15 arbitrary, smaller methods to avoid this
issue.
Split up the large method that initializes error messages
If the first and second transition DateTime objects are the same,
`ValidateAdjustmentRule` will throw an exception. I'm unsure why these
would be the same, but we do see that occur for some locales. In that
case, just exit early.

This change corrects Unity case 1160695.
…art-end

Handle locales with the same daylight savings time start and end
@joncham joncham force-pushed the unity-master-detect-overlapping-ref-fields branch from 1995e5b to 933d765 Compare September 10, 2019 14:41
@unity-cla-assistant
Copy link
Collaborator

unity-cla-assistant commented May 19, 2022

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
4 out of 10 committers have signed the CLA.

✅ joshpeterson
✅ ashwinimurt
✅ UnityAlex
✅ realek
❌ Joshua Peterson
❌ TautvydasZilys
❌ BorisShir
❌ eneko-unity
❌ lambdageek
❌ vargaz


Joshua Peterson seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.