LD_DEBUG and java - java

When I set LD_DEBUG=files and run my Java program, I found many errors like this:
/linux/depot/java-1.6.0_16_32/jre/lib/i386/libjava.so: error: symbol lookup error: undefined symbol: Java_sun_java2d_loops_MaskBlit_MaskBlit (fatal)
This info is horrifying, but obviously my program runs OK. Can anyone tell me why this happens?

It's not horrifying; it's what happens when you build code to run on a lot of different platforms. It's just the jvm looking for optional symbols. In this case, something to do with 2D and alpha compositing. There is an alternate code path that is taken if the symbol is not found at runtime. You can think of it as a sort of reflection for libraries.
The jvm code goes something like this:
TYPE fptr = CAST_TO_FN_PTR(TYPE, dlsym(RTLD_DEFAULT, symbol));
if (fptr != NULL) {
// Do something different because this platform supports 'symbol'
}

Related

Difficulty with Octave's "javaMethod"

In this question, I was trying to import java classes into Octave. In my particular example, I was (and am) working with javaplex, a set of java tools with code for implementation in Matlab. The answer to the question shows that, whereas in Matlab you would do the following:
import edu.stanford.math.plex4.*;
api.Plex4.createExplicitSimplexStream();
The answer provided in the question showed that the way to do this in Octave is
javaMethod( 'createExplicitSimplexStream', 'edu.stanford.math.plex4.api.Plex4')
This was working excellently, but then I ran into a strange problem. There is another method called createVietorisRipsStream. In Matlab, I would run this with a line such as the following:
api.Plex4.createVietorisRipsStream(parameters);
So I would think that the equivalent command in Octave would be
javaMethod( 'createVietorisRipsStream', 'edu.stanford.math.plex4.api.Plex4')
However, when I do this, I get the following error:
error: [java] java.lang.NoSuchMethodException: createVietorisRipsStream
I'm not sure why this error is coming up, and both are in the same JAVA file ('Plex4'). I did take a look at the Plex4 file, and there are two differences between createExplicitSimplexStream and createVietorisRipsStream that I noticed:
There are two instances of createExplicitSimplexStream and six instances of createVietorisRipsStream
There is bit that says <double[]>. I don't know if that is relevant however (I haven't read or wrote much java, up to this point, I've been able to use the tutorial they provided to only use Matlab and not have to look under the hood).
Here is one example of the code from the Plex4 file for a createExplicitSimplexStream:
public static ExplicitSimplexStream createExplicitSimplexStream(double maxFiltrationValue) {
return new ExplicitSimplexStream(maxFiltrationValue);
}
Here is one example of the code from the Plex4 file for a createVietorisRipsStream:
public static VietorisRipsStream<double[]> createVietorisRipsStream(double[][] points, int maxDimension, double maxFiltrationValue, int numDivisions) {
return FilteredStreamInterface.createPlex4VietorisRipsStream(points, maxDimension, maxFiltrationValue, numDivisions);
}
Any idea of why I'm getting the error I'm getting?
Read the octave documentation for the Java section properly, it's only 4 pages, and it explains this well!
As I mentioned in the comments in the previous question, the way to call a java method with arguments is:
javamethod(
name of method as a string,
name of class fully qualified with packages as a string,
method's first argument,
method's second argument,
... etc
)
This is the only way to call 'static' methods; with normal 'instance' methods, you can either use javaMethod and replace the name of the class by the java object itself, or simply use it as you would in java, i.e. objectname.methodname(arg1, arg2, ... etc)
I have implemented here the tutorial for you to have a look at (page 14 in the pdf). (don't forget to run the modified 'load_javaplex' script first).
octave:2> max_dimension = 3;
octave:3> max_filtration_value = 4;
octave:4> num_divisions = 1000;
octave:5> point_cloud = javaMethod( 'getHouseExample', 'edu.stanford.math.plex4.examples.PointCloudExamples')
point_cloud =
<Java object: double[][]>
octave:6> stream = javaMethod( 'createVietorisRipsStream', 'edu.stanford.math.plex4.api.Plex4', point_cloud, max_dimension, max_filtration_value, num_divisions)
stream =
<Java object: edu.stanford.math.plex4.streams.impl.VietorisRipsStream>
octave:7> persistence = javaMethod( 'getModularSimplicialAlgorithm', 'edu.stanford.math.plex4.api.Plex4', max_dimension, 2)
persistence =
<Java object: edu.stanford.math.plex4.autogen.homology.IntAbsoluteHomology>
octave:8> intervals = persistence.computeIntervals(stream)
intervals =
<Java object: edu.stanford.math.plex4.homology.barcodes.BarcodeCollection>
(I have not gone further because plot_barcodes needs to be modified a bit too; it's only a couple of lines but it would be too much to post here, the reasoning is the same though).
Also, if you're not sure what is meant by class constructors, class methods, and static vs instance-specific methods, unfortunately this is more to do with java, although it should be pretty introductory stuff. It is well worth reading up a bit about it first.
Good luck!

Apache Pig: Syntax error with 'DUMP' in macro definition

I encountered an interesting problem with macro definition in pig. Here's the code:
DEFINE Func(src) RETURNS dst{
$dst = GROUP $src ALL;
DUMP $dst;
}
raw = LOAD 'data';
grp = Func(raw);
And when execute those codes in grunt shell, there will be an error:
ERROR 1200:... Failed to parse macro 'Func'. Reason:... Syntax error, unexpected symbol at or near 'DUMP'
But, where did I make the mistake? O.O
I found that someone has already reported the bug(if we call that a bug: link) a long time ago, but it seems the Pig developing team is not planing to solve that. :(

TestRig in ANTLRworks: how to use own classes?

I'm trying to build a MT940 parser using antlr4. The grammar is simple but works for most cases.
Now I want to return my own classes. This works:
file returns [String myString]
:
Header940? record+ EOF
;
I think this is becasue String is in the default java packages.
I want this:
file returns [List<MT940Record> records]
:
Header940? record+ EOF
;
The TestRig complains (logically):
/tmp/TestRigTask-1392235543340/MT940_5aParser.java:50: error: cannot find symbol
public List<MT940Record> records;
^
symbol: class MT940Record
location: class FileContext
How can I set the CLASSPATH / lib directory in the TestRig in ANLTRWorks?
In ANTLRWorks, you can't. You can add an issue for this on the issue tracker:
https://github.com/sharwell/antlrworks2/issues
Note that ANTLR 4 was designed so you no longer need to use user-defined arguments and/or return values in your grammar. Instead of returning a List<MT940Record> like you described above, you should use a listener or visitor after the parse is complete to compute the necessary result.

Using chef to install Java 7, can't get it to work

I have a wrapper cookbook with one recipe in it, recipes/default.rb that reads the following:
include_recipe "apt"
node.override[:java][:jdk_version] = '7'
include_recipe "java"
I have the apt and java cookbooks from the community site. I'm running knife bootstrap with only this wrapper recipe.
When I converge the node, it installs Java 6 instead of Java 7. I feel like there's something obvious I'm missing, but I can't figure it out. Shouldn't the node.override make it so the default jdk_version of 6 is overridden?
Qualifying my answer with "I'm not a chef expert"... However, I think the issue is with "nested attributes" in Chef. I don't think you can just go ahead and override just the version, because after peeling over every possible thing that could be wrong with your piddly recipe, I found this:
http://lists.opscode.com/sympa/arc/chef/2012-10/msg00265.html
There's some other attributes that are being set after the default jdk version is set. If you look here:
http://community.opscode.com/cookbooks/java/source
You'll see default['java']['openjdk_packages'] gets set using that default version, and the openjdk recipe, which is likely the "install_flavor" being chosen, ONLY looks at that attribute. It doesn't read in the jdk_version directly. Interestingly, the java::oracle recipe (along with java::oracle_i386 and java::oracle_rpm) read in the version directly, so your initial attempt would have worked for that.
I would try setting the version with one of these, based on your particular platform:
Redhat/CentOS: node.override[:java][:openjdk_packages] = ["java-1.7.0-openjdk", "java-1.7.0-openjdk-devel"]
Debian/Ubuntu: node.override[:java][:openjdk_packages] = ["openjdk-7-jdk"]
Other "platform_family" choices can be found here: https://github.com/opscode-cookbooks/java/blob/master/attributes/default.rb
Here is how I got it to work with a wrapper cookbook.
I had to add this statement to the attributes/default.rb:
override[:java][:openjdk_packages] = [
"openjdk-7-jdk", "openjdk-7-jre-headless"
]
I tried adding the jdk_version in this location and it didn't work. I tried adding this statement (with node.override) in the wrapper cookbook recipe and it didn't work either.
Here is a description of why this is the case.

Using Inline::Java in perl with threads

I am writing a trading program in perl with the newest Finance::InteractiveBrokers::TWS
module. I kick off a command line interface in a separate thread at the
beginning of my program but then when I try to create a tws object, my program
exits with this message:
As of Inline v0.30, use of the Inline::Config module is no longer supported or
allowed. If Inline::Config exists on your system, it can be removed. See the
Inline documentation for information on how to configure Inline. (You should
find it much more straightforward than Inline::Config :-)
I have the newest versions of Inline and Inline::Java. I looked at TWS.pm and it doesn't seem to be using Inline::Config. I set 'SHARED_JVM => 1' in the 'use Inline()' and 'Inline->bind()' calls in TWS.pm but that did not resolve the issue...
My Code:
use Finance::InteractiveBrokers::TWS;
use threads;
use threads::shared;
our $callback;
our $tws;
my $interface = UserInterface->new();
share($interface);
my $t = threads->create(sub{$interface->runUI()});
$callback= TWScallback->new();
$tws = Finance::InteractiveBrokers::TWS->new($manager); #This is where the program fails
So is Inline::Config installed on your system or not? A cursory inspection of the code is not sufficient to tell whether Perl is loading a module or not. There are too many esoteric ways (some intentional and some otherwise) to load a package or otherwise populate a namespace.
The error message in question comes from this line of code in Inline.pm:
croak M14_usage_Config() if %main::Inline::Config::;
so something in your program is populating the Inline::Config namespace. You should do what the program instructs you to do: find out where Inline/Config.pm is installed on your system (somewhere in your #INC path) and delete it.

Categories