Skip to content

Commit 64d1d1a

Browse files
radekdoulikjonpryor
authored andcommitted
[jnimarshalmethod-gen] Use ReaderParameters.InMemory=true (dotnet#369)
Set `ReaderParameters.InMemory=true` so that assemblies are loaded into memory for processing, instead of reading their contents lazily from disk. This helps to process the assembly faster Times when processing `Mono.Android.dll`: Before: All 37.34 real 37.29 user 2.04 sys Limited 7.02 real 6.54 user 1.17 sys After: All 33.84 real 34.99 user 1.01 sys Limited 4.41 real 4.76 user 0.36 sys Where *All* has `jnimarshalmethod-gen.exe` processing *all* types in the assembly, while *Limited* means to use `jnimarshalmethod-gen.exe --types=FILE` where `FILE` contains the following listed types: # XA template startup, Mono.Android # Android.Runtime.UncaughtExceptionHandler Java.Interop.TypeManager\+JavaTypeManager Android.Views.View\+IOnClickListenerImplementor # XForms template, Mono.Android # Android.Animation.ValueAnimator\+IAnimatorUpdateListenerImplementor Java.Lang.Thread\+RunnableImplementor
1 parent cc14ed1 commit 64d1d1a

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

tools/jnimarshalmethod-gen/App.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class App : MarshalByRefObject
1919
{
2020

2121
internal const string Name = "jnimarshalmethod-gen";
22-
static DirectoryAssemblyResolver resolver = new DirectoryAssemblyResolver (logger: (l, v) => { Console.WriteLine (v); }, loadDebugSymbols: true, loadReaderParameters: new ReaderParameters () { ReadSymbols = true });
22+
static DirectoryAssemblyResolver resolver = new DirectoryAssemblyResolver (logger: (l, v) => { Console.WriteLine (v); }, loadDebugSymbols: true, loadReaderParameters: new ReaderParameters () { ReadSymbols = true, InMemory = true });
2323
static Dictionary<string, TypeBuilder> definedTypes = new Dictionary<string, TypeBuilder> ();
2424
static Dictionary<string, TypeDefinition> typeMap = new Dictionary<string, TypeDefinition> ();
2525
static public bool Debug;
@@ -145,11 +145,13 @@ void ProcessAssemblies (List<string> assemblies)
145145

146146
var readWriteParameters = new ReaderParameters {
147147
AssemblyResolver = resolver,
148+
InMemory = true,
148149
ReadSymbols = true,
149150
ReadWrite = true,
150151
};
151152
var readWriteParametersNoSymbols = new ReaderParameters {
152153
AssemblyResolver = resolver,
154+
InMemory = true,
153155
ReadSymbols = false,
154156
ReadWrite = true,
155157
};
@@ -347,7 +349,7 @@ void CreateMarshalMethodAssembly (string path)
347349
ColorWriteLine ($"Marshal method assembly '{assemblyName}' created", ConsoleColor.Cyan);
348350

349351
var dstAssembly = resolver.GetAssembly (destPath);
350-
var mover = new TypeMover (dstAssembly, ad, definedTypes, resolver);
352+
var mover = new TypeMover (dstAssembly, ad, path, definedTypes, resolver);
351353
mover.Move ();
352354

353355
if (!keepTemporary)

tools/jnimarshalmethod-gen/TypeMover.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ public class TypeMover
1313
{
1414
AssemblyDefinition Source { get; }
1515
AssemblyDefinition Destination { get; }
16+
string DestinationPath { get; }
1617
Dictionary<string, System.Reflection.Emit.TypeBuilder> Types { get; }
1718

1819
MethodReference consoleWriteLine;
1920

20-
public TypeMover (AssemblyDefinition source, AssemblyDefinition destination, Dictionary<string, System.Reflection.Emit.TypeBuilder> types, DirectoryAssemblyResolver resolver)
21+
public TypeMover (AssemblyDefinition source, AssemblyDefinition destination, string destinationPath, Dictionary<string, System.Reflection.Emit.TypeBuilder> types, DirectoryAssemblyResolver resolver)
2122
{
2223
Source = source;
2324
Destination = destination;
25+
DestinationPath = destinationPath;
2426
Types = types;
2527

2628
if (App.Debug) {
@@ -49,7 +51,7 @@ public void Move ()
4951
return;
5052
}
5153

52-
Destination.Write (new WriterParameters () { WriteSymbols = Destination.MainModule.HasSymbols });
54+
Destination.Write (DestinationPath, new WriterParameters () { WriteSymbols = Destination.MainModule.HasSymbols });
5355

5456
if (App.Verbose)
5557
App.ColorWriteLine ($"Wrote updated {Destination.MainModule.FileName} assembly", ConsoleColor.Cyan);

0 commit comments

Comments
 (0)