Is there any attempt in the works to make a Java version of LLVM?
Note: I am not asking about either LLVM front ends or back ends. I am asking about the LLVM toolset itself. I would like to experiment with LLVM but I find I am much more productive working with Java and Java libraries rather than C++.
There is a C interface to all LLVM libraries. It's quite stable and functional, and is used by Python and Haskell bindings.
So you can use it with JNI to create LLVM bitcode, optimize or transform it as you wish, save and run it, etc.
Related
Can Python invoke the Java Framework?
I want to know whether a Python project can invoke a Java Framework, I find a Java Framework in GitHub, whether I can use it in my Python project?
Jython
Jython is one method of calling Java from python -- actually, you run your Python inside Java JVM. This gives you access to almost any Java that runs on JVM, but comes with many limitations.
Because Jython is running python inside the JVM, this gives you acess to almost any Java library. However, you are very restricted in what Python you can use: you can only use Python 2.7, and can import pure Python libraries only (compiled Python libraries with C will not run on Jython).
For an example of a project that uses Jython: Processing.py runs on Jython in order to access the Processing Java API and its ecosystem of Java libraries.
https://github.com/jdf/processing.py
Note that Jython 2 and its docs are quite old, and that the developers are uncertain if / when Jython 3 will be released.
https://github.com/jython/jython3
py4j
py4j is a different approach -- it is "A Bridge between Python and Java" and lets native python code access separate Java running in a separate JVM. Note however that the python and Java code must be running in parallel and communicating through a gateway interface. This is communication between separately running processes -- you are not spinning up a JVM from Python or inside Python.
For example: on the JVM side pass myObject to a new GatewayServer(myObject); on the Python side create a JavaGateway() Python object and use it to communicate with the Java myObject.
Normally Python and Java have their own interpreters/VM's and cannot be shared. It is possible to use Jython but has limitations (fe. python version and support/compatibility with other python packages).
The interpreter and JVM do not match: Java has strict typing, python not. Java compiles and run, python is an interpreter and can change code in runtime (if you want). These are extra challenges why putting all in a same environment is very complex.
There are possibilities like a client/server architecture, but the feasability depends on the level of the framework.
Most of the time low level frameworks are optimized to run directly inside your application process. Any loose coupling will introduce performance and security and compatibility issues. Just think about how reflection will work or multiple inheritance.
If it is a high level framework (fe able to run stand alone) it is more feasable to use some sort of client/server. But still you have to develop a lot for it.
Industry standard is just to implement the framework of your desire in the language you want, then you can get also all the benefits of your platform.
I just saw the open source project on this in github (googlevr) and my question is how is it possible for C++ work with Java? I can understand that Java is for android stuff and C++ is for graphic, memory and tracking but how does two different compiled language work together?
In C and C++ you can create shared libraries. They are handled a bit differently for each platform, but do roughly the same thing.
Windows creates a .dll
Mac creates a .dylib
Linux creates a .so
These represent executable code that can be called by any process. This means that java code, matlab code, python code, etc can call code written in C/C++. Java uses a feature called JNI (Java Native Interface) to do this. JNI is notoriously tricky to setup and manage, so a lot of people use a library like Swig which essentially manages everything you need related to JNI in order to make calling precompiled C++ code from Java easier.
The key here is "precompiled". Someone, at some point, maybe even you, had to take the source code and compile it into a dll, dylib, or so and you have to have that shared library set up where the code that needs to use it (in this case your java app) can see it so that when the java app starts it can load the shared library and make calls into it.
For java one consideration is that java code is inherently cross-platform. C++ code needs to be compiled against each platform. So when you distribute your java app, you need to make sure you have a shared library available that is accessible for whichever platform it is being run on.
I implemented most of my projects in C++ and python. However, we recently got a new database interface that I could only use Java to retrieve data.
I want to stay with my Python/C++ tools but I am wondering if there is a good solution to integrate Java to my Python application. I heard about Jython, but it is a different python implementation and I am concerned some of my C++ tools will not work well with it. Jpype seems simple but it hasn't been updated since 2011, so a little concerned with the compatiablity with the current python/java.
Is there a good solution to this? all opinions are welcomed.
gcj (gcc compiler for java) supports java 1.5 syntax (1.4 is working better on it) and therefore some Java programs may be compiled to native code. gcjh (or javah) can produce headers for java libraries, so you can write C extensions for python. Of course some libraries could not be compiled with gcj (like Apache Commons Logging) because of using com.sun packages. Did not updated from 2009.
There is another Java to native compiler, commercial Excelsior Jet (it's another JavaVM, it supports Java 1.6 and soon Java 1.7). They said linux-64bit version of their product will be available in 2013-Q4. But I didn't try it well, I don't know, are headers for compiled library can be produced.
There is a lot packages at pypi, like JCC (from PyLucene creator) or Py4J that can use Oracle JavaVM through JNI or sockets.
One way to do this is to write web services. A web service can accept an HTTP request, marshal it into a data request, pass that to a Java class that get the data out, map the quert results into a response of some kind, and send it back.
Any client that can send an HTTP request, accept the response and unmarshal it can interact with that service. They need not know that it's implemented in Java.
You pay the price of an extra network roundtrip to get the benefit of language interoperability.
There are ways of wrapping C/C++ out there, but I can't speak to them.
Integrating with Java, however, is wonderfully simple. There's a distribution of Python called Jython which actually runs on the JVM. Using Java libraries is intuitive and easy:
from java.io.util import *
and for the most part it just works (some caveats apply in terms of threaded/async stuff). I love Jython. We used Jpype for a few projects but even if it were still fully maintained I'd still choose Jython over it any day for this sort of project.
ok, So i searched net for the possible implementation but all that I managed to find is Django projects implementation on Java platform through Jython. But I want to do the reverse, i.e. implement/integrate java project ( which in my case is SAIKU server ) on Django platform.
The question being, is it possible, and if yes, then kindly point me to the solution.
Thanking in advance =)
For your specific requirement, I would suggest using RESTFul API to access the Saiku Server.
However if you need to run Java Classes from Python.
Here are the options available for you:
JCC -- a C++ code generator for calling Java from C++/Python. It produces producing Python extensions which communicate via JNI with a Java virtual machine. As it implies, this would require compilations of every possible call. However this project is backbone of PyLucene project.
CodeMesh. C++ code generator for Java.
Py4J Python programs running in a Python interpreter to dynamically access Java objects in a Java Virtual Machine.
JPype allow python programs full access to java class libraries. It is done through interfacing at the native level in both Virtual Machines. However there are no recent development in this front.
In general, having an loosly coupled integration through REST or RCP would be easy to maintain than tightly coupled JNI based implementation.
There's no way to run Java within the Python runtime (which is what it sounds like you want). There are Java to Python "translators" available, but they're terrible. Honestly, if you need a Java server and Django to sit inside the same process for some reason, Jython is the way to go.
There are lots of options outside of that though, off the top of my head:
Implement Python bindings for your server (See PyLucene for an example)
Implement a socket server within your Java server that Python can talk to directly
How can we write a python (with CPython) binding to a Java library so that the developers that want to use this java library can use it by writing only python code, not worrying about any Java code?
You could try this way:
Use Jython instead of CPython to write Python code http://www.jython.org.
Integrate Jython code with Java code through Apache Bean Scripting Framework http://commons.apache.org/bsf/
If you definitely need to use CPython, then Apache Trift could be interesting for you: http://thrift.apache.org/ So you could make additional scalable abstraction layer and integrate your Java code with different languages (not only Python)
If you need a really low-level interface you could look at JNI http://java.sun.com/docs/books/jni/ for investigation. But I think it will take a lot of time to integrate your code with CPython using JNI.
I've used JPype in a similar instance with decent results. The main task would be to write wrappers to translate your java api into a more pythonic api, since raw JPype usage is hardly any prettier than just writing java code.