# Thursday, 27 September 2012
Bye Bye ConstructorBuilder

System.Reflection.Emit is a great .NET feature, especially if you consider that it shipped as part of .NET 1.0, but the design of System.Reflection.Emit leaves something to be desired.

One of the crazy features is ConstructorBuilder. On the System.Reflection side, ConstructorInfo isn't all that helpful, but it is not as actively harmful as ConstructorBuilder. The reason for this is that ConstructorInfo and MethodInfo both extend MethodBase, so most common APIs are available through MethodBase.

ConstructorBuilder and MethodBuilder share no common Builder base class (because they extend ConstructorInfo and MethodInfo), this causes a lot of code duplication and type testing/downcasting.

A long time ago I found out that you can mostly avoid ConstructorBuilder, since it is possible to use TypeBuilder.DefineMethod() to define constructors. Recently I finally got around to taking advantage of this and completely removing ConstructorBuiler from the IKVM.NET runtime and compiler.

The thing that pushed me over the edge was this experiment. In .NET 2.0 there is no ConstructorBuilder equivalent to MethodBuilder.CreateMethodBody(). So if I'm ever going to experiment with method level JIT it is nice to be able to use this more efficient method of installing the stub.

There is one problem with using MethodBuilder for constructors. If you define a custom attribute and want to apply that custom attribute while it is still unbaked, you need a ConstructorBuilder for the custom attribute constructor, because CustomAttributeBuilder requires it. Luckily, in dynamic mode IKVM doesn't need to do this and in static mode I use IKVM.Reflection so I added MethodInfo.__AsConstructorInfo() to wrap the MethodInfo in a ConstructorInfo.

I considered adding MethodInfo support to CustomAttributeBuilder, but that turned out to be much more complicated, so I went with the easy approach of reusing the existing wrapping strategy.

The result of this refactoring is the removal of a bunch of duplicate code and a lot of downcasting. It also saves a small bit of memory, because the ConstructorBuilder wrappers are not needed anymore.

Thursday, 27 September 2012 14:29:05 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Wednesday, 26 September 2012
IKVM.NET 0.46 Update 2 Release Candidate 0

The 0.46 version is the last version based on Java 6 and as mentioned previously would be supported longer than a typical release. Based on user feedback I decided to post an update that fixes a number of bugs that have been found since the previous release.

Changes (relative to 0.46 Update 1):

  • Updated version to 0.46.0.3.
  • Bug fix. java.lang.Package was not populated from manifest for ikvmc compiled assemblies.
  • Bug fix. When writing a direct ByteBuffer to a non-blocking socket and the write fails because there is no kernel buffer available, we should not advance the ByteBuffer position.
  • Bug fix. When adding certificates to virtual cacerts file make sure that the aliases are unique.
  • Bug fix. If a finally/fault handler contains reachable code before the handler's start index, the handler should branch to the handler start index.
  • Bug fix. After emitting a finally/fault handler block, we should emit the block leave stubs (even though you can't leave the block, they also emit the backward branch stubs).
  • Bug fix. If a Java class extends a remapped .NET type (cli.System.Object or cli.System.Exception), we should correctly report the base class.
  • Bug fix. If we encounter a jsr or ret instruction, we should throw a VerifyError (instead of NotImplementedException).
  • Bug fix. If an exception block ends with an astore, we need to propagate the local variable type after the astore to the exception handler.
  • Disable AppDomain.ProcessExit hook to run shutdown hooks when running on Mono to workaround https://bugzilla.xamarin.com/show_bug.cgi?id=5650
  • Bug fix. Custom attribute properties that don't have a public getter and setter should not be exposed as annotation properties.
  • Bug fix. Non-public property getter/setter methods should be ignored when we create properties to hide properties inherited from shadow types. This fixes a build break with .NET 4.5 beta which introduces a protected setter for Exception.HResult.
  • Bug fix. The $Method inner class for delegates should also be loadable for generic delegates. Thanks to Michael Bayne for reporting this.
  • Bug fix. When constructing a generic class loader we can't use GetWrapperFromType() on the type arguments, because they might refer to a subtype that is currently being loaded.
  • Replaced non-ascii character (micro) with ascii 'u' in Win32PrintService.java.
  • IKVM.Reflection: Bug fix. Resource Directory Entries must be sorted and names are case-insensitive.

Binaries available here: ikvmbin-0.46.0.3.zip

Sources: ikvmsrc-0.46.0.3.zip, openjdk6-b22-stripped.zip

Wednesday, 26 September 2012 08:16:30 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Monday, 17 September 2012
IKVM.NET 7.2 Release Candidate 1

The previous release candidate had a regression that caused custom attributes specified in the remap xml file not to be applied. This caused the build to fail on .NET 4.0.

Changes (relative to rc 0):

  • Updated version to 7.2.4630.1
  • Fixed build number in CommonAssemblyInfo.cs.in.
  • Fixed .NET 4.0 build issues.
  • Fixed map.xml custom attribute application regression.
  • Updated HOWTO.

Binaries available here: ikvmbin-7.2.4630.1.zip

Sources: ikvmsrc-7.2.4630.1.zip, openjdk-7u6-b24-stripped.zip

Monday, 17 September 2012 13:39:29 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Tuesday, 04 September 2012
IKVM.NET 7.2 Release Candidate 0

The first release candidate is available. Compared with the development snapshot some minor improvements to Object.getClass() and Class.getDeclaredField() instrinsics were made.

Changes (relative to IKVM.NET 7.1):

  • Integrated OpenJDK 7u6 b24.
  • Improved java.util.concurrent performance.
  • Removed org.omg.PortableInterceptor.UNKNOWN class, that is not part of [Open]JDK rt.jar.
  • Added ZipFile constructor that was added in Java 7.
  • Changed ikvmc to apply custom attribute annotations on annotation types to the corresponding custom attribute that is generated (and allow AttributeUsageAttribute to override the default AttributeUsageAttribute generated from the @Target annotation).
  • Added app.config files for executables to allow them to run on .NET 4.5 on Windows 8 without triggering the .NET 3.5 auto download.
  • Bug fixes.
  • Many IKVM.Reflection improvements.

Binaries available here: ikvmbin-7.2.4630.0.zip

Sources: ikvmsrc-7.2.4630.0.zip, openjdk-7u6-b24-stripped.zip

Tuesday, 04 September 2012 15:39:29 (W. Europe Daylight Time, UTC+02:00)  #    Comments [5]