[image] Create MonoImageStorage to own the image raw data (#13892)
commita56573fb7c61adc4a0629a540d0ba093c1f951d8
authorAleksey Kliger (λgeek) <akliger@gmail.com>
Sun, 7 Apr 2019 09:23:29 +0000 (7 05:23 -0400)
committerZoltan Varga <vargaz@gmail.com>
Sun, 7 Apr 2019 09:23:29 +0000 (7 05:23 -0400)
tree71a03c72fb6aaa58c605b783651cca7667b9afc1
parent9a63a2d41f79472d28bf7b9786e4d57f2750e470
[image] Create MonoImageStorage to own the image raw data (#13892)

Create a new data structure: MonoImageStorage.

It is an object that will have the responsibility for the raw data of a
MonoImage.  It has a string key and a refcount that is used to share a
MonoImageStorage between multiple MonoImage objects.

The reason we need this is because the current MonoAssembly/MonoImage design is
broken for multiple domains and (more evidently) it will be broken when we add
AssemblyLoadContext support.  The issue is that a MonoImage may be shared
between multiple domains (or ALCs), but it has a 'references' field which
points to a single other MonoAssembly.

This is a problem because the references of an image may be resolved
differently in different domains (or ALCs).

The eventual solution will be to stop sharing MonoImages based on path name (or
in the case of in-memory images based on a name made up from the address of the
byte blob).

However we still don't want to open the same data more than once (if we're on a
config where we don't have mmap, we malloc some memory and dump the data in
there - we don't want to do that multiple times for the same file).

So the solution is to create this MonoImageStorage object and make it possible
to share it based on path name, but don't give it any responsibilities except
for owning the memory.  It doesn't know anything about metadata or assemblies
or any of that stuff - it just owns a chunk of memory and knows when and how to
free it.

This commit just adds the MonoImageStorage object and wires it up in MonoImage
loading.  There should be no observable behavioral changes from this commit.
12 files changed:
mono/metadata/assembly.c
mono/metadata/coree.c
mono/metadata/debug-mono-ppdb.c
mono/metadata/icall-windows.c
mono/metadata/image.c
mono/metadata/loader.c
mono/metadata/metadata-internals.h
mono/metadata/metadata-verify.c
mono/metadata/reflection.c
mono/metadata/w32process.c
mono/mini/debugger-agent.c
tools/pedump/pedump.c