# Monday, 22 October 2007
New Development Snapshot

I've made a bunch of changes to support custom assembly class loaders. This should finally solve some of the issues caused by the new class loader architecture. Eventually it will be possible to write your own assembly class loader (hence the name custom assembly class loaders), but currently only the two provided ones are supported: ikvm.runtime.AppDomainAssemblyClassLoader and ikvm.runtime.ClassPathAssemblyClassLoader.

AppDomainAssemblyClassLoader

This approximates the pre-0.32 behavior by searching all currently loaded assemblies (after looking in the assembly itself and the assemblies it references).

ClassPathAssemblyClassLoader

This class loader supports dynamically loading classes and resources from the CLASSPATH (or java.class.path system property). It too first searches the assembly itself and any assemblies it references. This class loader makes the most sense as a replacement for the assembly class loader of the main executable, that way it will also be the system class loader. Note that if multiple assemblies use this class loader, they each will have a separate class loader instance that loads different classes (even though they may be based on the same class files).

How to Use

There is a new ikvmc option to specify a custom assembly class loader:

ikvmc -classloader:ikvm.runtime.AppDomainAssemblyClassLoader example.jar

For non-Java code you can apply a custom attribute to your code:

using System;

[assembly: IKVM.Attributes.CustomAssemblyClassLoader(typeof(ikvm.runtime.ClassPathAssemblyClassLoader))]

class SimpleJavaRunner
{
  public static void Main(string[] args)
  {
    string[] newArgs = new string[args.Length - 1];
    Array.Copy(args, 1, newArgs, 0, newArgs.Length);
    java.lang.Class.forName(args[0])
      .getMethod("main", typeof(string[]))
      .invoke(null, new object[] { newArgs });
  }
}

You can also specify them in the app.config file, this overrides the above methods:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="ikvm-classloader:MyExampleAssembly" value="ikvm.runtime.AppDomainAssemblyClassLoader, IKVM.OpenJDK.ClassLibrary, Version=0.37.0.0, Culture=neutral, PublicKeyToken=null" />
  </appSettings>
</configuration>

Here the key is ikvm-classloader: followed by the simple name of the assembly. The value must be the assembly qualified type name of the custom assembly class loader type.

As always, feedback is appreciated.

Changes:

  • Implemented Custom Assembly Class Loaders.
  • Fixed URL.equals() for "ikvmres:" urls.
  • Fixed findResources() bug that caused resources in core assembly to show up twice if a .NET assembly explicitly referenced the core assembly.
  • Added check to prevent defineClass() on an assembly class loader from defining a class that already exists in the assembly.
  • Fixed Class.getModifiers() to mask out ACC_SUPER bit.

Binaries available here: ikvmbin-0.37.2851.zip.

Monday, 22 October 2007 15:22:38 (W. Europe Daylight Time, UTC+02:00)  #    Comments [1]
# Monday, 15 October 2007
Mono Summit 2007

I'll be at the Mono Summit 2007.

Monday, 15 October 2007 11:59:24 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Friday, 12 October 2007
IKVM 0.36 rc5

Yet another release candidate and possibly not even the last one (more on that next week).

Changes:

  • Fixed reflection regression introduced in rc4.
  • Added workaround for .NET 3.5 beta breaking change.
  • Added support for another binary compatibility issue (public classes nested in non-public classes).
  • Added workaround for another .NET 2.0 x64 JIT bug.

Binaries available here: ikvmbin-0.36.0.4.zip.

Sources (+ binaries): ikvm-0.36.0.4.zip

