# Wednesday, 30 June 2010
IKVM.Reflection Testing

I decided to do some brute force testing of IKVM.Reflection. I ran my LinkerPrototype on almost all assemblies in the .NET and Mono GACs. This resulted in a number of fixes to the linker (but note that it's still just a toy) and a bunch of fixes to IKVM.Reflection. Most of these fixes aren't relevant for IKVM.NET, but I want IKVM.Reflection to be useful as a general System.Reflection replacement.

Fixes:

  • MethodInfo.DeclaringType should return null for global generic method instances.
  • Fixed support for TypeSpec in custom modifiers.
  • Fixed bug that caused duplicate MethodSpec rows to be emitted.
  • Fixed bug that caused duplicate MemberRef rows to be emitted.
  • Allow use of generic method definition in IL stream.
  • Made signature binding lazy for GenericMethodInstance.
  • Allow declarative security attributes to use non-public constructors.
  • Implemented ManifestResourceInfo.FileName property.
  • Implemented workaround for incorrect exception table length in methods generated by VB compiler.
  • Fixed exception filter block handling to support having both regular handlers and a filter for the same try block.
  • Fixed metadata header to account for the actual ImageRuntimeVersion string length, instead of assuming it to be "v2.0.50727".
  • Implemented __GetDeclaredMethods() for ArrayType and MultiArrayType.
  • Fixed two MarshalSpec blob parsing bugs.
  • Fixed several places where generic type definitions would be encoded as TypeDef token instead of TypeSpec.
  • Re-instroduced generic type instantation for "identity" instantations of TypeBuilder types.
  • Several fixes for C++/CLI that tends to stick custom modifiers everywhere. Also, support void& in local variable signature.
  • Support fields that have an RVA, but where it is set to zero (C++/CLI does this).
  • Added support for a TypeRef with a null ResolutionScope.

The source is available in cvs and the LinkerPrototype zip link above contains the most recent IKVM.Reflection.dll, but if you want just the IKVM.Reflection.dll binary, it is available here: ikvm-reflect-0.43.3833.zip

Wednesday, 30 June 2010 10:47:31 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
Apache PDFBox 1.2.0 Released

Yesterday the release of Apache PDFBox 1.2.0 was announced. Thanks to Daniel Wilson the included Ant build script to build the .NET version has been updated to work with IKVM.NET 0.42.

Wednesday, 30 June 2010 08:50:07 (W. Europe Daylight Time, UTC+02:00)  #    Comments [2]
# Monday, 21 June 2010
New Development Snapshot

One more development snapshot. A couple of minor tweaks.

Changes:

  • Updated copyright notices.
  • Removed Winforms thread workaround timer that was previously required to make the thread abortable.
  • IKVM.Reflection: Fixed a couple of bugs related to escaped type names not being unescaped.
  • IKVM.Reflection: Changed assembly reference caching to be more efficient and to handle the fact that assembly identities can change (if it is an AssemblyBuilder).
  • IKVM.Reflection: Changed assembly identity caching to only add identities to the cache when they are used to look up the assembly.

Binaries available here: ikvmbin-0.43.3824.zip

Monday, 21 June 2010 10:36:02 (W. Europe Daylight Time, UTC+02:00)  #    Comments [2]
# Monday, 14 June 2010
CLR JIT Bugs Found During IKVM.NET Development

"It is actually fairly common that people notice that things fail under retail but not debug and tend to blame code generation.
While a code generation bug is possible, as a matter of statistics, it is not likely."
-- Vance Morrison

Date CLR Arch Type Description
2010-06-12 v4 x64 Incorrect code Optimizer incorrectly propagates invariants.
2010-06-04 v2, v4 x86 Crash Access violation while compiling code.
2010-04-11 v4 x64 Vulnerability Type safety vulnerability caused by incorrect optimization.
2009-10-28 v4 beta 2 x64 Vulnerability Type safety vulnerability in exception handler code.
2007-07-02 v2 x64 Exception System.InvalidProgramException on verifiable IL.
2007-05-11 v2 x64 Incorrect code 0.0 and -0.0 are considered the same by the optimizer.
2006-12-06 v2 x86 Vulnerability Ability to access array outside of bounds.
Monday, 14 June 2010 10:30:23 (W. Europe Daylight Time, UTC+02:00)  #    Comments [2]
New Development Snapshot

I finished all the .NET 4.0 security model changes. If you build from source, you can now (optionally) build on .NET 4.0 and get native .NET 4.0 assemblies that use the new .NET 4.0 security model (and also experimental class gc support). The .NET 2.0 binaries also work on .NET 4.0.

This is probably the final development snapshot before the first 0.44 release candidate and it has been tested more than a typical development snapshot. Please start testing it and, as always, feedback is appreciated.

Changes:

  • Final set of .NET 4.0 security model changes.
  • Added "first-pass" build of IKVM.AWT.WinForms.dll and moved "native" AWT code from IKVM.Runtime.dll to IKVM.AWT.WinForms.dll.
  • Fixed verifier bug that caused verification errors if "new" string was interned before verifying any code. Thanks to Andrey Malakov for tracking this down.
  • Include more parts of tools.jar in IKVM.OpenJDK.Tools.dll.
  • Add feature to expand environment variables in system properties specified with -D ikvmc option.
  • Added jdk-tools target to openjdk.build to build javac.exe, javah.exe and javap.exe (not included in the default build).
  • Added build script to build ikvmdoc.exe (not included in the default build).
  • Fixed JNIEnv.DescribeException() (NPE instead of printing the exception).
  • IKVM.Reflection: When the user string heap overflows, throw an exception instead of silently creating corrupt image.
  • IKVM.Reflection: Fixed .PDB emitter to work with .NET 4.0. Thanks to Jb Evain for the heads up on this.

Binaries available here: ikvmbin-0.43.3817.zip

Monday, 14 June 2010 07:53:11 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Tuesday, 08 June 2010
New Development Snapshot

I finally did the work necessary to improve the codegen for finally handlers. More improvements are still possible, but at least most finally handlers will now execute without touching the exception object (and hence without having to do any mapping/stack trace collection work). It also means that assembly file sizes are a little bit smaller and that the debugging experience should be improved (less exception catching & rethrowing).

Changes:

  • Restructuring of verifier/analyzer code.
  • Fixed exception stack trace collection regression that caused frame part of the exception stack trace collection infrastructure to show up in some stack traces.
  • Make synthesized .class resources available via ClassLoader.getResources() (note the plural) as well.
  • Use a LinkedHashMap to preserve annotation order (but only in dynamic mode, because for compiled code we get the .NET attributes in unspecified order). By my reading of the API spec there is no guarantee about the ordering, but the Google Guice test suite depends on it.
  • TypeWrapper.AssertFinished() doesn't make sense for the static compiler anymore.
  • Moved mutable flags from Instruction array into separate array.
  • Made ExceptionTableEntry immutable.
  • Implemented codegen improvement to use CLR fault handlers for Java catch all handlers, whenever possible.
  • IKVM.Reflection: Order try blocks inside handlers before the entries for that handler. Workaround for CLR x86 JIT null pointer dereference bug.

Binaries available here: ikvmbin-0.43.3811.zip

Tuesday, 08 June 2010 08:24:58 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Tuesday, 01 June 2010
New Development Snapshot

I got a little side tracked by the investigation of the Google Collections test suite performance issue, reported by Albert Strasheim in the comments to the previous snapshot.

This caused me to do some work on exception handling (unfortunately without any performance benefit to the Google Collections test suite) which, in turn, triggered something I've been wanting to do for while, namely to introduce a stub version of IKVM.OpenJDK.Core.dll which can be referenced by IKVM.Runtime.dll during FIRST_PASS compilation, to make it possible to have a cyclic dependency between IKVM.Runtime.dll and IKVM.OpenJDK.Core.dll for method signatures and not just the method bodies as was previously the case.

Changes:

  • Added (limited) support to ikvmc for cyclic dependency compilation. The build now takes advantage of this to make it possible to use strongly typed method signatures for "native" methods implemented in IKVM.Runtime.dll.
  • Changed reflection to convert any Method|FieldAccessExceptions to occur (in partial trust) into IllegalAccessException.
  • Fixed type conversion verification issues in reflection dynamic methods.
  • Moved exception handling code to IKVM.Runtime.dll (for IKVM.OpenJDK.Core.dll) and cleaned up several issues. Changed mapping API to be more efficient (in terms of bytecode size, and to allow stack trace collection to be bypassed for discarded remapped exceptions).
  • Added new public API to unmap exception (ikvm.runtime.Util.unmapException()).
  • Fixed loop counter integer overflow bug in tableswitch bytecode parsing. Bug #3009543.
  • IKVM.Reflection: Fixed bug in constructor importing that could cause Module.ResolveMethod() on ModuleBuilder to return the underlying MethodInfo instead of the ConstructorInfo wrapper.

Binaries available here: ikvmbin-0.43.3803.zip

Tuesday, 01 June 2010 07:36:30 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Tuesday, 25 May 2010
New Development Snapshot

More bug fixing and rounding out IKVM.Reflection.

Changes:

  • Fixed resolution of generic type instance names with "fake" type as type argument.
  • Fixed bug in Finalize/finalize special casing for .NET types that caused exception when reflecting on them.
  • Fixed Finalize/finalize special casing for .NET types to also work for java.lang.Throwable derived types.
  • Removed fake core class library types from ikvmstub and added a -bootstrap option to run without dependency on runtime/core class library.
  • Fixed regression introduced when ikvm.runtime.Startup.setProperties() signature was changed. It should also be changed in the executable main stub.
  • Fixed ikvmc/ikvmstub regression introduced with the switch to IKVM.Reflection (not IKVM.Reflection.Emit) in volatile field handling acros assemblies.
  • Fixed several bugs exposed by Google Guice 2.0 test suite (bug #3004682).
  • Fixed AssemblyClassLoader so that it does not claim to be able to load .class resources for dynamically loaded classes.
  • When compiling with the -sharedclassloader option we can't do the "effectively final" optimization, because classes in another assembly can be part of the same package (and hence extend the packge private class).
  • Handle the case where the exception block ends at the end of the method.
  • IKVM.Reflection: Implemented Type.IsAssignableFrom() (minus co-/contravariance).
  • IKVM.Reflection: Implemented custom attribute filtering at the source. Added support for custom attribute sub typing.
  • IKVM.Reflection: Added __GetCustomAttributes() overloads for Assembly and Module for ease of use and consistency.
  • IKVM.Reflection: Added ICustomAttributeProvider interface.

Binaries available here: ikvmbin-0.43.3797.zip

Tuesday, 25 May 2010 06:28:37 (W. Europe Daylight Time, UTC+02:00)  #    Comments [2]
# Tuesday, 18 May 2010
New Development Snapshot

More IKVM.Reflection fixes and some improvements to ikvmc and ikvmstub.

Changes:

  • Allow ikvmstub to work with -nostdlib and an explicit path to mscorlib.
  • Fixed ikvmc/ikvmstub assembly resolver to recognize mscorlib by its name, not by having a System.Object type.
  • ikvmc/ikvmstub: Added strong named assembly version "policy" support. Reject lower versions, accept higher versions with optional warning and prefer exact matches.
  • ikvmc/ikvmstub: Added check to avoid loading assemblies that require a newer version of mscorlib than the one were using (to avoid weird exceptions and potential other problems).
  • ikvmc/ikvmstub: Base assembly ref/def matching on Universe.CompareAssemblyIdentity().
  • Changed StaticCompiler.GetType() to be multi-target aware. Instead of looking thru all assemblies currently loaded, only the relevant referenced assemblies are searched. Note that this is a (minor) breaking change. Types referenced in -remap:map.xml file are now only resolved against directly referenced assemblies.
  • Fixed ikvmc regression in custom assembly class loader module constructor support.
  • IKVM.Reflection: It turns out that mscorlib is special cased by the runtime. Any name with a simple name of "mscorlib" is considered mscorlib.
  • IKVM.Reflection: Made mscorlib handling more explicit (and simpler) and fixed Import() to not load assemblies directly, but go through the resolve event.
  • IKVM.Reflection: Added Assembly.CodeBase property and fixes Assembly.GetName() and AssemblyName.GetAssemblyName() to set the CodeBase of the AssemblyName.
  • IKVM.Reflection: Fixed GetReferencedAssemblies() to set AssemblyName.CultureInfo when it's the invariant culture and to set AssemblyName.Flags.
  • IKVM.Reflection: Added AssemblyName.ToString().
  • IKVM.Reflection: Set flags in AssemblyName returned by Assembly.GetName().
  • IKVM.Reflection: Support setting the Retargettable assembly name flag.
  • IKVM.Reflection: Added implementation of Fusion's CompareAssemblyIdentity API.
  • IKVM.Reflection: Added RawModule to allow user code to load and inspect a module without it becoming part of the universe and later import it efficiently into the universe.
  • IKVM.Reflection: Made Universe.HasMscorlib internal and removed the now obsolete Universe.LoadMscorlib().
  • IKVM.Reflection: Added protection against accidentally importing any IKVM.Reflection type, not just Type.

Binaries available here: ikvmbin-0.43.3790.zip

Tuesday, 18 May 2010 16:58:24 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Monday, 10 May 2010
New Development Snapshot

More fixes. Thanks to Kornél Pál for his patches, bug reports and work on porting gmcs to IKVM.Reflection.

Changes:

  • Removed mcs specific flag that is no longer required.
  • Removed use of reflection for getting the slot of a java.lang.reflect.Field.
  • Implemented RuntimeMXBean. Feature request #2994310.
  • Implemented OperatingSystemMXBean.
  • Added ikvmc option to disable automagic serialization.
  • Fixed ikvmc to give a proper error message if an output file cannot be created.
  • Added -delaysign option to ikvmc.
  • Added support for AssemblyVersionAttribute and AssemblyCultureAttribute to ikvmc.
  • Added warnings to ikvmc for AssemblyDelaySignAttribute, AssemblyKeyFileAttribute and AssemblyKeyNameAttribute.
  • Added warning to ikvmc when StructLayoutAttribute is ignored.
  • Fixed runtime to register .NET generic type instances with the right class loader (i.e. the special generic class loader that is created, instead of the assembly class loader of the generic type definition).
  • Fixed EnumHelper.GetPrimitiveValue() to handle the case where the underlying type of an enum differs from the constants values attached to the fields.
  • Added a couple of checks to the runtime to avoid problems when user code tries to convert .NET types that aren't supported into a java.lang.Class.
  • IKVM.Reflection: Fixed a whole bunch of bugs exposed by Kornél Pál awesome work on porting gmcs to IKVM.Reflection.
  • IKVM.Reflection: Removed TypeForwardedToAttribute support and added explicit API to do the same. Modified ikvmc to use new API.
  • IKVM.Reflection: Removed DefaultParameterValueAttribute support.
  • IKVM.Reflection: Fixed AssemblyName.GetAssemblyName() to throw the proper exceptions.
  • IKVM.Reflection: Implemented ModuleBuilder.GetArrayMethod(). Based on patch from Kornél Pál.
  • IKVM.Reflection: Removed CheckBaked() from __GetDeclaredXxx methods and moved it to .NET compatible APIs only.
  • IKVM.Reflection: Added support for defining mscorlib assembly.
  • IKVM.Reflection: Added __SetAssemblyVersion(), __SetAssemblyCulture(), __SetAssemblyKeyPair(), __SetAssemblyPublicKey(), __SetAssemblyAlgorithmId() and __SetAssemblyFlags() methods to AssemblyBuilder.
  • IKVM.Reflection: Added support for delay signing.
  • IKVM.Reflection: Added TypeBuilder.__SetAttributes() and MethodBuilder.__SetAttributes() to allow modying the attributes after the builder has been created.

Binaries available here: ikvmbin-0.43.3782.zip

Monday, 10 May 2010 07:26:53 (W. Europe Daylight Time, UTC+02:00)  #    Comments [3]