Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I want a JVM assembler that is straightforward and simple. It should take a text file written in the mnemonic language described in The Java Virtual Machine Specification and produce class files, i.e. bytecode.
To be clear: I don't want a library that can generate class files from invocations of an API.
What are the current statuses of the JVM assemblers? Do they support invokedynamic (not mandatory to me, but an advantage)? On what operative system can I use them? What are their individual pros and cons?
Some time has passed, and now there is an alternative to Jasmin called Krakatau.
From the README.txt:
The Krakatau assembler is intended as a replacement for Jasmin, and was originally written due to the limitations of Jasmin. It is mostly backwards compatible with Jasmin's syntax, though not necessarily with the extensions introduced in JasminXT. However, Krakatau offers many new features, most importantly the ability to directly specify constant pool references.
At this time, it seems that Krakatau was last updated a month ago, and Jasmin was last updated nine years ago.
Krakatau does support invokedynamic and utilizes the same instruction names as are used in the JVMS.
Krakatau is implemented in Python. Personally, I like my Java tools to be implemented in Java, but given the nature of this tool (constructing class files from non-Java source) and the lack of competition in this niche, I'll give it a chance.
Jasmin is the de facto standard. Recent versions support invokedynamic. It's written in Java, so it's portable.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I am trying to find a Java decompiler just like swf-decompiler, that allows to edit and recompile the source, without having to export it anywhere, and do any external actions. What I want is to very quickly apply small changes to .jars and save them, without taking extra time on manually recompiling java code with other tools, Is there a decompiler like that? Is there anything similar (like .class variable editor) and is it even possible to make a Java decompiler like swf-decompiler?
Recommending a tool is offtopic, but as for the question of whether it is possible, the answer is yes and no.
Java is relatively decompiler friendly, so for simple cases, it should be possible to create such a tool. However, there are some features or patterns that tend to trip up current decompilers, and given the complexity of the language, there is unlikely to ever be a decompiler that can reliably roundtrip arbitrary Java.
Furthermore, while compiling Java loses a lot less information than C, it does lose information. Obviously, you'll lose stuff like comments and whitespace, but under default settings, you'll lose a lot more: local variable names, flags, and types, generic types, compile time annotations, etc. Most of this information is preserved to some extent for reflection purposes, and passing the -g flag to the compiler can force it to save more information, but you can't get it all back.
So in short, you can do a reasonable job most of the time, but you can't ever do it perfectly all of the time.
Also note that this is for ordinary Java compiled yourself. If the classfiles were not originally written in Java or they are obfuscated at all, you can forget recompiling. Even when decompilers produce readable output, the output is unlikely to be recompileable.
If you want to modify arbitrary jars, what you need is a disassembler and assembler. The best one I know of is Krakatau (Disclosure: I wrote it). The advantage of this is that it will work for any classfiles, even if they are obfuscated. However, it is not user friendly at all. If you don't know your way around the classfile format and bytecode, you won't be able to make more than trivial changes (such as changing a constant string).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
As of October 2010, is GNU's Java compiler dead?
Are there any active alternatives (especially for compiling Java to native code)?
LLVM solutions would be preferred.
You could use IKVM and Mono's ahead of time compiler to generate native code.
EDIT
There is an example at the bottom of this page.
A more pertinent question would be whether it was ever really alive. Consider these issues, from its own website:
1.2 support is 'still incomplete'.
1.3 ditto.
The project was last updated over a year ago [as of October 2009].
Currently 'supports most of the 1.4 libraries plus some 1.5 additions.'
Doesn't support java.nio.
Doesn't support javax.naming ('complete but no providers').
Doesn't support javax.sql.
Doesn't support AWT or Swing.
Doesn't support localization via java.text.
State of java.security is 'unknown'.
Doesn't check permissions in java.lang.reflect.
Does it compile generics?
Huge chunks missing out of other packages, e.g. nearly 50% of java.util.
No annotations.
No script engine.
Nearly all of javax.xml.* (recursively) is missing.
No org.omg.CORBA.
Practically no org.w3c.
Current comparison with JDK 1.6 is here. Note that this appears to add percentages to give a completely meaningless total.
And note that it isn't billed as a 'Java compiler'. It is a compiler for a subset of Java known as GNU CLASSPATH. Which in turn hasn't been updated since Feb 2009.
If it isn't dead it is certainly lying down.
EDIT It's dead. GCJ is no longer listed as a GNU package. And after four years of zero activity we are entitled to assume the same about GNU CLASSPATH.
One alternative to compile Java to native is Excelsior JET.
I think not that it is dead. It has only few important. Which result in a slow development. There are 3 fact because it has only few important today:
It based on the GNU Classpath. Since Java is open source (OpenJDK) there is no large need for another open source Java. This has slow down the development speed.
The Java was faster in the last years. The GCJ output is not faster. In many cases it is slower.
The GNU Classpath has many incompatibility.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I am in a project where previous programmers have been copy-pasting codes all over the place. These codes are actually identical (or very similar) and they could have been refactored into one.
I have spent countless hours refactoring these codes manually but I think there must be a better way. Some are very trivial static methods that could have been moved into an ancestor class (but instead was copy pasted all over by previous junior programmers).
Is there a code analysis tool that can detect this and provide reports/recommendations? I prefer free/open source tool if possible.
I use the following tools:
PMD/CPD (BSD-style License).
Checkstyle (LGPL License) - support was removed, see details.
Both tools have code duplication detection support. But both of them lack the ability to advise you how to refactor your code.
JetBrains IntelliJ IDEA Ultimate has good static code analysis with code duplication support, but it is not free.
Most of the tools listed on the Wikipedia article on Duplicate Code Tools will detect duplicates in many different languages, including Java.
SonarQube can detect duplicated codes but does not give recommendation on eliminating them. It is free and - although with the default setup it can only detect lexically identical clones
Either Simian or PMD's CPD. The former supports a wider set of languages but is non free for commercial projects.
http://checkstyle.sourceforge.net/ has support for finding duplicates
See our SD Java CloneDR, a tool for detecting exact and near-miss duplicate code in large Java systems.
The CloneDR will find code clones in spite of whitespace changes, line breaks, comment insertions deletions, modification of constants or identifiers, and in a number of cases, even replacement of one statement by another or a block of statements.
It shows where each set of clones is found, each individual clone, an abstraction of the clones having their shared commonality and parameterization of the abstraction to show how each clone instance can be derived from the abstraction.
It finds 10-20% clones in most Java systems.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Is there a tool out there that can automatically convert Python to Java?
Can Jython do this?
Actually, this may or may not be much help but you could write a script which created a Java class for each Python class, including method stubs, placing the Python implementation of the method inside the Javadoc
In fact, this is probably pretty easy to knock up in Python.
I worked for a company which undertook a port to Java of a huge Smalltalk (similar-ish to Python) system and this is exactly what they did. Filling in the methods was manual but invaluable, because it got you to really think about what was going on. I doubt that a brute-force method would result in nice code.
Here's another possibility: can you convert your Python to Jython more easily? Jython is just Python for the JVM. It may be possible to use a Java decompiler (e.g. JAD) to then convert the bytecode back into Java code (or you may just wish to run on a JVM). I'm not sure about this however, perhaps someone else would have a better idea.
It may not be an easy problem.
Determining how to map classes defined in Python into types in Java will be a big challange because of differences in each of type binding time. (duck typing vs. compile time binding).
Yes Jython does this, but it may or may not be what you want
to clarify your question:
From Python Source code to Java source code? (I don't think so)
.. or from Python source code to Java Bytecode? (Jython does this under the hood)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Are there any good tools out there for automatically converting non-Java source code into Java source?
I'm not expecting something perfect, just to get the worst of the grunt work out of the way.
I guess there is a sliding scale of difficulty. C# should be relatively easy (so long as you ignore all the libraries). (well written) C++ not so bad. C requires making a little OO. (Statically type) functional languages may be easy to grok. Dynamic OO languages may require non-local analysis.
One thing you can try is find a Java bytecode compiler for the language you're talking about (there are JVM compilers for all kinds of languages) and then decompile the bytecode back into Java using a decompiler like Jad.
This is fraught with peril. The regenerated code will suck and will probably be unreadable.
Source-to-source migrations fall under the umbrella of Program Transformation. Program-Transformation.org tracks a bunch of tools that are useful for language recognition, analysis, and transformation. Here are few that are capable of source-to-source migrations:
ASF+SDF Meta-Environment - As noted, there is no new development on this tool. Instead, the developers are focusing on Rascal.
Rascal Meta Programming Language
Stratego /XT
TXL
DMSĀ® Software Reengineering Toolkit (commercial)
If you spend any time with one of the open source tools, you'll notice that even though they include source-to-source migration as a feature, it's hard to find working examples. I imagine this is because there's no such thing as a one-size-fits-all migration. Each project/team makes unique use of a language and can vary by libraries used, type complexity, idioms, style, etc. It makes sense to define some transformations per migration. This means a project must reach some critical mass before automatic migration is worth the effort.
A few related documents:
An introduction to Rascal - includes a migration between the toy language Pico and Assembly starting at page 94.
Cracking the 500 Language Problem
An Experiment in Automatic Conversion of Legacy Java Programs to C# (gated) - uses TXL
Google: ANTLR
The language conversion is fairly simple, but you will find the libraries are different.
This is likely to be most of your work.
If you just want to use some legacy C/Pascal code, you could also use JNI to call it from Java.
If you want to run it in a Java applet or similar constrained environment, and it does not have to be very efficient, you can use NestedVM (which is a MIPS to Java bytecode converter) in conjunction with a gcc cross-compiler that compiles to MIPS). But don't expect to get readably Java code from that.
Any of those tools might help only if your non java code is not huge enough.
If its huge non java code and if you want to seriously translate it to java, then few things need to be thought of, its not just hundreds of lines of code, there is a design beneath it, there are few decisions taken by people beneath the code due to which certain problems might have been solved and few things have been working there. and investing time on any good translator won't be worth as it won't exist, it's not just syntax translation from one language to another.
If its not so huge code, its better to re write in java, as it has so many APIs packages out of box, it might not be big deal, hiring few interns for this also might help.
ADA to Java can be done with a find-and-replace!