Project

Profile

Help

Bug #1593 ยป EmailCorrespondenceWithJeroenFrijters.txt

O'Neil Delpratt, 2012-08-03 08:25

 

Hi Jeroen,

Thanks, the generated byte code now loads.

On 02/08/2012 15:40, Jeroen Frijters wrote:
> It looks like a "simple" class loader issue. It just can't find the base class. Where is com.saxonica.bytecode.GeneratedCode supposed to come from?
The base class exists as an abstract class in the product

> If it is in a statically (ikvmc) compiled assembly then it looks like that assembly is not referenced from your main (test) executable. I don't know if Visual Studio 2010 does anything different here from 2008, but it is possible (I'm currently traveling and don't have access to Visual Studio 2010).
Not Sure. but it would be interesting to see what the difference is.

If you don't actually use an assembly the C# compiler will not include a reference to an assembly (even though it is referenced in the project settings), but I believe this was true of 2008 as well. The workaround for that is to do something like this in your test driver main executable:

> GC.KeepAlive(typeof(com.saxonica.bytecode.GeneratedCode));
This also worked.

> You could also explicitly pass the class loader of com.saxonica.bytecode.GeneratedCode as the parent class loader of the class loader you construct to load the generated class. That is a more general solution as it does not require the system class loader (i.e. the main executable) to be able to reference the base class.

Managed to get the class loader from the parent class.


Kind regards,
O'Neil




Hi O'Neil,

It looks like a "simple" class loader issue. It just can't find the base class. Where is com.saxonica.bytecode.GeneratedCode supposed to come from?

If it is in a statically (ikvmc) compiled assembly then it looks like that assembly is not referenced from your main (test) executable. I don't know if Visual Studio 2010 does anything different here from 2008, but it is possible (I'm currently traveling and don't have access to Visual Studio 2010).

If you don't actually use an assembly the C# compiler will not include a reference to an assembly (even though it is referenced in the project settings), but I believe this was true of 2008 as well. The workaround for that is to do something like this in your test driver main executable:

GC.KeepAlive(typeof(com.saxonica.bytecode.GeneratedCode));

You could also explicitly pass the class loader of com.saxonica.bytecode.GeneratedCode as the parent class loader of the class loader you construct to load the generated class. That is a more general solution as it does not require the system class loader (i.e. the main executable) to be able to reference the base class.

Regards,
Jeroen

________________________________________
From: Dr O'Neil Delpratt [oneil@saxonica.com]
Sent: Thursday, August 02, 2012 1:26 PM
To: Jeroen Frijters
Cc: Michael Kay
Subject: Re: NoClassDefFoundError thrown

Hi Jeroen,

Thanks for all your help. I managed to successfully get the IKVM to
build with the debug WriteLine statement.

Using the statement 'global::System.Console.WriteLine(x);' we get the
the trace of where the exception is thrown from in IKVM, which is given
below. What we are doing in Saxon is generating bytecode using ASM on
the fly, which works in Java and .NET 2.XX but not in .NET 4.XX. Any
ideas? I have attached a generated bytecode which was used to solve a
IKVM bug sometime ago, hopefully it can be used to reproduce the error
we are getting. I will continue to investigate around the
DynamicTypeWrapper class and in particular what is happening in the
LoadTypeWrapper method. Using the statement you suggested:
'global::System.Console.WriteLine(x);' in openjdk.cs we get the the
trace of where the exception is thrown from in IKVM, which is given below.