External sources (haven't changed since rc1): classpath-0.95-stripped.zip, openjdk-b13-stripped.zip

Friday, 12 October 2007 18:28:39 (W. Europe Daylight Time, UTC+02:00)  #    Comments [3]
# Monday, 01 October 2007
IKVM 0.36 rc4

External forces inspired me (read: I was paid) to make another release candidate.

Reflection on .NET is very slow compared with Java and because IKVM reflection was built on top of .NET reflection, it too was very slow. I rewrote the lower levels of reflection to take advantage of DynamicMethod when running .NET 2.0. This allows the slow .NET reflection to be bypassed and optimized accessor methods to be generated dynamically. I also rewrote the part of serialization that uses reflection to get and set the field values to generate custom dynamic methods for the serialization process. Serialization is now up to 20x faster.

Unfortunately I had to disable the use of DynamicMethod when running on Mono, because testing revealed that Mono 1.2.5's implementation of DynamicMethod is still too buggy.

A remaining caveat wrt reflection performance is that you need to call setAccessible(true) to get the best performance when running on IKVM, because stack walking (which is needed to do the required access checks when you access a non-public member) is still very slow compared with Java.

Changes:

  • Improved serialization and reflection performance when running on .NET 2.0.

Binaries available here: ikvmbin-0.36.0.3.zip.

Sources (+ binaries): ikvm-0.36.0.3.zip

External sources (haven't changed since rc1): classpath-0.95-stripped.zip, openjdk-b13-stripped.zip

Monday, 01 October 2007 15:31:54 (W. Europe Daylight Time, UTC+02:00)  #    Comments [1]
# Thursday, 20 September 2007
IKVM 0.36 rc3

This is probably the last release candiate before the official 0.36 release.

Changes:

  • Fixed non-blocking nio socket send of zero bytes to not return -1.
  • Fixed nio Selector.wakeup() race condition.
  • Added checks for code that uses reflection to call ClassLoader.defineClass() on the assembly class loader for ikvmc compiled classes to throw IllegalAccessError when the class tries to extend a non-public base class (instead of dying with a Critical Failure).
  • Fixed bug in the handling of Java annotations applied in .NET code (via the corresponding ikvmc generated attributes).
  • Significantly improved performance of Class.getModifiers().

Binaries available here: ikvmbin-0.36.0.2.zip.

Sources (+ binaries): ikvm-0.36.0.2.zip

External sources (haven't changed since rc1): classpath-0.95-stripped.zip, openjdk-b13-stripped.zip

Thursday, 20 September 2007 15:55:12 (W. Europe Daylight Time, UTC+02:00)  #    Comments [1]
# Monday, 17 September 2007
Two Useful Tools for IKVM.NET

IKVMDoc

Brian Heineman wrote a doclet to convert Javadoc into .NET XML documentation that can be consumed by .NET tools like Visual Studio. This makes the type and member documentation available in the Visual Studio IntelliSense popups. Very nice! There's still room for improvement, especially in the area of converting broken html tags into well formed xml tags. The code is available cvs. I've used it to generate an xml documentation file for IKVM.OpenJDK.ClassLibrary.dll and that can be downloaded here.

In future IKVM releases I plan to include an ikvmc compiled version of IKVMDoc.

jar2ikvmc

Gena Donchyts wrote a handy tool that analyzes a bunch of jars and generates a script to ikvmc compile these jars in the right order and with the required (static) dependencies. The tool and documentation are available here.

Thanks

Thanks to Brian and Gena for providing these great tools!

Monday, 17 September 2007 08:18:25 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Thursday, 13 September 2007
IKVM 0.36 rc2

Release candidate 2.

Changes:

  • Fixed annotation handling to use Enum.valueOf() instead of reflection, to prevent IllegalAccessException when accessing non-public enum.
  • Bootstrap packages are no longer sealed.
  • Packages for ikvmc compiled code are no longer sealed automatically (only when they are sealed in the manifest).
  • Implemented support for enabling/disabling assertions in ikvm.exe.
  • Fixed ikvmstub exception when the resulting jar is empty.
  • Added support for creating proxies for non-public interfaces in ikvmc compiled assemblies.
  • Made method annotation resolution lazy, to deal with annotations that annotate themselves.
  • Fixed bug in finalize method handling that could cause compiler error if base class explicitly called finalize method in derived class.
  • Improved JLS binary compatibility support.
  • Fixed implicit conversion from System.Type to java.lang.Class to return null instead of throwing a NullReferenceException for unrepresentable types.

Binaries available here: ikvmbin-0.36.0.1.zip.

Sources (+ binaries): ikvm-0.36.0.1.zip

External sources (haven't changed since rc1): classpath-0.95-stripped.zip, openjdk-b13-stripped.zip

Thursday, 13 September 2007 11:53:26 (W. Europe Daylight Time, UTC+02:00)  #    Comments [1]
# Monday, 03 September 2007
IKVM 0.36 rc1

Release candidate 1 of the first OpenJDK based release.

Compared with the last snapshot I made one small change, I implemented the new 1.6 JNI method.

Binaries available here: ikvmbin-0.36.0.0.zip.

Sources: ikvm-0.36.0.0.zip, classpath-0.95-stripped.zip, openjdk-b13-stripped.zip

If you want to build from source, you need the classpath and openjdk zips as well. The classpath-0.95-stripped.zip file contains the required AWT/Swing sources (from a patched version of GNU Classpath 0.95). The openjdk-b13-stripped.zip contains the required sources and the required generated sources (from running an OpenJDK build on Linux). These two zips need to be unzipped in the same directory as where you unzip ikvm-0.36.0.0.zip. I've tested the build on Windows with .NET 1.1, .NET 2.0 and Mono 1.2.3 and on Linux with Mono 1.2.5.

Monday, 03 September 2007 09:54:34 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Wednesday, 29 August 2007
New Snapshot

One more snapshot before release candidate 1 with a couple of fixes:

  • Windows x64 specific binaries are now included (in the ikvm\bin-x64 directory).
  • Enabled workaround for x64 tail call optimization.
  • Implemented clearing of SoftReferences. They're still not guaranteed to be cleared before an OutOfMemoryError, but the new behavior is hopefully more reasonable than never clearing them.
  • Fixed code generator bug that could cause AbstractMethodError to be thrown when subclassing a .NET type that has an explicit interface method implementation.
  • Integrated IcedTea updates to support PBEwithMD5andDES.

Binaries available here: ikvmbin-openjdk-0.35.2796.zip.

Wednesday, 29 August 2007 08:26:12 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Tuesday, 28 August 2007
MS07-045 bug

We interrupt our regularly scheduled programming for some Microsoft idiocy. If you have a classic ASP website that instantiates .NET classes via COM interop that suddenly stopped working after installing MS07-045 and you're now getting the dreaded 0x8000FFFF Catastrophic failure aka E_UNEXPECTED, you can fix that by allowing Everyone Read access to HKEY_USERS\S-1-5-20\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones or by running MS07-045-patch (.NET 2.0 required) to make the registry permission changes for you (you need admin rights to make the changes or run the executable).

Tuesday, 28 August 2007 11:38:35 (W. Europe Daylight Time, UTC+02:00)  #    Comments [2]