# Friday, 25 January 2013
Fixing a Long Standing Limitation

I finally fixed the limitation that classes dynamically loaded by an assembly class loader can't access the internals of the assembly.

Here's a simple demonstration of the problem. Suppose you have these two classes:

class Other {
  static {
    Test.m();
  }
}

class Test {
  public static void main(String[] args) throws Exception {
    Class.forName("Other");
  }
  static void m() {
    System.out.println("Test.m");
  }
}

Now if you compile Test.class (without Other) into an assembly with a ClassPathAssemblyClassLoader and run this with IKVM.NET 7.2 you'll see something like this:


C:\j>ikvmc Test.class -classloader:ikvm.runtime.ClassPathAssemblyClassLoader
IKVM.NET Compiler version 7.2.4630.6
Copyright (C) 2002-2013 Jeroen Frijters
http://www.ikvm.net/

note IKVMC0001: Found main method in class "Test"
note IKVMC0002: Output file is "Test.exe"

C:\j>Test
Exception in thread "main" java.lang.ExceptionInInitializerError
        at cli.System.Runtime.CompilerServices.RuntimeHelpers._RunClassConstructor(Unknown Source)
        at IKVM.Internal.TypeWrapper.RunClassInit(Unknown Source)
        at IKVM.NativeCode.java.lang.Class.forName0(Unknown Source)
        at java.lang.Class.forName(Class.java:287)
        at Test.main(Test.java:9)
Caused by: cli.System.MethodAccessException: Test.m()
        at Other.<clinit>(Test.java)

The call from Other to Test fails with a MethodAccessException, because the dynamic assembly does not have access to the internal members of the Test.exe assembly.

Long ago I considered fixing this by adding an InternalsVisibleToAttribute to all statically compiled assemblies that allows the runtime generated dynamic assembly access to its internals, but I dismissed this because it would mean that untrusted code could abuse this same assembly identity to access the internals of any ikvmc compiled assemblies.

Forging a StrongNameKeyPair

Yesterday I realized that I could use InternalsVisibleToAttribute without opening a security hole. When the IKVM runtime is running as fully trusted code, it can forge a StrongNameKeyPair to attach to the dynamic assemblies it generates and thereby gain access to the statically compiled assemblies, without giving untrusted code the same access.

The only downside to this approach is that it relies on an implementation detail of the CLR (and Mono). I try to stay away from depending on implementation details, but in this case the gain far outways any risk.

Using It From C#

It also works for your C# assemblies. By adding a custom attribute, you can now enable dynamically loaded Java classes access to your assembly internals.

Here's a C# example:

using System;
using System.Runtime.CompilerServices;
using java.lang;
using java.lang.reflect;

[assembly: InternalsVisibleTo("DemoApp-ikvm-runtime-injected, PublicKey=00240000048000009400000006020000002400005253413100040000010001009D674F3D63B8D7A4C428BD7388341B025C71AA61C6224CD53A12C21330A3159D300051FE2EED154FE30D70673A079E4529D0FD78113DCA771DA8B0C1EF2F77B73651D55645B0A4294F0AF9BF7078432E13D0F46F951D712C2FCF02EB15552C0FE7817FC0AED58E0984F86661BF64D882F29B619899DD264041E7D4992548EB9E")]

interface IFoo {
  Program Instance { get; }
}

class Program : InvocationHandler {
  static void Main() {
    Class c = typeof(Program);
    var cl = c.getClassLoader();
    var interfaces = new Class[] { typeof(IFoo) };
    var handler = new Program();
    var proxy = (IFoo)Proxy.newProxyInstance(cl, interfaces, handler);
    Console.WriteLine(proxy.Instance);
  }
  public object invoke(object obj, Method m, object[] objarr) {
    return this;
  }
}

Here we create a Proxy for the non-public interface IFoo. This is allowed because of the InternalsVisibleToAttribute that gives access to an assembly named DemoApp-ikvm-runtime-injected with the specified public key. The name of the assembly must be the name of the current assembly (in this example "DemoApp") with "-ikvm-runtime-injected" appended. The public key is always the same. The corresponding private key does not exist.

Development Snapshot

Please note that this is a development snapshot, not a release or release candidate. So consider it untested.

Changes:

  • Use InternalsVisibleToAttribute to allow the runtime to dynamically inject classes into statically compiled assemblies.
  • Stop generating proxy helpers for non-public interfaces.
  • Added support for RadialGradientPaint in Graphics.setPaint().

