janklab / matlab-bench

Some utilities for exploring Matlab's behavior
MIT License
32 stars 6 forks source link

Error running java code: Undefined variable "net" or class "net.apjanke.matlab_bench.bench_nops.DummyJavaClass". #1

Closed eacousineau closed 5 years ago

eacousineau commented 10 years ago

Trying to run the code (sha: 6059d52), but I get the following error:

Undefined variable "net" or class "net.apjanke.matlab_bench.bench_nops.DummyJavaClass".

Error in bench_matlab_nops>bench_nops_pass (line 195)
jObj = net.apjanke.matlab_bench.bench_nops.DummyJavaClass;

Error in bench_matlab_nops (line 33)
    bench_nops_pass(10000, 1);

Will try and dig a bit and see what issue it is.

System:

Matlab R2013a on GLNXA64  
Matlab 8.1.0.604 (R2013a) / Java 1.6.0_17 on GLNXA64 Linux ***** 
Machine: Core i7-3740QM CPU @ 2.70GHz, 7803 GB RAM (#35~precise1-Ubuntu SMP Fri May 2 21:32:55 UTC 2014)
eacousineau commented 10 years ago

Ah, looks like a major / minor version issue. I added a quick main() method and was able to execute the jar from the bench_matlab_ops directory:

$ java net.apjanke.matlab_bench.bench_nops.DummyJavaClass

Running it with Matlab's Java version reveals that it is incompatible with my system's. Awesome haha.

$ $MATLAB_ROOT/sys/java/jre/glnxa64/jre/bin/java net.apjanke.matlab_bench.bench_nops.DummyJavaClass
Exception in thread "main" java.lang.UnsupportedClassVersionError: net/apjanke/matlab_bench/bench_nops/DummyJavaClass : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: net.apjanke.matlab_bench.bench_nops.DummyJavaClass.  Program will exit.

I've gotta stop for a while, but if I'm able to return to this, I'll see how easy it is to recompile with a version compatible with Matlab (without screwing over my security).

apjanke commented 10 years ago

Oops... I forgot I had JDK 1.8 installed on my machine, and I used its javac to compile this, and Java 1.8 class files are not necessarily back-compatible. I'll recompile to an older JVM target for wider compatibility.

apjanke commented 10 years ago

I've recompiled the Java classes with JDK 1.6 and checked them in. (https://github.com/apjanke/matlab-bench/commit/a87f8738546c92c727e120aef61612c4d337a482) Should work now. I've added a main() for testing and was able to reproduce the problem with the old class file.

Works for me now using a standalone 1.6 JRE. I don't have the older version of Matlab to test it in that environment, but this should be sufficient. Let me know if it doesn't work.

[@ in ~/Dropbox/satchel/projects/Matlab/matlab-bench/bench_matlab_ops on ⇄ master]
$ java -cp . net.apjanke.matlab_bench.bench_nops.DummyJavaClass
Hello, world!
[@ in ~/Dropbox/satchel/projects/Matlab/matlab-bench/bench_matlab_ops on ⇄ master]
$ /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -cp . net.apjanke.matlab_bench.bench_nops.DummyJavaClass
Hello, world!
[@ in ~/Dropbox/satchel/projects/Matlab/matlab-bench/bench_matlab_ops on ⇄ master]
$
apjanke commented 5 years ago

Closing as fixed.