Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I saw the http://vmkit.llvm.org/ project but it's not quite what I'm looking for. Don't want my code to run on yet another VM but on .NET's and Java's VM.
Are there any compiler backends for LLVM that generate .NET CIL and/or Java Bytecode?
LLVM is on a much lower level than CIL and Java byte code. This means that it is difficult to map the LLVM instructions on to CIL and Java instructions, and nobody has really needed it yet so the work has not been done completely.
Some of the work has been done though. See http://llvm.1065342.n5.nabble.com/JVM-Backend-tp41356.html to see if it is useful to you.
EDIT 2020-09-03: Since this answer was written, WebAssembly has been defined which is essentially a cross platform machine language definition which runs in all major browsers and hopefully soon also natively on Linux and others. I would think that the future would be that everything distributes in this format and then is run on the appropriate virtual machine. This will most likely end the CPU wars.
C++ can be compiled to CIL (with visual C++/CLI compiler), so why not a CIL backend for LLVM?
I don't think it would be so complicated as far as the not .NET specific CIL instruction set
is quite small/simple. Compiling C++ to Java is much more complicated because there are no pointer instructions in Java's bytecode, so a Java's bytecode LLVM backend would be much more complicated.
I guess guys from MONO LLVM backend have already worked on something similar, but it seems they exploited LLVM in a different way because MONO is a C# compiler not a C++ compiler.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
Are there any libraries or methods that would make sharing code between C++/Java and IOS/Android easier? I realize we have JNI and IOS can use C++ pretty much directly, but it seems like it could be easier.
Microsoft Universal Windows Apps and Chrome Apps are (sort of) doing this.
Open Source is preferable.
I'm using Qt Creator a lot. With the latest versions, you write your whole application in C++, using Qt toolkit, and you can compile it targetting PC, Android and iOS (never tested this last one). If you need to call some SDK functions not available in Qt API, they provide wrapper objects to create and manipulate Jni objects, and you can also execute pure Jni code (loading a java file) if you want to.
If you are looking to share Java, you could try to use this: https://github.com/google/j2objc. I am not certain I'd say that it is easier than using C++. Each option will have some challenges. The downside to j2objc is that it is a translation of Java to Obj-C. So if there is a bug in it (note the comment in the desc which indicates it is between alpha and beta quality), you will need to figure out how you deal with it.
Admittedly, I have only done limited Android dev, and for that, it used the NDK and had a C++ lib which was shared between iOS and Android. I've also developed apps for iOS that were probably 95%+ C++.
BTW, your question is actually a bit vague. If you are talking libs, you should specify what areas you are looking to solve for. Your solution will vary based on your goals.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I have an app written in Scala and some of my team members want a Java version of it. It is a demo app to use another API written in Scala, and they want a Java version of the app to be able to use the API from Java. However, the app is somewhat large and I don't want to manually rewerite in Java (and they don't want to learn Scala). Is there any tool that will automatically generate (readable) Java code from the Scala code?
they want a Java version of the app to be able to use the API from Java
Scala classes are usable from Java (since it's all JVM bytecode in the end). Can you just package a jar with your classes for them to use?
I don't think it's possible to convert from scala back to standard java since Scala does some pretty low-level byte-code manipulation. I'm 90% sure they do some things that can't exactly be translated back into normal Java code.
No, there is no such tool.
Scala in some sense is a coffescript of Java.
Look how all that funky classes in coffescript are translated to javascript. The same* would be with scala.
I don't think that there is a lot features that can't be translated to Java in any way, but most of the features will be translated to extremely cluttered code, even if the human will do that work.
But there is java to scala translators.
* not saying literally about classes
You have to decompile the .class files to java source files, beware that scala produces many more .class files
You can use javap from oracle included in the sdk or jad decompiler
for detailed explanation read the following article:
Link scala class to java source
Not sure if this would work, but you could run the class files through a java decompiler.
If it works at all the result is bound to be ugly as hell.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Theoretically this seems possible to me. So can Any one confirm this to me, if it's possible? and if there is such a software that does this?(like Java to C++ or C#)
And in general would it be possible to transfer languages like Java to server-side programing language like PHP?
Translating the syntactical elements of one language and producing another is not trivial but it's not impossible. A good parser can build syntax trees in one language and then emit another. The difficulty of porting code outside the context of simple "Hello World" type applications is twofold:
The libraries of one language will probably differ (e.g. WinForms vs Swing)
Some language features will have to be catered for: (lambda expressions, anonymous methods, different inheritance implementations etc).
It is possible, but the major problem is that Java has a very large runtime library which needs to be made available in the target language in order to be able to do a fully automatic conversion.
For the special case of Java -> .NET, you can use J# from Microsoft to compile it into a .NET assembly which can then be used. Also ikvm.net allows for running a JVM inside .NET.
For PHP I do not believe such a solution exist. You MAY be able to use gcj to create a native library which can be linked in, but I do not believe it is a feasible soultion.
What functionality do you need in PHP?
Visual Studio ships with a Java to C# translator, and even tough it does a pretty decent job, there's still a lot to clean up afterwards.
In my experience you really have to ask yourself if it makes sense to translate code from one language to another. What is the gain? Will the translated code be maintainable? If the answers to these questions point in the wrong direction, translating is probably not the right approach.
Google Web Toolkit does conversion from Java to JavaScript:
http://code.google.com/webtoolkit/overview.html
to answer your question, yup, theoretically this is indeed possible and practically such technology is used every day :)
The interesting thing, in my opinion, is that the Java converters typically convert by taking the bytecode, not the source code. Then it's, say, bytecode-to-ObjectiveC source code. For some converters (at least one opensource one) it's bytecode-to-XML then XML-to-target-language.
For example, the Uniwar application for the iPhone, which has been acclaimed by all and made its way to the appStore's top ten, as been written in Java (JME) and automatically converted from the Java bytecode. Reaching the top ten, even for a few days, means that this is deployed on a lot of machines ;)
In the Real-World [TM], Cobol-Java and, weirdly, Java-Cobol are not unheard of.
For all this to work that said you need a really good converter :)
Theoretically it is possible. But as others pointed out the main problem is to translate libraries.
Some time ago I made Java to Tcl(XOTcl) and Java to Python translators to evaluate the translation posibility. Search by java2tcl and yava2python.
They convert syntax but do not make relevant constructions translations (e.g. Java file operations to Python ones). That would require more development time.
In general my opinion is what such a translation may be possible. But only if your translator covers classes/libraries of the converted project.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
Is there a nice place for learning the JVM bytecode instruction set. The specification perhaps and maybe some tutorials?
I ask because I would like to design a toy language and a compiler for it that generates JVM bytecode.
Thanks for your knowledge and perhaps googling.
A good reference for Java bytecode specification is the The Java Virtual Machine Specification.
See Chapter 4. The class File Format and Chapter 6. The Java Virtual Machine Instruction Set.
A little more "graphic" explanation, IBM developer works: Understanding bytecode makes you a better programmer.
The book Programming for the Java Virtual Machine explains the JVM instruction set and how to write code for it. It also introduces a bytecode assembler called Oolong, which I have not been able to download. You can, however, use Jasmin, the predecessor of Oolong. Essentially, you write a text file with instructions and Jasmin will spit out a .class file. The book was published in 1999, but it is still a good and gentle introduction to the VM.
Also useful are the javap disassembler and bytecode manipulation frameworks like ASM and BCEL, even if all you want to do is verify your classes.
The Java Virtual Machine Specification is a good place to start.
See Chapter 4 The class File Format. The updates cover new attributes added since the 2nd edition was made.
To start with, I suggest generating Java code from your language.
This will make reading and debugging much simpler.
A new version of the specification has been released:
The Java Virtual Machine Specification, Java SE 7 Edition
This new addition does exclude the chapter on Java Programming Language Concepts which folks may or may not find useful. See here for that chapter in the Second Edition of the spec.
Perhaps check out Preon's example on how to parse a Java class file. It has a fairly complete representation of the bytecode in a Java object model.
This is a bit more specialized, but here is an on-line presentation on how to optimize generated bytecode for running on the JVM. It was presented at the recent JVM Languages Summit conferences. InfoQ has a collection of presentations from that conference which might be of help to someone wanting to bring up a language on the JVM (or to see what's already been done).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I'm interested in how java organizes memory and executes code (like what gets put in the stack or the heap), from the start of main, to assigning variables, calling functions, passing parameters, returning values, instantiating objects, etc. Has anyone found a good, beginner-friendly article/reference on it?
The canonical reference is the JVM spec. However, different JVMs can implement the spec in different ways. You can also check out the open source Java platform implementation, OpenJDK.
I don't know exactly how they execute their bytecode, but I found this link describing java's bytecode. I am not sure if it helps, but at least it's something to start on.
Quote:
This article gives you an understanding of Java bytecode that will enable you to be a better programmer. Like a C or C++ compiler translates source code into assembler code, Java compilers translate Java source code into bytecode. Java programmers should take the time to understand what the bytecode is, how it works, and most importantly, what bytecode is being generated by the Java compiler. In some cases, the bytecode generated is not what you expect.