Closed toddATavail closed 8 years ago
Sorry, I guess the wording is confusing.
If you have any .stack directives in a method, Krakatau generates a StackMapTable attribute, filled in with the data from those directives. What it was means is that you don't also have to say ".stackmaptable". If you don't have any .stack directives, it won't implicitly generate a StackMapTable attribute.
If you are generating bytecode yourself, I would highly recommend using version 49.0 (or 50.0, I guess). Creating stack maps is a huge pain. And old classfiles versions are completely interoperable with new ones. The only downside is that you can't use invokedynamic or other new features.
You might be able to generate the class file using Krakatau, then run it through ASM using COMPUTE_FRAMES to create the frames. That's assuming that you are able to integrate Java into your optimizing compiler
As far writing a tool to generate stack maps for you from bytecode, the biggest issue I can think of is how to handle type merging. Without knowing the inheritance hierarchies of the classes in advance, you can't determine the lowest common superclass or which classes are interfaces.
Apart from that, it would require work and it's not a priority for me.
Also, I second the suggestion to try ASM.
Thanks for the advice. I'll look into using ASM to rewrite the class files with the computed stack maps.
You might want to reword the passage that confused me, lest it confuse anyone else. Krakatau is a pretty good tool. It would certainly be nice if it could generate stack map tables also, as this would reverse a lot of the harm introduced by Oracle in necessitating computation of the stack map tables by users. A clean JVM assembler that is able to automatically generate correct stack map tables would be a tremendous asset to the community; incidentally, it's what I thought that Krakatau already was, and what drove me to use it.
Thanks again.
ASM worked for me, by the way. I am now using ASM to add stack map tables to classes generated by Krakatau. I have complete control over the compiler, so it will be easy to integrate this extra step into the code generation process. Thanks for the good advice!
Storyyeller: Out of curiosity, would you like the program that I wrote to leverage ASM to add stack map tables to existing class files? It's a small, clean, well-documented, one-file Java application that uses only ASM and the JRE. It doesn't exactly fit in with your Python code, but it's a good complement to Krakatau itself, and might make your product even more attractive to developers with similar use cases. Presumably users of Krakatau already have access to Java technology; they might not have ASM already, but it's a good bet that they can get it if needed.
My company, My Coverage Plan, Inc., has authorized me to release this program for you to redistribute, so long as 1) it remains under an open-source license that acknowledges our contribution and 2) we can continue to use it under either the new or original license.
If you're not interested, then perhaps you wouldn't mind if I approached the authors of ASM with the same offer? They didn't seem to have anything like this already written up, and I have to imagine that it's a fairly common use case ever since Oracle tightened the thumbscrews on 1.7. But I'd like to offer it to you first, since it's a useful augment to Krakatau.
I think it would be a better fit with ASM. If they don't want it, I'd suggest uploading it to Github seperately.
According to the documentation (Documentation/assembler.txt):
However, I have not yet found a case where assemble.py actually produces the
StackMapTable
attribute. This includes cases where the JVM requires one.Consider the following Krakatau source file, SumIntegersApp.j, which encodes a program that sums the command line arguments, treating them as stringified integers:
The latest version of Krakatau from GitHub produces a version
52
Java class file from this source (assemble.py SumIntegersApp.j). Using javap -verbose -c produces:Note that the
StackMapTable
is missing for main. Being a version52
class file, this is problematic, because attempting to run the class's main method produces:Setting the version to
50
produces a working class file, and the program executes as expected, but only because class files with version< 51
do not requireStackMapTable
attributes.I am using Krakatau as the back end of an optimizing compiler for a domain specific language, and I chose this technology in large part because of the quoted passage at the beginning of my post; I did not want to have to compute my own
StackMapTable
s. This issue is critical for me; I might be able to get away with using version50
class files in the short term, but not forever.Is it possible that I am not invoking Krakatau correctly? Do you see any problems with my source file, my procedure, or my reasoning? Thanks in advance for your help.