[Mono-devel-list] Re: Assembly Unloading
Jim Purbrick
jimpurbrick at yahoo.co.uk
Wed May 25 12:47:45 EDT 2005
> Now that Sebastien has helped make the security
> situation clearer, I think unloading assemblies is
> (hopefully) the last big issue I need to resolve.
I now have a bytecode translator implemented which can
save and restore running code to serializable heap
objects and can check method calls against a white
list of allowed methods, so now I'm looking at how to
unload assemblies and JIT output when a script stops
or is serialized to a new server.
Zoltan convinced me that messing with the runtime to
try to unload assemblies was a bad idea and looking at
the DynamicMethod mechanisms provided by LCG it seems
that only static methods can be dynamically created
and collected.
So, now I'm looking at Richards suggestion of just
serializing all the scripts to disk, destroying the
current domain, creating a new one and loading the
scripts in to the new domain.
What i'm currently trying is:
1) mono_jit_init("root domain");
2) domain = mono_domain_create();
3) Load assembly in to domain.
4) Run script.
5) Serialize running script to file.
6) mono_domain_free(domain, true);
7) domain = mono_domain_create();
8) Deserialize script from file.
Looping this process I can run, save, load and run.
However, when I come to save the script for the second
time the application crashes with the call stack
below. If I remove the domain creation and destruction
steps the application will continue to loop, saving
and loading itself to and from file.
Another concern is that when I list the assemblies
using AppDomain.CurrentDomain.GetAssemblies() The
current domain is always the root and always contains
my script assembly, even though I only load the script
assembly in to the secondary domain.
Does anyone know what I'm doing wrong here? Do
assemblies get loaded when I deserialize a script from
disk? If so how do I control which domain they get
loaded in to? Are there any examples for this stuff?
Should I be doing this from managed code? (I'd rather
not)
Cheers,
Jim.
Heres the call stack I get when I try to save for a
second time. I'm using Mono 1.1.7 on Debian and
Windows and get the same crash on both.
System.NullReferenceException: Object reference not
set to an instance of an object
in <0x00030> System.Type:Equals (System.Object o)
in <0x0001e> System.Collections.Hashtable:KeyEquals
(System.Object item, System.Object key)
in <0x00144> System.Collections.Hashtable:get_Item
(System.Object key)
in <0x00535>
System.Runtime.Serialization.Formatters.Binary.ObjectWriter:GetObjectData
(System.Object obj,
System.Runtime.Serialization.Formatters.Binary.TypeMetadata
metadata, System.Object data)
in <0x0003f>
System.Runtime.Serialization.Formatters.Binary.ObjectWriter:WriteObject
(System.IO.BinaryWriter writer, Int64 id,
System.Object obj)
in <0x0014d>
System.Runtime.Serialization.Formatters.Binary.ObjectWriter:WriteObjectInstance
(System.IO.BinaryWriter writer, System.Object obj,
Boolean isValueObject)
in <0x00039>
System.Runtime.Serialization.Formatters.Binary.ObjectWriter:WriteQueuedObjects
(System.IO.BinaryWriter writer)
in <0x00049>
System.Runtime.Serialization.Formatters.Binary.ObjectWriter:WriteObjectGraph
(System.IO.BinaryWriter writer, System.Object obj,
System.Runtime.Remoting.Messaging.Header[] headers)
in <0x002ce>
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter:Serialize
(System.IO.Stream serializationStream, System.Object
graph, System.Runtime.Remoting.Messaging.Header[]
headers)
in <0x00015>
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter:Serialize
(System.IO.Stream serializationStream, System.Object
graph)
in <0x000b5> UThread.UThread:Save (System.String filename)
___________________________________________________________
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com
More information about the Mono-devel-list
mailing list