Moved readObject/writeObject to C# side.

This commit is contained in:
jfrijters 2010-05-27 11:21:23 +00:00
Родитель 1dc4ffa32b
Коммит a4500fdb47
4 изменённых файлов: 41 добавлений и 38 удалений

Просмотреть файл

@ -276,14 +276,12 @@ public final class ExceptionHelper
static native String getClassNameFromType(cli.System.Type type); static native String getClassNameFromType(cli.System.Type type);
static native int GetLineNumber(cli.System.Diagnostics.StackFrame frame); static native int GetLineNumber(cli.System.Diagnostics.StackFrame frame);
static native String GetFileName(cli.System.Diagnostics.StackFrame frame); static native String GetFileName(cli.System.Diagnostics.StackFrame frame);
static native void initThrowable(Object throwable, Object detailMessage, Object cause);
static native Throwable MapExceptionImpl(Throwable t); static native Throwable MapExceptionImpl(Throwable t);
static native cli.System.Type getTypeFromObject(Object o); static native cli.System.Type getTypeFromObject(Object o);
private static native String SafeGetEnvironmentVariable(String name); private static native String SafeGetEnvironmentVariable(String name);
// native methods implemented in map.xml // native methods implemented in map.xml
private static native Throwable getCauseForSerialization(Throwable t);
private static native cli.System.Exception getOriginalAndClear(Throwable t); private static native cli.System.Exception getOriginalAndClear(Throwable t);
private static native void setOriginal(Throwable t, cli.System.Exception org); private static native void setOriginal(Throwable t, cli.System.Exception org);
private static native boolean needStackTraceInfo(Throwable t); private static native boolean needStackTraceInfo(Throwable t);
@ -594,31 +592,6 @@ public final class ExceptionHelper
return type.IsInstanceOfType(t); return type.IsInstanceOfType(t);
} }
static void writeObject(Throwable t, ObjectOutputStream s) throws IOException
{
synchronized (t)
{
ObjectOutputStream.PutField fields = s.putFields();
fields.put("detailMessage", t.getMessage());
Throwable cause = t.getCause();
if (cause == null && !(t instanceof cli.System.Exception))
{
cause = getCauseForSerialization(t);
}
fields.put("cause", cause);
fields.put("stackTrace", t.getStackTrace());
s.writeFields();
}
}
static void readObject(Throwable t, ObjectInputStream s) throws IOException, ClassNotFoundException
{
ObjectInputStream.GetField fields = s.readFields();
initThrowable(t, fields.get("detailMessage", null), fields.get("cause", null));
StackTraceElement[] stackTrace = (StackTraceElement[])fields.get("stackTrace", null);
t.setStackTrace(stackTrace == null ? new StackTraceElement[0] : stackTrace);
}
static Throwable MapTypeInitializeException(cli.System.TypeInitializationException t, cli.System.Type handler) static Throwable MapTypeInitializeException(cli.System.TypeInitializationException t, cli.System.Type handler)
{ {
boolean wrapped = false; boolean wrapped = false;

Просмотреть файл

@ -997,7 +997,7 @@
<body> <body>
<ldarg_0 /> <ldarg_0 />
<ldarg_1 /> <ldarg_1 />
<call class="java.lang.ExceptionHelper" name="readObject" sig="(Ljava.lang.Throwable;Ljava.io.ObjectInputStream;)V" /> <call type="IKVM.NativeCode.java.lang.ExceptionHelper" name="readObject" sig="(Ljava.lang.Throwable;Ljava.io.ObjectInputStream;)V" />
<ret /> <ret />
</body> </body>
</method> </method>
@ -1006,7 +1006,7 @@
<body> <body>
<ldarg_0 /> <ldarg_0 />
<ldarg_1 /> <ldarg_1 />
<call class="java.lang.ExceptionHelper" name="writeObject" sig="(Ljava.lang.Throwable;Ljava.io.ObjectOutputStream;)V" /> <call type="IKVM.NativeCode.java.lang.ExceptionHelper" name="writeObject" sig="(Ljava.lang.Throwable;Ljava.io.ObjectOutputStream;)V" />
<ret /> <ret />
</body> </body>
</method> </method>
@ -2008,14 +2008,6 @@
</implements> </implements>
</class> </class>
<class name="java.lang.ExceptionHelper"> <class name="java.lang.ExceptionHelper">
<method name="getCauseForSerialization" sig="(Ljava.lang.Throwable;)Ljava.lang.Throwable;">
<body>
<ldarg_0 />
<castclass_impl class="java.lang.Throwable" />
<ldfld class="java.lang.Throwable" name="cause" sig="Ljava.lang.Throwable;" />
<ret />
</body>
</method>
<method name="getOriginalAndClear" sig="(Ljava.lang.Throwable;)Lcli.System.Exception;"> <method name="getOriginalAndClear" sig="(Ljava.lang.Throwable;)Lcli.System.Exception;">
<body> <body>
<ldarg_0 /> <ldarg_0 />

Просмотреть файл

@ -27,6 +27,8 @@ namespace java
namespace io namespace io
{ {
public class File { } public class File { }
public class ObjectInputStream { }
public class ObjectOutputStream { }
public class ObjectStreamField { } public class ObjectStreamField { }
} }
@ -35,6 +37,7 @@ namespace java
public class Class { } public class Class { }
public class ClassLoader { } public class ClassLoader { }
public class SecurityManager { } public class SecurityManager { }
public class StackTraceElement { }
namespace reflect namespace reflect
{ {

Просмотреть файл

@ -26,6 +26,12 @@ using System.Reflection;
using System.Diagnostics; using System.Diagnostics;
using IKVM.Attributes; using IKVM.Attributes;
using IKVM.Internal; using IKVM.Internal;
using ObjectInputStream = java.io.ObjectInputStream;
using ObjectOutputStream = java.io.ObjectOutputStream;
using StackTraceElement = java.lang.StackTraceElement;
#if !FIRST_PASS
using Throwable = java.lang.Throwable;
#endif
namespace IKVM.NativeCode.java.lang namespace IKVM.NativeCode.java.lang
{ {
@ -110,7 +116,7 @@ namespace IKVM.NativeCode.java.lang
return type.FullName; return type.FullName;
} }
public static void initThrowable(object throwable, object detailMessage, object cause) private static void initThrowable(object throwable, object detailMessage, object cause)
{ {
#if !FIRST_PASS #if !FIRST_PASS
if(cause == throwable) if(cause == throwable)
@ -172,6 +178,35 @@ namespace IKVM.NativeCode.java.lang
new global::java.io.ObjectStreamField("cause", typeof(global::java.lang.Throwable)), new global::java.io.ObjectStreamField("cause", typeof(global::java.lang.Throwable)),
new global::java.io.ObjectStreamField("stackTrace", typeof(global::java.lang.StackTraceElement[])) new global::java.io.ObjectStreamField("stackTrace", typeof(global::java.lang.StackTraceElement[]))
}; };
#endif
}
internal static void writeObject(Exception x, ObjectOutputStream s)
{
#if !FIRST_PASS
lock (x)
{
ObjectOutputStream.PutField fields = s.putFields();
fields.put("detailMessage", Throwable.instancehelper_getMessage(x));
Exception cause = Throwable.instancehelper_getCause(x);
if (cause == null && x is Throwable)
{
cause = ((Throwable)x).cause;
}
fields.put("cause", cause);
fields.put("stackTrace", Throwable.instancehelper_getStackTrace(x));
s.writeFields();
}
#endif
}
internal static void readObject(Exception x, ObjectInputStream s)
{
#if !FIRST_PASS
ObjectInputStream.GetField fields = s.readFields();
initThrowable(x, fields.get("detailMessage", null), fields.get("cause", null));
StackTraceElement[] stackTrace = (StackTraceElement[])fields.get("stackTrace", null);
Throwable.instancehelper_setStackTrace(x, stackTrace == null ? new StackTraceElement[0] : stackTrace);
#endif #endif
} }
} }