# Monday, 19 October 2009
IKVM 0.42 Release Candidate 1

A new release candidate is available.

Changes since previous release candidate:

  • Changed version to 0.42.0.1.
  • Fixed a regression introduced in 0.40 that caused a System.NotSupportedException to be thrown by ikvmc when compiling multiple targets where one target (indirectly) implements a non-public interface from another target. Thanks to Erik Vullings for reporting this.

Binaries available here: ikvmbin-0.42.0.1.zip

Sources: ikvm-0.42.0.1.zip, openjdk6-b16-stripped.zip

Monday, 19 October 2009 06:56:56 (W. Europe Daylight Time, UTC+02:00)  #    Comments [4]
# Monday, 12 October 2009
IKVM 0.42 Release Candidate 0

The first release candidate is available.

Changes since last 0.41 development snapshot:

  • Changed version to 0.42.0.0.
  • Fixed virtual file system regression that caused NullReferenceException when trying to access a non-existing directory.
  • Volker added some print support code.
  • Fixed assertion in ILGenerator.
  • Fixed regression in reflection introduced when we started allowing open generic types to be visible to Java (for stack walking).
  • Fixed bug #2876211.

Binary available here: ikvmbin-0.42.0.0.zip

Sources: ikvm-0.42.0.0.zip, openjdk6-b16-stripped.zip

Monday, 12 October 2009 06:43:34 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Friday, 02 October 2009
New Development Snapshot

We're starting to prepare for the 0.42 release. This is the last 0.41 development snapshot.

Changes:

  • Added support for exposing open generic types as Java classes (special "handle" classes that can only be used for stack walking). Fixes bug #2843805.
  • ArrayTypeWrapper: Fixed a race condition and avoid holding the lock while calling external code.
  • Removed vestigial compact framework support code.
  • Some source file restructuring (Moved DynamicTypeWrapper and DotNetTypeWrapper classes into their own source files and AssemblyClassLoader and BootstrapClassLoader clases into AssemblyClassLoader.cs).
  • Fixed regression introduced with recent label handling changes. Bug #2847725.
  • Various AWT fixes by Nat and Volker.
  • Rewrote custom assembly class loader initialization to avoid running user code (static initializer) while holding a lock and to better handle invocation of getClassLoader() during the class loader constructor (or static initializer).
  • Added hack to expose more custom attributes from mscorlib as annotations.

Binary available here: ikvmbin-0.41.3562.zip

Friday, 02 October 2009 06:58:51 (W. Europe Daylight Time, UTC+02:00)  #    Comments [1]
# Tuesday, 25 August 2009
New Development Snapshot

Time for another snapshot as there have been a large number of changes since the previous snapshot. The Swing/AWT work that Volker and more recently also Nat have been doing has resulted in SwingSet2 now running quite nicely. Check out these screenshots:

Click for full size Click for full size Click for full size

Note that this is running the OpenJDK Swing code, with the GNU Classpath code the source code view and the HTML tab (the blue "Bouncing Babies!" text is HTML rendered in the tab) never worked. So this is great progress, but a lot more is still needed. Keyboard (and focus) support is still lacking and font support is still fairly limited, for example.

