diff options
author | jfrijters <jfrijters> | 2010-05-27 18:08:58 +0400 |
---|---|---|
committer | jfrijters <jfrijters> | 2010-05-27 18:08:58 +0400 |
commit | 63fac84c10fffd47ab44d3e79da2b2185b476614 (patch) | |
tree | 6b07067f322aa33f68d8256e46fca12778ed4441 | |
parent | d67bc55267dae670d6add79755db8ca78e01781d (diff) |
- Added new public API to unmap exception (ikvm.runtime.Util.unmapException()).
- Moved (parts of) mapping and unmapping to C# side.
-rw-r--r-- | classpath/ikvm/extensions/ExtensionMethods.java | 2 | ||||
-rw-r--r-- | classpath/ikvm/runtime/Util.java | 9 | ||||
-rw-r--r-- | classpath/java/lang/ExceptionHelper.java | 29 | ||||
-rw-r--r-- | openjdk/map.xml | 18 | ||||
-rw-r--r-- | runtime/ExceptionHelper.cs | 40 | ||||
-rw-r--r-- | runtime/common.cs | 19 |
6 files changed, 67 insertions, 50 deletions
diff --git a/classpath/ikvm/extensions/ExtensionMethods.java b/classpath/ikvm/extensions/ExtensionMethods.java index 772e0fdf..eef5b8a7 100644 --- a/classpath/ikvm/extensions/ExtensionMethods.java +++ b/classpath/ikvm/extensions/ExtensionMethods.java @@ -36,7 +36,7 @@ public final class ExtensionMethods { t = ikvm.runtime.Util.mapException(t); t.printStackTrace(); - java.lang.ExceptionHelper.UnmapException(t); + ikvm.runtime.Util.unmapException(t); } @ExtensionAttribute.Annotation diff --git a/classpath/ikvm/runtime/Util.java b/classpath/ikvm/runtime/Util.java index bc41956a..5cee7359 100644 --- a/classpath/ikvm/runtime/Util.java +++ b/classpath/ikvm/runtime/Util.java @@ -41,11 +41,10 @@ public final class Util public static native Type getInstanceTypeFromClass(Class classObject); - //[HideFromJava] - public static Throwable mapException(Throwable x) - { - return ExceptionHelper.MapExceptionFast(x, true); - } + @cli.IKVM.Attributes.HideFromJavaAttribute.Annotation + public static native Throwable mapException(Throwable x); + + public static native Throwable unmapException(Throwable x); public static void throwException(cli.System.Exception x) { diff --git a/classpath/java/lang/ExceptionHelper.java b/classpath/java/lang/ExceptionHelper.java index 8e1e7ae5..42226bb2 100644 --- a/classpath/java/lang/ExceptionHelper.java +++ b/classpath/java/lang/ExceptionHelper.java @@ -282,37 +282,10 @@ public final class ExceptionHelper private static native String SafeGetEnvironmentVariable(String name); // native methods implemented in map.xml - private static native cli.System.Exception getOriginalAndClear(Throwable t); private static native void setOriginal(Throwable t, cli.System.Exception org); private static native boolean needStackTraceInfo(Throwable t); private static native void setStackTraceInfo(Throwable t, cli.System.Diagnostics.StackTrace part1, cli.System.Diagnostics.StackTrace part2); - static void FixateException(cli.System.Exception x) - { - exceptions.put(x, NOT_REMAPPED); - } - - // also used by ikvm.extensions.ExtensionMethods.printStackTrace() - public static Throwable UnmapException(Throwable t) - { - if(!(t instanceof cli.System.Exception)) - { - cli.System.Exception org = getOriginalAndClear(t); - if(org != null) - { - exceptions.put(org, t); - t = org; - } - } - return t; - } - - // used by ikvm.runtime.Util - public static Throwable MapExceptionFast(Throwable t, boolean remap) - { - return MapException(t, null, remap); - } - static Throwable MapException(Throwable t, cli.System.Type handler, boolean remap) { Throwable org = t; @@ -398,7 +371,7 @@ public final class ExceptionHelper static Throwable MapTypeInitializeException(cli.System.TypeInitializationException t, cli.System.Type handler) { boolean wrapped = false; - Throwable r = MapExceptionFast(t.get_InnerException(), true); + Throwable r = ikvm.runtime.Util.mapException(t.get_InnerException()); if(!(r instanceof Error)) { r = new ExceptionInInitializerError(r); diff --git a/openjdk/map.xml b/openjdk/map.xml index a7458bd3..40a916a8 100644 --- a/openjdk/map.xml +++ b/openjdk/map.xml @@ -951,7 +951,7 @@ <body> <ldarg_0 /> <ldarg_1 /> - <call class="java.lang.ExceptionHelper" name="MapExceptionFast" sig="(Ljava.lang.Throwable;Z)Ljava.lang.Throwable;" /> + <call type="IKVM.NativeCode.java.lang.ExceptionHelper" name="MapExceptionFast" sig="(Ljava.lang.Throwable;Z)Ljava.lang.Throwable;" /> <ret /> </body> </method> @@ -975,7 +975,7 @@ </attribute> <body> <ldarg_0 /> - <call class="java.lang.ExceptionHelper" name="UnmapException" sig="(Ljava.lang.Throwable;)Ljava.lang.Throwable;" /> + <call type="IKVM.NativeCode.java.lang.ExceptionHelper" name="UnmapException" sig="(Ljava.lang.Throwable;)Ljava.lang.Throwable;" /> <ret /> </body> </method> @@ -986,7 +986,7 @@ </attribute> <body> <ldarg_0 /> - <call class="java.lang.ExceptionHelper" name="FixateException" sig="(Lcli.System.Exception;)V" /> + <call class="cli.IKVM.NativeCode.java.lang.ExceptionHelper" name="FixateException" sig="(Ljava.lang.Throwable;)V" /> <ldarg_0 /> <ret /> </body> @@ -2008,18 +2008,6 @@ </implements> </class> <class name="java.lang.ExceptionHelper"> - <method name="getOriginalAndClear" sig="(Ljava.lang.Throwable;)Lcli.System.Exception;"> - <body> - <ldarg_0 /> - <castclass_impl class="java.lang.Throwable" /> - <ldfld class="java.lang.Throwable" name="original" sig="Ljava.lang.Throwable;" /> - <ldarg_0 /> - <castclass_impl class="java.lang.Throwable" /> - <ldnull /> - <stfld class="java.lang.Throwable" name="original" sig="Ljava.lang.Throwable;" /> - <ret /> - </body> - </method> <method name="setOriginal" sig="(Ljava.lang.Throwable;Lcli.System.Exception;)V"> <body> <ldarg_0 /> diff --git a/runtime/ExceptionHelper.cs b/runtime/ExceptionHelper.cs index a117f571..e5987920 100644 --- a/runtime/ExceptionHelper.cs +++ b/runtime/ExceptionHelper.cs @@ -1,5 +1,5 @@ /* - Copyright (C) 2002, 2004-2007, 2010 Jeroen Frijters + Copyright (C) 2002-2010 Jeroen Frijters This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -27,6 +27,7 @@ using System.Diagnostics; using IKVM.Attributes; using IKVM.Internal; using IDictionary = System.Collections.IDictionary; +using Interlocked = System.Threading.Interlocked; using ObjectInputStream = java.io.ObjectInputStream; using ObjectOutputStream = java.io.ObjectOutputStream; using StackTraceElement = java.lang.StackTraceElement; @@ -449,5 +450,42 @@ namespace IKVM.NativeCode.java.lang } #endif } + + // this method is *only* for .NET exceptions (i.e. types not derived from java.lang.Throwable) + internal static void FixateException(Exception x) + { +#if !FIRST_PASS + global::java.lang.ExceptionHelper.exceptions.put(x, global::java.lang.ExceptionHelper.NOT_REMAPPED); +#endif + } + + // also used by ikvm.extensions.ExtensionMethods.printStackTrace() + internal static Exception UnmapException(Exception x) + { +#if FIRST_PASS + return null; +#else + if (x is Throwable) + { + Exception org = Interlocked.Exchange(ref ((Throwable)x).original, null); + if (org != null) + { + global::java.lang.ExceptionHelper.exceptions.put(org, x); + x = org; + } + } + return x; +#endif + } + + [HideFromJava] + internal static Exception MapExceptionFast(Exception x, bool remap) + { +#if FIRST_PASS + return null; +#else + return global::java.lang.ExceptionHelper.MapException(x, null, remap); +#endif + } } } diff --git a/runtime/common.cs b/runtime/common.cs index 01815330..5085408a 100644 --- a/runtime/common.cs +++ b/runtime/common.cs @@ -437,5 +437,24 @@ namespace IKVM.NativeCode.ikvm.runtime } return wrapper.TypeAsBaseType; } + + [HideFromJava] + public static Exception mapException(Exception x) + { +#if FIRST_PASS + return null; +#else + return global::IKVM.NativeCode.java.lang.ExceptionHelper.MapExceptionFast(x, true); +#endif + } + + public static Exception unmapException(Exception x) + { +#if FIRST_PASS + return null; +#else + return global::IKVM.NativeCode.java.lang.ExceptionHelper.UnmapException(x); +#endif + } } } |