# 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]
# Monday, 03 May 2010
IKVM 0.42 Update 1 Released

I've promoted 0.42 Update 1 RC 2 to an official release.

Changes (Update 1 RC 0 + RC 1 + RC 2):

  • Added fix to mangle all artificial type names if they clash with Java type names in the same assembly.
  • Fix for http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41696.
  • Fixed exception sorter to be correct when invoked with two references to the same object.
  • Fix for bug #2946842.
  • Fixed ikvmstub to not emit stubs for generic type definitions.
  • Fixed several incorrect usages of Type.IsArray when we only want to deal with vectors.
  • Fixed timezone handing bug for unrecognized timezone names.
  • Several partial trust fixes.

The 0.42 release notes can be found here.

If you want to build from source, you need openjdk6-b16-stripped.zip from the 0.42.0.3 folder.

Monday, 03 May 2010 07:10:51 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Friday, 23 April 2010
New Development Snapshot

A fairly massive set of changes this time, mostly around .NET 4.0 suport and IKVM.Reflection fixes.

Targetting .NET 4.0

Please note that the work isn't done yet (in particular, I haven't checked in all the changes required for the .NET 4.0 security model), but it is now possible to build assemblies with ikvmc that target and reference .NET 4.0 while running ikvmc on the .NET 2.0 runtime.

C:\j>ikvmc test.class -nostdlib -lib:\windows\microsoft.net\framework\v4.0.30319 -r:mscorlib.dll
Note IKVMC0001: found main method in class "test"
Note IKVMC0002: output file is "test.exe"

C:\j>test
Hello World, running on CLR 4.0.30319.1


Note that (like the C# compiler) you can also reference .NET 4.0 assemblies while targetting .NET 2.0, but when you run the resulting assembly on .NET 2.0 and it tries to load the .NET 4.0 assembly that will fail with a BadImageFormatException.

The algorithm that ikvmc uses to load assemblies now resembles what csc uses and does not involve the CLR anymore. The same switches are used (-nostdlib, -lib and -reference), but there are some subtle differences. The most important being that ikvmc's -nostdlib also removes the current CLR runtime directory from the search path and that the -reference option (like it always has) has a runtime consequence (because it affects class loader delegation) and the assemblies that aren't explicitly required by the code being compiled will be silently loaded from the library search path (which is: current directory, CLR directory (except if -nostdlib is specified), -lib:<dir> directories, LIB environment directories).

Breaking Change

The above mentioned changes to assembly loading by ikvmc result in some (potential) breaking changes for build scripts. In particular, the -reference option could previously be used with a partial name (which would be resolved by the CLR with the Assembly.LoadWithPartialName() method), but this is no longer supported (to ease transitioning you can still specify the simple name of the assembly and the ikvmc assembly resolver will append ".dll" to it, but it will issue a warning about this.)

Changes:

  • Started implementing the various required changes for the .NET 4.0 security model. This is not finished yet, so running on .NET 4.0 with this snapshot is not yet supported.
  • .NET 4.0 fix: When class GC is enabled, don't intrinsify ThreadLocal.
  • .NET 4.0 support: When class GC is enabled, throw a VerifyError when custom attributes as used that aren't allowed in RunAndCollect assemblies.
  • Added parameter validation to ikvmc's -version option (bug #2987144).
  • Added System.Core target to build a tiny custom version of System.Core.dll that contains only System.Runtime.CompilerServices.ExtensionAttribute and will allow us to build on .NET 2.0 without having to figure out where System.Core.dll lives (or without it even being present).
  • Removed lib/security/local_policy.jar from vfs.zip (because, by default, OpenJDK builds the restricted version) and instead make a vfs alias for it that points to the unrestricted US_export_policy.jar.
  • Changed ikvm.runtime.Startup.setProperties() to take an IDictionary instead of Hashtable. This allows a Dictionary<string, string> to be passed in now and avoids future problems if/when we want to target Silverlight (which doesn't have System.Collections.Hashtable).
  • Rewrote assembly loading for ikvmc and ikvmstub (and unified it). It now no longer depends on the runtime to do assembly name to path resolution and behaves more csc like.
  • Added -nostdlib and -lib options to ikvmc and ikvmstub.
  • IKVM.Reflection: Fixed stack height updating for jmp instruction.
  • IKVM.Reflection: Don't crash when a DllImportAttribute doesn't have an ImportScope (which can happen for C++ code).
  • IKVM.Reflection: Version parts should be treated as unsigned.
  • IKVM.Reflection: Don't loop infinitely when field RVA lies outside of the file.
  • IKVM.Reflection: Don't try to return a MethodBody if the method isn't in IL.
  • IKVM.Reflection: Implemented ModuleRef ResolutionScope for TypeRef.
  • IKVM.Reflection: Fixed type name parsing bug (thanks to Jb Evain for reporting this). Generic type parameter type names can be without assembly name and then need to be resolved in context.
  • IKVM.Reflection: Added workaround for broken compiler(s) that add terminating NUL to type names in custom attribute data.
  • IKVM.Reflection: Added support for custom modifiers in generic type instantions (in signatures).
  • IKVM.Reflection: Having PinvokeImpl set doesn't necessarily imply having an ImplMap record (for mixed mode assemblies).
  • IKVM.Reflection: Made __GetDataFromRVA more general by taking an offset and a length (to be able to reuse the byte array) and this also removes the need for the field type to have a StructLayout.
  • IKVM.Reflection: A Version object that only has Major.Minor set will return -1 for Build and Revision. Handle that case by setting these parts to zero, instead of casting to 65535.
  • IKVM.Reflection: Added support for delay signing (i.e. setting the public key without having the private key).
  • IKVM.Reflection: Dynamic assemblies should also be visible in the universe.
  • IKVM.Reflection: Fixed default assembly resolver to throw/not throw the right exceptions.
  • IKVM.Reflection: Made method/field signature reading lazy. This makes building assemblies with circular dependencies easier.
  • IKVM.Reflection: Fixed method signature handling of custom modifiers (required and optional were mixed up).

Binaries available here: ikvmbin-0.43.3765.zip

Friday, 23 April 2010 09:51:39 (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]