Changes:

  • More AWT/Swing work by Volker Berlin and Nat Luengnaruemitchai.
  • Fixed detection of dynamic assemblies (at runtime).
  • Fixed NullReferenceException when getting annotations on delegate constructor for delegates defined in Java.
  • Added App.config setting (ikvm-emit-symbols) to force emitting debug symbols on or off.
  • Fixed regression introduced in 0.40 that caused ikvmc to crash when specifying a non-public custom class loader.
  • Fixed bug in the handling of Annotation.__ReturnValue and Annotation.__Multiple fake types.
  • Implemented automatic .NET serialization support for Java serializable type (see here for details).
  • Fix for #2829717. Constructing java.lang.String instances from JNI should redirect to static helper method.
  • Several minor IKVM.Reflection.Emit fixes.
  • Added ILGenerator.__GetILOffset().
  • Changed CodeEmitter to use ILGenerator.__GetILOffset() (when usig IKVM.Reflection.Emit) instead of manually tracking the IL offset.
  • Added "clever" exception block assistance mode to ILGenerator. In this mode, leave and endfinally instructions are only auto inserted when necessary.
  • Use ILGenerator's new "clever" mode in ikvmc to produce smaller code.
  • Fixed IKVM.Reflection.Emit to put .pdb file in same location as assembly (instead of current directory). Thanks to Dawid Weiss for reporting this.
  • Removed ISymWrapper.dll dependency from IKVM.Reflection.Emit.PdbWriter.dll.
  • IKVM.Reflection.Emit.PdbWriter.dll now caches the debugging information, instead of "streaming" it into the unmanged PDB writer to workaround the ridiculous memory usage of the unmanaged PDB writer. It is now possible to build the full core class library assemblies set with debugging enabled.
  • Fixed major regression in pdb debugging support introduced in 0.40 that caused local variable support to be completely broken.

Binary available here: ikvmbin-0.41.3524.zip

Tuesday, 25 August 2009 09:21:38 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Monday, 24 August 2009
Microsoft PDC

If you're going to the PDC and want to chat, let me know.

Meet me in Los Angeles -- PDC 2009

Monday, 24 August 2009 06:23:45 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Tuesday, 11 August 2009
Serialization Interop

I'm not a big fan of serialization, but there is one use that makes sense to me; intra-process, cross-AppDomain serialization. If you have ever done any cross-AppDomain work with IKVM you've probably run into the situation where a Java exception couldn't be serialized across the AppDomain boundary.

I've finally addressed this by building automatic (oneway) serialization interop support into IKVM. This means that most Java classes that are serializable should now automatically become .NET serializable. There are, however, some important caveats:

  • Serialized streams will not be compatible between different IKVM releases. This is intended *only* for cross-AppDomain serialization between different instances of the same IKVM code.
  • ObjectOutputStream.writeUnshared() and ObjectInputStream.readUnshared() have not been implemented. So any classes that rely on those will fail to serialize/deserialize.
  • Instances of dynamically loaded Java classes and statically (ikvmc) compiled classes that implement readResolve() will fail deserialization if they (directly or indirectly) serialize self references.
  • Deserialization ordering may be different, meaning that if a class has a custom deserialization method, it may encounter objects that have not been completely deserialized.
  • Under some circumstances, a class that implements readResolve() may have its readResolve() method called twice on the same object.
  • When a ghost array is serialized, it is serialized as an object[] (i.e. it loses its specific type).

Again, any Java class that is serializable (i.e. that implements java.io.Serializable or java.io.Externalizable and follows the associated rules) is generally automatically .NET serializable. There are a couple of exceptions where ikvmc and the runtime will assume that your class wants to handle its own .NET serialization:

Using the .NET custom serialization custom attributes OnDeserializedAttribute, OnDeserializingAttribute, OnSerializedAttribute or OnSerializingAttribute does not interfere with getting automatic serialization support (and the .NET serialization engine will call the annotated methods at the appropriate times).

Inheritance - Extending Java classes in .NET

When you want to subclass a serializable Java class in (e.g.) C# and make your subclass serializable as well, you need to do two simple things:

  1. Add a [Serializable] attribute to your class.
  2. Add a .NET deserialization constructor that calls the base class constructor and does nothing else.

Here's an example of extending java.util.ArrayList:

[Serializable]
class MyList : java.util.ArrayList
{
  private int exampleField;

  public MyList()
  {
  }

  protected MyList(SerializationInfo info, StreamingContext context)
    : base(info, context)
  {
  }
}

MyList is now .NET serializable and exampleField will automatically be serialized/deserialized.

Inheritance - Extending .NET classes in Java

For this scenario, nothing has really changed. You still need to follow the standard .NET rules for creating serializable types.

Serializing .NET objects in Java

The automatic serialization interop is only one way, so you won't be able to serialize .NET objects using Java serialization (unless they happen to implement java.io.Serializable.__Interface or java.io.Externalizable). I currently have no plans to implement this functionality.