at IKVM.Internal.DynamicTypeWrapper.LoadTypeWrapper(ClassLoaderWrapper
classLoader, String name)
at IKVM.Internal.DynamicTypeWrapper..ctor(ClassFile f,
ClassLoaderWrapper classLoader)
at IKVM.Internal.DynamicClassLoader.DefineClassImpl(Dictionary`2 types,
ClassFile f, ClassLoaderWrapper classLoader, Object protectionDomain)
at IKVM.Internal.ClassLoaderWrapper.DefineClassCritical(ClassFile f,
Object protectionDomain)
at IKVM.Internal.ClassLoaderWrapper.DefineClass(ClassFile f, Object
protectionDomain)
at IKVM.NativeCode.java.lang.ClassLoader.defineClass1(ClassLoader
thisClassLoader, String name, Byte[] b, Int32 off, Int32 len, Object pd,
String source)

and the stack trace reported back to Visual studio is the following:

java.lang.NoClassDefFoundError was unhandled
Message=com.saxonica.bytecode.GeneratedCode
Source=IKVM.Runtime
StackTrace:
at IKVM.NativeCode.java.lang.ClassLoader.defineClass1(ClassLoader
thisClassLoader, String name, Byte[] b, Int32 off, Int32 len, Object pd,
String source)
at java.lang.ClassLoader.defineClass1(String , Byte[] , Int32 , Int32 ,
ProtectionDomain , String )
at java.lang.ClassLoader.defineClass(String name, Byte[] b, Int32 off,

Int32 len, ProtectionDomain protectionDomain)
at java.lang.ClassLoader.defineClass(String name, Byte[] b, Int32 off,

Int32 len)
at net.sf.saxon.dotnet.DotNetPlatform$1.findClass(String )
at java.lang.ClassLoader.loadClass(String name, Boolean resolve)
at java.lang.ClassLoader.loadClass(String name)
at com.saxonica.bytecode.util.CompilerService.makeClass(ClassWriter
writer, String className)
at
com.saxonica.bytecode.util.CompilerService.compileToByteCode(Expression
expr, String objectName, Int32 evaluationModes)
at
com.saxonica.bytecode.LetExpressionCompiler.compileCommonExpr(CompilerService
compiler, Expression exp, Int32 evaluationMode, Int32 refCount)
at
com.saxonica.bytecode.LetExpressionCompiler.compileToPush(CompilerService compiler,
Expression expression)
at com.saxonica.bytecode.util.CompilerService.compileToPush(Expression expr)
at
com.saxonica.bytecode.ForExpressionCompiler.compileToPush(CompilerService compiler,
Expression expression)
at com.saxonica.bytecode.util.CompilerService.compileToPush(Expression expr)
at com.saxonica.bytecode.BlockCompiler.compileToPush(CompilerService
compiler, Expression expression)
at com.saxonica.bytecode.util.CompilerService.compileToPush(Expression expr)
at
com.saxonica.bytecode.ElementCreatorCompiler.compileToPush(CompilerService

compiler, Expression expression)
at
com.saxonica.bytecode.ToPushCompiler.compileToIterator(CompilerService
compiler, Expression expression)
at
com.saxonica.bytecode.util.CompilerService.compileToIterator(Expression
expr)
at
com.saxonica.bytecode.util.CompilerService.compileToByteCode(Expression
expr, String objectName, Int32 evaluationModes)
at com.saxonica.expr.ee.OptimizerEE.compileToByteCode(Expression expr,
String objectName, Int32 evaluationMethods)
at net.sf.saxon.query.XQueryExpression..ctor(Expression exp, Executable
exec, QueryModule mainModule, Configuration config)
at net.sf.saxon.query.QueryParser.makeXQueryExpression(String query,
QueryModule mainModule, Configuration config)
at net.sf.saxon.query.StaticQueryContext.compileQuery(String query)
at Saxon.Api.XQueryCompiler.Compile(String query)
at SaxonEE_bytecode_test.Program.TestXQueryCompilation() in
C:\Users\ond1\Desktop\SaxonEE-bytecode-test\SaxonEE-bytecode-test\Program.cs:line
24
at SaxonEE_bytecode_test.Program.Main() in
C:\Users\ond1\Desktop\SaxonEE-bytecode-test\SaxonEE-bytecode-test\Program.cs:line
37
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:









Hi,

It can't find the windows resource compiler. Building from a Visual Studio command prompt should fix that, but you can also simply ignore this error, the important files have been built at this point.

Sent from my Windows Phone
From: Dr O'Neil Delpratt
Sent: 8/1/2012 9:13
To: Jeroen Frijters
Subject: Re: NoClassDefFoundError thrown

Hi Jeroen,

I am getting this build error which indicates a missing file. Any ideas?:

[nant] C:\work\software\ikvm-ikvm\ikvm\jvm\jvm.build
Buildfile: file:///C:/work/software/ikvm-ikvm/ikvm/jvm/jvm.build
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: JVM

Function platform::is-win32 is deprecated. Use the
is-windows function instead.

version:

[copy] Copying 1 file to
'C:\work\software\ikvm-ikvm\ikvm\jvm\jvm.rc'.

JVM:

[rc] Compiling
"C:\work\software\ikvm-ikvm\ikvm\jvm\jvm.rc" to
"C:\work\software\ikvm-ikvm\ikvm\jvm\jvm.res".

BUILD FAILED - 0 non-fatal error(s), 1 warning(s)

C:\work\software\ikvm-ikvm\ikvm\jvm\jvm.build(20,10):
'rc' failed to start.
The system cannot find the file specified



On 01/08/2012 15:03, Jeroen Frijters wrote:
The javac in your path must be Java 7.

________________________________________
From: Dr O'Neil Delpratt [oneil@saxonica.com]
Sent: Wednesday, August 01, 2012 3:36 PM
To: Jeroen Frijters
Subject: Re: NoClassDefFoundError thrown

Hi Jeroen,

Thanks again. I am now almost there with a complete build. However I am
getting lots of errors related to the Openjdk. I am using the zip file
from your website: openjdk-7u4-stripped.zip
Any ideas?

Just to mention a few of the error:
.....
[exec] sun\nio\ch\FileDispatcherImpl.java:255:

<identifier expected
[exec] catch
(cli.System.ArgumentOutOfRangeException
[exec] ^
[exec] sun\nio\ch\FileDispatcherImpl.java:256: '{' expected
[exec] |
cli.System.ObjectDisposedException x)
[exec] ^
[exec] sun\nio\ch\FileDispatcherImpl.java:256: illegal start of expression
[exec] |
cli.System.ObjectDisposedException x)
[exec] ^
[exec] sun\nio\ch\FileDispatcherImpl.java:256: ';' expected
[exec] |
cli.System.ObjectDisposedException x)
[exec] ^
[exec] sun\nio\ch\FileDispatcherImpl.java:256: ';' expected
[exec] |
cli.System.ObjectDisposedException x)
[exec] ^
[exec] sun\nio\ch\FileDispatcherImpl.java:263: illegal
start of expression
[exec] static class NotLockedHack {
[exec] ^
[exec] sun\nio\ch\FileDispatcherImpl.java:268: '{' expected
[exec] try (FileStream fs = new
FileStream(tmp.getPath(),
cli.System.IO.FileMode.wrap(cli.System.IO.FileMode.Create))) {
[exec] ^
[exec] 100 errors

BUILD FAILED - 0 non-fatal error(s), 309 warning(s)

C:\work\software\ikvm-ikvm\ikvm\openjdk\openjdk.build(99,10):
External Program Failed: javac (return code was 1)

On 01/08/2012 14:01, Jeroen Frijters wrote:
Hi O'Neil,

Oh yeah, sorry about that. openjdk.cs is not your run of the mill C# due to all the name clashes. It should be:

global::System.Console.WriteLine(x);

Regards,
Jeroen
________________________________________
From: Dr O'Neil Delpratt [oneil@saxonica.com]
Sent: Wednesday, August 01, 2012 11:48 AM
To: Jeroen Frijters
Subject: Re: NoClassDefFoundError thrown

Hi Jeroen,

Thanks for your pointer. I have being using nant to build IKVM with your
suggestion but I am getting the following error:
[csc]
c:\work\software\ikvm-ikvm\ikvm\runtime\openjdk.cs(2944,28): error
CS0117: 'IKVM.NativeCode.java.lang.System' does not contain a definition
for 'Console'

I am not an expert in .NET but is it complaining about the namespace?

On 25/07/2012 07:18, Jeroen Frijters wrote:
Hi O'Neil,

This does not look familiar to me.

What is the name of the class in the NoClassDefFoundError and what sort of class is it (meaning, the one you're now trying to define or a .NET class or a class library class)?

What could also be helpful is to modify defineClass1 in ikvm/runtime/openjdk.cs to print the stack trace of the original location of the NoClassDefFoundError:

catch (RetargetableJavaException x)
{
+ System.Console.WriteLine(x);
throw x.ToJava();
}

Regards,
Jeroen

-----Original Message-----
From: Dr O'Neil Delpratt [mailto:oneil@saxonica.com]
Sent: Tuesday, July 24, 2012 19:28
To: Jeroen Frijters
Subject: NoClassDefFoundError thrown

Hi Jeroen,
My apologies in not posting this on the mailing list.

In the Saxon release 9.4 we are generating byte code from XSLT/XQuery
source and loading and executing it.
This worked fine with IKVM version 0.46.0.2 and visual studio 2008, .NET
version 2.XXX. However the same code is not working with Visual Studio
2010, .NET version 4.0.30319. When we run the visual studio project we
get NoClassDefFoundError, the stack trace of the error is as follows:
at IKVM.NativeCode.java.lang.ClassLoader.defineClass1(ClassLoader
thisClassLoader, String name, Byte[] b, Int32 off, Int32 len, Object pd,
String source)
at java.lang.ClassLoader.defineClass1(String , Byte[] , Int32 ,
Int32 , ProtectionDomain , String )
at java.lang.ClassLoader.defineClass(String name, Byte[] b, Int32
off, Int32 len, ProtectionDomain protectionDomain)
at java.lang.ClassLoader.defineClass(String name, Byte[] b, Int32
off, Int32 len)
at com.saxonica.bytecode.util.CompilerService$1.findClass(String )
at java.lang.ClassLoader.loadClass(String name, Boolean resolve)
at java.lang.ClassLoader.loadClass(String name)
at com.saxonica.bytecode.util.CompilerService.makeClass(ClassWriter
writer, String className)
.......

Any ideas of what is happening? Is there a more recent release which has
addressed this kind of issue?




    (1-1/1)