[image] Create MonoImageStorage to own the image raw data (#13942)
commit43540e6649806a84257f1a385dbfe5482eb8ae7f
authorAleksey Kliger (λgeek) <akliger@gmail.com>
Mon, 22 Apr 2019 18:43:11 +0000 (22 14:43 -0400)
committerGitHub <noreply@github.com>
Mon, 22 Apr 2019 18:43:11 +0000 (22 14:43 -0400)
tree3b3f5157801889eb79c615d9877844b232976f97
parent800701fe3f370a3f1ab79723192fb3262d1b8375
[image] Create MonoImageStorage to own the image raw data (#13942)

* [image] Create MonoImageStorage to own the image raw data

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.

* [win32] call FreeLibrary from MonoImageStorage dtor, not mono_image_close_except_pools

If we're sharing a MonoImageStorage, only call FreeLibrary when the storage is
finally destroyed, not every time one of the images is closed.
mono/metadata/assembly.c
mono/metadata/coree.c
mono/metadata/icall-windows.c
mono/metadata/image.c
mono/metadata/loader.c
mono/metadata/metadata-internals.h
mono/metadata/w32process.c