Tuesday, 11 August 2009 09:24:07 (W. Europe Daylight Time, UTC+02:00)  #    Comments [2]
# Friday, 31 July 2009
IKVM 0.40 Update 1 Release Candidate 1

Another minor update.

Changes:

  • Changed version to 0.40.0.3
  • Fixed regression introduced in 0.40 that caused ikvmc -classloader:<class> option to fail if <class> wasn't public.
  • Fixed regression introduced in 0.40 that caused ikvmstub on core class libraries to fail.
  • Fixed #2829717.

Binaries available here: ikvmbin-0.40.0.3.zip.

Sources: ikvm-0.40.0.3.zip, classpath-0.95-stripped.zip, openjdk6-b12-stripped-IKVM-0.40.zip

Friday, 31 July 2009 08:50:46 (W. Europe Daylight Time, UTC+02:00)  #    Comments [10]
# Friday, 17 July 2009
Responsible Disclosure, Irresponsible Patching?

In December 2006 I reported a critical .NET security vulnerability to Microsoft. When I found the the issue it had already been fixed in Vista, but it still took them until July 2007 to release a fix for XP. Seven months, I thought that was pretty bad.

In September 2008 I reported another critical .NET security vulnerability to Microsoft. The fix for this issue was trivial and made it into the subsequent Silverlight 2.0 RTM on October 13th. This week the July patches were released and for the tenth month no security bulletin about this issue.

Wednesday I mailed the Microsoft Security Response Center to ask what the status is. I received no reply.

So I decided to investigate. I quickly discovered that my main (Vista) system was already patched (!). After some digging I found that on XP, Windows Update offers KB951847 which contains a fix.

The KB article makes no mention of any security fixes, nor is there a corresponding security bulletin.

If this is Microsoft's idea of responsible disclosure, then maybe I should also apply my "no Microsoft bug filing" policy to security issues.

Friday, 17 July 2009 10:37:40 (W. Europe Daylight Time, UTC+02:00)  #    Comments [4]
# Thursday, 16 July 2009
New Development Snapshot

It's been a while since the previous snapshot, but I haven't been sitting around idle. Besides the fixes to IKVM.Reflection.Emit, which were part of secret prototype project I've been working on (and may or may not announce at some point in the future :-)), I've also been working on IKVM.NET itself.

I did a bunch of work to improve startup (at least for "core" classes). In particular, many scenarios should now be possible without initializing the reflection machinery.

Here are some examples:

 

IKVM 0.40

IKVM 0.41.3484

 

    x86 JIT

    x86 NGEN

            x86 JIT

    x86 NGEN

    2nd invocation

obj = Float.TYPE 12.4 1.56 0.280 0.0152 0.0041
System.out.println("Hello World") 275 12.8 114 8.90 0.0569
new StringBuffer() 129 10.8 6.34 0.0866 0.0041
Charset.forName("windows-1252") 267 13.7 77.4 7.87 0.0028


Times are in milliseconds and (except for the last column) show the time it takes to execute the code snippet on the left as the very first Java code in the process. I added the "2nd invocation" column to emphasize that these large times are due to JIT and/or initialization costs. Things have clearly improved, but it should also be clear that when you care about startup time, you really need to look into using NGEN.

I should point out that currently only the "windows-1252" (and UTF-8) charsets are eagerly constructed to avoid reflection, if you care about another charset, let me know and I will add it (unless your charset isn't in IKVM.OpenJDK.Core.dll, then you're out of luck.)