Binaries available here: ikvmbin-7.3.4772.zip

Friday, 25 January 2013 07:51:20 (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
# Wednesday, 16 January 2013
New Development Snapshot

The recent Windows RT jailbreak enabled me to run IKVM on my Surface RT. Out of curiousity I decided to run a part of the test suite. Only three tests failed, one because it relies on specific GC behavior and two because they use JVM.DLL. Previously, IKVM's JVM.DLL assemblies were created with ilasm, because that was the easiest way to create unmanaged exports at the time. However, ilasm doesn't seem to support ARM, so I added this support to IKVM.Reflection and wrote a simple tool to generate unmanaged export assemblies. Of course, supporting unmanaged exports on Windows RT in IKVM.Reflection is not very useful, but it was an interesting exercise to learn a little bit about the ARM instruction set.

I also did some more useful work. I finally got around to changing how ikvmc handles assembly references. It now works like the C# compiler and uses the IKVM.Reflection support for missing assemblies that I added for mcs. This means that it no longer automatically loads assemblies (apart from the IKVM runtime and class library assemblies) and you need to add explicit references for indirectly used assemblies as well. The downside is that this has the potential to break some builds, but the upside is that the compilation process is now more predictable and only loads the actually required assemblies, like a "real" compiler, instead of the System.Reflection heritage that required loading even unused dependencies.

Another change is that ikvmstub jars are now officially deprecated from being used with ikvmc (it will still work for a while, but a warning message is issued).

Finally, it is now illegal to explicitly reference a secondary assembly in a shared class loader group. Previously this caused a warning message, but now this is an error. You need to reference the primary assembly.

Changes:

  • Deduplicate ikvmc messages based on all parameter values, not just the first one.
  • Allow ikvmc messages to be suppressed based on any number of parameter values.
  • Fixed ikvmc to write fully specific -nowarn options to suppress file.
  • Fixed ikvmc to handle missing types.
  • Added ikvmc support for missing assemblies.
  • Officially deprecated using stubs with ikvmc.
  • Bug fix. Don't add duplicate methods to attribute annotation interfaces. The primary cause of this was attributes with virtual properties where we would add the base class property as well as the derived class overridden property.
  • Changed build process to replace ilasm usage to generate JVM.DLL with a custom tool.
  • Bug fix. Local variable analysis for finally blocks was incorrect. Fixes bug #3600788.
  • Changed ikvmc to give an error message (instead of a warning) when referencing a secondary assembly from a shared class loader group).
  • Made ikvmc EditorBrowsableAttribute construction fully symbolic, to avoid having to load System.dll.
  • Disabled automatic assembly loading for ikvmc.
  • Suppress ikvmc warnings after an error has occurred (to avoid obscuring the fact that compilation failed).
  • IKVM.Reflection: Added UniverseOptions.ResolveMissingMembers and deprecated EnableMissingMemberResolution().
  • IKVM.Reflection: Added Universe.ResolvedMissingMember event.
  • IKVM.Reflection: Fixed importing of CLR types with funny names (where we'd previously run into bugs in CLR's Type.Name and Type.Namespace).
  • IKVM.Reflection: Restructured relocation writing to pack all relocation in a page in the same block, as WoA apparently requires this.
  • IKVM.Reflection: Implemented ARM startup stub.
  • IKVM.Reflection: Implemented ARM unmanaged exports.

Binaries available here: ikvmbin-7.3.4764.zip

Wednesday, 16 January 2013 12:24:57 (W. Europe Standard Time, UTC+01:00)  #    Comments [1]
# Tuesday, 15 January 2013
IKVM.NET 7.2 Update 1 Release Candidate 0

An updated release with a couple of bug fixes.

Changes (relative to 7.2):

  • Bug fix. Don't deadlock AppDomain.ProcessExit event handler when the event gets called from another thread than the one initiating exit.
  • Bug fix. Static compiler should not use proxy stubs to implement non-public interfaces in another assembly.
  • Bug fix. Don't add duplicate methods to attribute annotation interfaces.
  • Bug fix. Local variable analysis for finally blocks was incorrect. Fixes bug #3600788.

Binaries available here: ikvmbin-7.2.4630.6.zip

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