Changes:

  • More AWT/Swing work..
  • Removed more GNU Classpath remnants.
  • Added rmi stub generation to build process, instead of relying on .class files in stripped zip.
  • Added "RuntimeCompatibilityAttribute(WrapNonExceptionThrows = true)" to generated assemblies.
  • Added ikvmc warnings for VerificationError and ClassFormatError.
  • Added -baseaddress:<address> option to ikvmc.
  • Fixed ikvmc to skip empty lines in response file, instead of throwing an exception.
  • Split XML assembly into eight parts. Thanks to Michael Kay for helping out with this.
  • Changed build to put x86 specific binaries in bin-x86 directory and x64 specific binaries in bin-x64. jvm.dll is now always built in both flavors. Unfortunately, ikvm-native still needs to be built separately.
  • Split core library into several more assemblies.
  • Added step to build process to automatically compute a base address for core library assemblies. This should make ngen-ed images more efficient (if the images can be loaded at their preferred base addresses).
  • Added a mechanism to the build to prevent accidentally introducing new dependencies between the OpenJDK assemblies.
  • Fixed bug that caused startup properties set with ikvm.runtime.Startup.setProperties() to be forgotten when doing a System.setProperties(null).
  • Forked java.io.ObjectStreamField to make signature computation lazy.
  • Made ikvm.runtime.Util.getInstanceTypeFromClass() into an instrinsic, when used with a class literal.
  • Optimized class literals that reference statically compiled classes (at a slight cost to dynamically compiled classes).
  • Optimized primitive class literals.
  • Added codegen optimization for reading unsigned bytes from a byte array (buf[i] & 0xFF or buf[i] 0x0FFL).
  • Made callerID initialization lazy.
  • Forked sun/nio/cs/StandardCharsets.java to eagerly create MS1252 and UTF-8 charsets, to avoid reflection (at least in Western Europe, if you want another charset added, just let me know.)
  • Several other minor optimizations.

Binary available here: ikvmbin-0.41.3484.zip

Thursday, 16 July 2009 10:00:05 (W. Europe Daylight Time, UTC+02:00)  #    Comments [4]
# Friday, 26 June 2009
IKVM.Reflection.Emit Update

I have done a massive amount of fixes to IKVM.Reflection.Emit to make it full featured (even though it still doesn't implement all Reflection.Emit APIs, the functionality should (almost) all be there, for example via different overloads).

I completed support for generics (I think) and fixed many bugs in that area, ikvmc only uses a very small amount of generics so these fixes are unlikely to affect it.

It's worth explicitly stating the design goals of IKVM.Reflection.Emit:

  • It's a write-only API. Some GetXXX methods or properties may be implemented, but that's mostly for its internal convenience.
  • There is intentionally no error checking. During ikvm development the error checking in System.Reflection.Emit has cost me a huge amount of time, it is generally much easier to diagnose the problem when you have a broken assembly file. PEverify and ILDASM are your friends.
  • Code that uses System.Reflection.Emit in a write-only way is supposed to "just work" (modulo missing APIs, but those changes should be trivial).

I've done some pretty heavy duty testing on it. It should be ready for external (i.e. non-ikvmc) usage now. If you decide to use it (or consider using it), please let me know. As always, feedback is appreciated.

Changes:

  • Added support for ByRef and Pointer types.
  • Completed support for all literal field constant types and fixed null literal fields.
  • Added ModuleBuilder.DefineInitializedData().
  • Fixed many generics related bugs.
  • Added a (non-standard) API to ModuleBuilder to set the PE image base address.
  • Added TypeBuilder.SetParent().
  • Added TypeBuilder.GetMethod() and TypeBuilder.GetConstructor() to instantiate methods on generic types.
  • Added a (non-standard) API to ILGenerator to disable the "helpful" automatic leave/endfinally instructions in exception blocks.
  • Added support for pinned local variables.
  • Added UIntPtr and TypedReference signature encodings.
  • Fixed handling of TypeBuilder enums in custom attributes.
  • Added MethodBuilder.SetSignature().
  • Added GenericTypeParameterBuilder.SetInterfaceConstraints() and .SetGenericParameterAttributes().
  • Fixed (Method|Type)Builder.SetCustomAttribute() to set HasSecurity flag when SuppressUnmanagedCodeSecurityAttribute is set.
  • Added support for defining events.

Binary available here: ikvm-refemit-0.41.3464.zip

Friday, 26 June 2009 06:42:52 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]