Tuesday, 15 January 2013 11:47:09 (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
# Sunday, 06 January 2013
New Development Snapshot

I've been busy with other stuff, but I did manage to fix a couple of bugs and add a new feature. So a new development snapshot.

Changes:

  • .NET resources in non-Java assemblies are now exposed as Java resources.
  • Added IKVM.Attributes.JavaResourceAttribute to publish .NET resource to Java under a different name.
  • Bug fix. Don't deadlock AppDomain.ProcessExit event handler when the event gets called from another thread than the one initiating exit.
  • Minor optimization. Only register the AppDomain.ProcessExit event handler when necessary.
  • Bug fix. Private methods declared in map.xml should not be made virtual.
  • Support "attributes" attribute on method tag in map.xml for methods declared in remapped types.
  • Recognize methods in remapped types with the "__<" name prefix as HideFromJava.
  • Bug fix. Static compiler should not use proxy stubs to implement non-public interfaces in another assembly.
  • IKVM.Reflection: Implemented __ContainsMissingType for function pointer types.
  • IKVM.Reflection: Changed __ContainsMissingType to take custom modifiers into account.
  • IKVM.Reflection: Added caching for __ContainsMissingType property to simplify the prevention of infinite recursion while evaluating generic parameter constraints.

Binaries available here: ikvmbin-7.3.4754.zip

Sunday, 06 January 2013 09:51:23 (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
# Friday, 28 December 2012
Raspberry Pi

I got a Raspberry Pi for my birthday.

pi@raspberrypi ~ $ sudo apt-get install ikvm
pi@raspberrypi ~ $ ikvmc -out:javac.exe -r:/usr/lib/ikvm/IKVM.OpenJDK.Tools.dll -main:com.sun.tools.javac.Main
pi@raspberrypi ~ $ vi Hello.java
pi@raspberrypi ~ $ mono javac.exe Hello.java
pi@raspberrypi ~ $ ikvm Hello
Hello World

Amazing...

Friday, 28 December 2012 21:19:04 (W. Europe Standard Time, UTC+01:00)  #    Comments [1]
# Sunday, 16 December 2012
A Hack To Make CLR's DEVPATH Suck Less

The CLR's DEVPATH feature has always been broken and its brokeness varied over the years, but for my purposes it was a very useful feature. However with .NET .4.5 Microsoft decided to up the ante. If you have configured your .NET 4.5 runtime as a "developer installation", ngen will fail to generate native images for framework assemblies. This means that after Windows Update services mscorlib.dll, no native images will be used anymore.

Obviously you can work around this by editing the machine.config and re-running ngen, but that is a bit of a pain so decided to hack together a workaround.

The basic idea is to have a DLL that gets injected into (nearly) every process and patches mscoree.dll to make CreateConfigStream read developer-machine.config instead of machine.config if the DEVPATH environment variable is set.

The source and binaries are available here. Like the Microsoft DEVPATH code, this is untested so there is no warranty and use at your own risk. Bug reports are welcome of course.

There is no installer and there are no installation instructions, because frankly, if you don't know how to install it you probably shouldn't be doing so anyway..

The overhead is fairly low. If you don't have DEVPATH set the DLL will immediately unload again. The file size is only 3KB and in memory it will only use a single 4KB page.

Sunday, 16 December 2012 11:47:50 (W. Europe Standard Time, UTC+01:00)  #    Comments [3]
# Wednesday, 12 December 2012
New Development Snapshot

Time for another development snapshot.

Changes:

  • Do the "no serialization" check before calling Serialization.AddAutomagicSerialization() to avoid triggering the class initializer (which will try to load SerializableAttribute, which is not available everywhere).
  • Removed more ConstructorBuilder usage to fix regression (constructor custom attributes specified map.xml were not applied).
  • Construct the System assembly name from the mscorlib name to support other runtimes.
  • Removed dummy constructor from __Helper class.
  • Removed remaining ConstructorBuilder usages.
  • Removed unnecessary MethodBuilder casts.
  • Removed permanent app.config files and changed build process to only generate them when doing a .NET 2.0 build.
  • Bug fix. Transient field modifier should also be retained on literal fields.
  • Bug fix. Field.getModifiers() should only return the relevant modifiers.
  • Removed some O(n^2) operations to improve handling of class files with a large number of fields.
  • Bug fix. Set AddressOfRawData in IMAGE_DEBUG_DIRECTORY.
  • Bug fix. Class.forName("") should not throw System.ArgumentException.
  • Bug fix. Off-by-one error in local ref index reusing. Fix for bug #3575555.
  • Bug fix. Don't try to inject DynamicMethod in array types (applies to array.clone() method for MethodHandles).
  • Bug fix. Abstract generic methods are not supported. Fix for #3579785.
  • Bug fix. Interface mappings can be "incomplete". Fix for bug #3581564.
  • Added (optional) support for building without System.Core.dll dependency.
  • Bug fix. The local variable state at the end of an exception block (if the last instruction is a local variable store) needs to be merged into the exception handler state.
  • Changed FileNotFoundException message in the case of an access denied to match the JDK message. JRuby depends on this.
  • Renamed Adler32 "checksum" field to "adler", because JRuby depends on this.
  • Bug fix. The static compiler cannot use a different way to encode erased array types than the runtime compiler (because otherwise the runtime can't override statically compiled methods).
  • Fixed native library build to explicitly pass /MACHINE option to linker to avoid warning.
  • Implemented StandardGlyphVector.performDefaultLayout() and setGlyphPosition(int, Point2D).
  • Added missing SecuritySafeCritical attribute.
  • Changed build infrastructure to support targetting .NET 4.0 on systems where 4.5 is installed.
  • IKVM.Reflection: Bug fix. Ignore unknown metadata streams instead of throwing a BadImageFormatException. The CLR ignores these streams as well and some obfuscators add them.
  • IKVM.Reflection: Added TypeInfo (from .NET 4.5).
  • IKVM.Reflection: Implemented caching for TypeDefImpl.IsGenericTypeDefinition property.
  • IKVM.Reflection: Added new .NET 4.5 TypeBuilder.DefineNestedType() overload.
  • IKVM.Reflection: Added new .NET 4.5 API TypeBuilder.CreateTypeInfo().
  • IKVM.Reflection: Added new .NET 4.0 overload of TypeBuilder.DefineProperty().
  • IKVM.Reflection: Added new .NET 4.5 property AssemblyName.CultureName.
  • IKVM.Reflection: When an assembly name has a duplicate key, throw FileLoadException like .NET 4.x does instead of COMException like .NET 2.0 does.
  • IKVM.Reflection: Added new .NET 4.5 property MethodBase.MethodImplementationFlags.
  • IKVM.Reflection: Added new .NET 4.5 properties CustomAttributeNamedArgument.IsField and CustomAttributeNamedArgument.MemberName.
  • IKVM.Reflection: Added new .NET 4.5 properties EventInfo.AddMethod, EventInfo.RaiseMethod and EventInfo.RemoveMethod.
  • IKVM.Reflection: Added new .NET 4.5 property ParameterInfo.HasDefaultValue.
  • IKVM.Reflection: Added new .NET 4.5 properties PropertyInfo.GetMethod and PropertyInfo.SetMethod.
  • IKVM.Reflection: Added Universe.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, IEnumerable) that corresponds to new .NET 4.5 API AssemblyBuilder.DefineDynamicAssembly(...).
  • IKVM.Reflection: Added new .NET 4.5 method EnumBuilder.CreateTypeInfo().
  • IKVM.Reflection: Added new .NET 4.0 method GetCustomAttributesData() to Assembly, MemberInfo, Module and ParameterInfo.
  • IKVM.Reflection: Added new .NET 4.5 property CustomAttributes to Assembly, MemberInfo, Module and ParameterInfo.
  • IKVM.Reflection: Added new .NET 4.5 property Type.GenericTypeArguments.
  • IKVM.Reflection: Added new .NET 4.0 methods Type.GetEnumNames(), Type.GetEnumName() and Type.IsEnumDefined().
  • IKVM.Reflection: Added new .NET 4.5 properties Assembly.ExportedTypes and Assembly.DefinedTypes.
  • IKVM.Reflection: Added new .NET 4.5 property Assembly.Modules.
  • IKVM.Reflection: Moved local var signature token creation to a more logical location.
  • IKVM.Reflection: Added new .NET 4.5 methods ConstructorBuilder.SetMethodBody() and MethodBuilder.SetMethodBody(). Note that the implementation is currently completely untested.
  • IKVM.Reflection: Added (old) method MethodBuilder.CreateMethodBody() that is now trivial to implement.
  • IKVM.Reflection: Added new .NET 4.0 property Assembly.IsDynamic.
  • IKVM.Reflection: Added (old) API Module.GetSignerCertificate().
  • IKVM.Reflection: Bug fix. While reading the Cecil source I realized that array bounds are signed.
  • IKVM.Reflection: Stop relying on System.Reflection.AssemblyName to compute public key token from public key.
  • IKVM.Reflection: Small optimization to table record allocation. Thanks to Marek for the pointer.
  • IKVM.Reflection: Implemented LocalVariableInfo.ToString().
  • IKVM.Reflection: Bug fix. ModuleReader.ResolveMember() should support types. Thanks to Jb Evain for finding this.
  • IKVM.Reflection: Bug fix. LocalBuilder should extend LocalVariableInfo.
  • IKVM.Reflection: Made AssemblyBuilder.__AssemblyFlags a read/write property and marked __SetAssemblyFlags() obsolete.
  • IKVM.Reflection: Bug fix. Changed AssemblyName.ProcessorArchitecture to match (weird) .NET behavior. When reading the property it returns the architecture of the PE file, not the field from the AssemblyDef record.
  • IKVM.Reflection: Throw InvalidOperationException when MethodBuilder.DefineGenericParameters() is called a second time.
  • IKVM.Reflection: Added UniverseOptions.DontProvideAutomaticDefaultConstructor to disable the "helpful" creation of a default constructor.
  • IKVM.Reflection: Fixed ExportedType resolver to support types defined in another module in this assembly.
  • IKVM.Reflection: Added the Assembly.ModuleResolve event.
  • IKVM.Reflection: If missing member resolution is enabled, automatically create missing modules as needed.
  • IKVM.Reflection: Simplified LazyForwardType resolution to reuse ResolveExportedType() and thus always set the metadata token for forwarded missing types.
  • IKVM.Reflection: Added Type.__IsTypeForwarder property to let mcs distinguish between "normal" missing types and forwarded missing types.
  • IKVM.Reflection: When calling MethodBuilder.DefineParameter() multiple times for the same parameter, we would (sometimes) not store the ParameterBuilder and this would cause the resulting PE file to be corrupt. Now we store the duplicate Param records like SRE does.
  • IKVM.Reflection: Added UniverseOptions.MetadataOnly.
  • IKVM.Reflection: Made user string heap loading lazy.
  • IKVM.Reflection: Bug fix. If SizeOfOptionalHeader is greater than the number of bytes we read from the optional header, we should skip the additional bytes. If it is less, the image is invalid. Thanks to Jb Evain.

Binaries available here: ikvmbin-7.3.4728.zip

Wednesday, 12 December 2012 10:25:12 (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
# Monday, 10 December 2012
IKVM.NET 7.2 Released

I've released IKVM.NET 7.2 to SourceForge and NuGet. The binaries are identical to the ones in release candidate 5.

Release Notes

This document lists the improvements, known issues and incompatibilities.

What's New (relative to IKVM.NET 7.1):

  • Integrated OpenJDK 7 u6 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.
  • Add support for running with headless awt toolkit.
  • 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.
  • Added (optional) support for building without System.Core.dll dependency.
  • Disabled AppDomain.ProcessExit hook to run shutdown hooks when running on Mono to workaround https://bugzilla.xamarin.com/show_bug.cgi?id=5650.
  • Several verifier fixes.
  • Several metadata reflection fixes.
  • Fixed two try/finally block code gen bugs.
  • Various other minor fixes.
  • IKVM.Reflection: Many minor bug fixes and improvements.
  • IKVM.Reflection: Added most new .NET 4.5 APIs.
  • IKVM.Reflection: Added experimental support for generating Windows Runtime (.winmd) assemblies.
  • IKVM.Reflection: Added missing DefineResource() APIs to ModuleBuilder and AssemblyBuilder.
  • IKVM.Reflection: Added co-/contra-variance support to Type.IsAssignableFrom().
  • IKVM.Reflection: Added support for using the .NETCore v4.5 aka Metro profile mscorlib.dll.
  • IKVM.Reflection: Added UniverseOptions.DisablePseudoCustomAttributeRetrieval to disable returning pseudo custom attributes.
  • IKVM.Reflection: Bug fix. Ignore unknown metadata streams.
  • IKVM.Reflection: Bug fix. Set AddressOfRawData in IMAGE_DEBUG_DIRECTORY.

Runtime

  • Code unloading (aka class GC) is not supported.
  • In Java static initializers can deadlock, on .NET some threads can see uninitialized state in cases where deadlock would occur on the JVM.
  • JNI
     
    • Only supported in the default AppDomain.
    • Only the JNICALL calling convention is supported! (On Windows, HotSpot appears to also support the cdecl calling convention).
    • Cannot call string contructors on already existing string instances
    • A few limitations in Invocation API support
       
      • The Invocation API is only supported when running on .NET.
      • JNI_CreateJavaVM: init options "-verbose[:class|:gc|:jni]", "vfprintf", "exit" and "abort" are not implemented. The JDK 1.1 version of JavaVMInitArgs isn't supported.
      • JNI_GetDefaultJavaVMInitArgs not implemented
      • JNI_GetCreatedJavaVMs only returns the JavaVM if the VM was started through JNI or a JNI call that retrieves the JavaVM has already occurred.
      • DestroyJVM is only partially implemented (it waits until there are no more non-daemon Java threads and then returns JNI_ERR).
      • DetachCurrentThread doesn't release monitors held by the thread.
    • Native libraries are never unloaded (because code unloading is not supported).
  • The JVM allows any reference type to be passed where an interface reference is expected (and to store any reference type in an interface reference type field), on IKVM this results in an IncompatibleClassChangeError.
  • monitorenter / monitorexit cannot be used on unitialized this reference.
  • Floating point is not fully spec compliant.
  • A method returning a boolean that returns an integer other than 0 or 1 behaves differently (this also applies to byte/char/short and for method parameters).
  • Synchronized blocks are not async exception safe.
  • Ghost arrays don't throw ArrayStoreException when you store an object that doesn't implement the ghost interface.
  • Class loading is more eager than on the reference VM.
  • Interface implementation methods are never really final (interface can be reimplemented by .NET subclasses).
  • JSR-133 finalization spec change is not fully implemented. The JSR-133 changes dictate that an object should not be finalized unless the Object constructor has run successfully, but this isn't implemented.
  • Strict class-file checking is not implemented.
  • If a class with a finalizer and static initializer allocates instances of itself in the static initializer and the static initializer subsequently fails, the .NET runtime may abort the application when trying to finalize the objects.

Static Compiler (ikvmc)

  • Some subtle differences with ikvmc compiled code for public members inherited from non-public base classes (so called "access stubs"). Because the access stub lives in a derived class, when accessing a member in a base class, the derived cctor will be run whereas java (and ikvm) only runs the base cctor.
  • Try blocks around base class ctor invocation result in unverifiable code (no known compilers produce this type of code).
  • Try/catch blocks before base class ctor invocation result in unverifiable code (this actually happens with the Eclipse compiler when you pass a class literal to the base class ctor and compile with -target 1.4).
  • Only code compiled together during a single compilation fully obeys the JLS binary compatibility rules.

Class Library

Most class library code is based on OpenJDK 7u6 build 24. Below is a list of divergences and IKVM.NET specific implementation notes.

com.sun.security.auth.module        Only implemented on Windows.
java.applet Not implemented.
java.awt Partial System.Windows.Forms based back-end. Not supported.
java.io.Console Not implemented.
java.lang.instrument Not implemented.
java.lang.management Limited implementation.
java.net SCTP and SDP not implemented.
java.net.ProxySelector Getting the default system proxy for a URL is not implemented.
java.nio.file Most optional features (e.g. ACLs) are not implemented.
java.text.Bidi Not supported.
java.util.zip Partially based on GNU Classpath implementation.
javax.crypto ECC is not implemented.
javax.imageio.plugins.jpeg Partial implementation. JPEGs can be read and written and there is limited metadata support.
javax.management Limited implementation.
javax.print There is a Win32 specific printing implementation. Not supported.
javax.script ECMAScript implementation is not included.
javax.smartcardio Not implemented.
javax.sound Not implemented.
javax.swing Not supported.
javax.tools Not supported.
org.ietfs.jgss Not implemented.
sun.jdbc.odbc Implementation based on .NET ODBC managed provider.
sun.net.www.content.audio Audio content handlers not implemented.
sun.net.www.content.image Not supported.

The entire public API is available, so "Not implemented." for javax.smartcardio, for example, means that the API is there but there is no back-end to provide the actual smartcard communication support. "Not supported." means that the code is there and probably works at least somewhat, but that I'm less likely to fix bugs reported in these areas, but patches are welcome, of course.

Specific API notes:

  • java.lang.Thread.stop(Throwable t) doesn't support throwing arbitrary exceptions on other threads (only java.lang.ThreadDeath).
  • java.lang.Thread.holdsLock(Object o) causes a spurious notify on the object (this is allowed by the J2SE 5.0 spec).
  • java.lang.String.intern() strings are never garbage collected.
  • Weak/soft references and reference queues are inefficient and do not fully implement the required semantics.
  • java.lang.ref.SoftReference: Soft references are not guaranteed to be cleared before an OutOfMemoryError is thrown.
  • Threads started outside of Java aren't "visible" (e.g. in ThreadGroup.enumerate()) until they first call Thread.currentThread().
  • java.lang.Thread.getState() returns WAITING or TIMED_WAITING instead of BLOCKING when we're inside Object.wait() and blocking to re-acquire the monitor.
  • java.nio.channel.FileChannel.lock() shared locks are only supported on Windows NT derived operating systems.
  • java.lang.SecurityManager: Deprecated methods not implemented: classDepth(String), inClass(String), classLoaderDepth(), currentLoadedClass(), currentClassLoader(), inClassLoader()

Supported Platforms

This release has been tested on the following CLI implementations / platforms:

CLI Implementation       Architecture      Operating System
.NET 2.0 SP2 x86 Windows 8
.NET 2.0 SP2 x64 Windows 8
.NET 4.5 x86 Windows 8
.NET 4.5 x64 Windows 8
Monday, 10 December 2012 07:51:13 (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
# Thursday, 06 December 2012
IKVM.NET 7.2 Release Candidate 5

Apologies for the ridiculous delay. I've been busy. This is the final release candidate.

Changes (relative to rc 4):

  • Updated version to 7.2.4630.5
  • Bug fix. The static compiler cannot use a different way to encode erased array types than the runtime compiler (because otherwise the runtime can't override statically compiled methods).
  • Added missing SecuritySafeCritical attribute.

Binaries available here: ikvmbin-7.2.4630.5.zip

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

Thursday, 06 December 2012 10:13:45 (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
# Thursday, 01 November 2012
JDK 7 Thread Cloning Vulnerability

This blog entry was originally posted on June 23, 2011, but was deleted as Oracle asked me to take it down while they investigate. After more than a year, the issue still has not been addressed, so I notified Oracle that I wanted to repost the blog entry and received no response. -- Jeroen

I warned on the mailing list when this came up, but apparently was ignored,so maybe a blog post will help.

In one of last year's updates of JDK 6 the cloning vulnerability was fixed in a hackish, but clever and safe way. Now in JDK 7 they try to fix it by overriding Object.clone() with a version that simply throws CloneNotSupportedException. The only problem is, in Java (and .NET too) overriding a method is not a safe way to make the base class method unavailable.

The (still) not so well known ACC_SUPER flag allows you (when it isn't set) to call arbitrary (accessible) methods in your super class hierarchy. So Thread.clone() can be skipped and Object.clone() can be called from any Thread subclass that doesn't have the ACC_SUPER flag set.

Here's an example:

class Clone extends Thread implements Cloneable {
  public Object clone() {
    try { return super.clone(); }
    catch (CloneNotSupportedException _) { throw new Error(); }
  }
}

class Demo {
  public static void main(String[] args) throws Throwable {
    Clone c1 = new Clone() {
      public void run() {
        for (;;) {
        }
      }
    };
    c1.start();
    Thread t = (Thread)c1.clone();
    c1.stop();
    c1.join();
    System.gc();
    t.stop();
  }
}

Note that after you compile this with JDK 6 you'll need to edit the Clone.class to clear the ACC_SUPER flag. Use a hex editor to replace 20 (hex) with 00 or download a copy here.

Now run it:

C:\j>\jdk1.7-b145\bin\java Demo
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006cd5af54, pid=3708, t id=10460
#
# JRE version: 7.0-b145
# Java VM: Java HotSpot(TM) 64-Bit Server VM (21.0-b15 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# V [jvm.dll+0x1caf54]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\j\hs_err_pid3708.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
#

Thursday, 01 November 2012 16:11:20 (W. Europe Standard Time, UTC+01:00)  #    Comments [9]