bytecode

8 branches for try with resources - jacoco coverage possible?

情到浓时终转凉″ 提交于 2019-11-27 05:13:37
问题 I've got some code that uses try with resources and in jacoco it's coming up as only half covered. All the source code lines are green, but I get a little yellow symbol telling me that only 4 of 8 branches are covered. I'm having trouble figuring out what all the branches are, and how to write code that covers them. Three possible places throw PipelineException . These are createStageList() , processItem() and the implied close() Not throwing any exceptions, throwing an exception from

Compile lua code, store bytecode then load and execute it

二次信任 提交于 2019-11-27 05:11:04
问题 I'm trying to compile a lua script that calls some exported functions, save the resulting bytecode to a file and then load this bytecode and execute it, but I haven't found any example on how to do this. Is there any example available on how to do this? How can I do this? Edit: I'm using Lua + Luabind (C++) 回答1: This is all very simple. First, you load the Lua script without executing it. It does not matter if you have connected the Lua state with your exported functions; all you're doing is

Avoiding getfield opcode

浪子不回头ぞ 提交于 2019-11-27 04:57:52
In Java's String class, the trim method contains this: int off = offset; /* avoid getfield opcode */ char[] val = value; /* avoid getfield opcode */ I'm a bit puzzled by the comment "avoid getfield opcode" ... What does this mean? (I take it this avoids the use of getfield in the bytecode but why is this a Good Thing [TM]?) Is it to prevent object creation in case trim doesn't do anything (and hence this is returned) or? My guess is that the point is to copy the values into local variables once, to avoid having to fetch the field value repeatedly from the heap for each iteration of the loop in

Bytecode features not available in the Java language

守給你的承諾、 提交于 2019-11-27 04:55:08
问题 Are there currently (Java 6) things you can do in Java bytecode that you can't do from within the Java language? I know both are Turing complete, so read "can do" as "can do significantly faster/better, or just in a different way". I'm thinking of extra bytecodes like invokedynamic , which can't be generated using Java, except that specific one is for a future version. 回答1: As far as I know there are no major features in the bytecodes supported by Java 6 that are not also accessible from Java

Gradle sourceCompatibility has no effect to subprojects

感情迁移 提交于 2019-11-27 03:42:32
I have Java 6 and 7 installed on my machine. Gradle uses 1.7 (checked using gradle -v ). But I need to compile my code to be compatible with Java 1.6. As far as I understand the documentation I can use the sourceCompatibility property to do so (and indirectly the targetCompatibility which defaults to the sourceCompatibility ). So I added the following line to my build file (on the root level, not in any closure): sourceCompatibility = 1.6 (to be sure I also added the targetCompatibility = 1.6 in some trials, but that should not make a difference) To check whether the result was actually

How are Scala traits compiled into Java bytecode?

為{幸葍}努か 提交于 2019-11-27 03:33:38
I have played around with Scala for a while now, and I know that traits can act as the Scala equivalent of both interfaces and abstract classes. How exactly are traits compiled into Java bytecode? I found some short explanations that stated traits are compiled exactly like Java interfaces when possible, and interfaces with an additional class otherwise. I still don't understand, however, how Scala achieves class linearization, a feature not available in Java. Is there a good source explaining how traits compile to Java bytecode? Mitch Blevins I'm not an expert, but here is my understanding:

What are advantages of bytecode over native code? [closed]

夙愿已清 提交于 2019-11-27 03:23:51
It seems like anything you can do with bytecode you can do just as easily and much faster in native code. In theory, you could even retain platform and language independence by distributing programs and libraries in bytecode then compiling to native code at installation, rather than JITing it. So in general, when would you want to execute bytecode instead of native? Hank Shiffman from SGI said (a long time ago, but it's till true): There are three advantages of Java using byte code instead of going to the native code of the system: Portability : Each kind of computer has its unique instruction

What is a stack map frame

穿精又带淫゛_ 提交于 2019-11-27 02:32:30
I've recently been looking at The Java Virtual Machine Specifications (JVMS) to try to better understand the what makes my programs work, but I've found a section that I'm not quite getting... Section 4.7.4 describes the StackMapTable Attribute, and in that section the document goes into details about stack map frames. The issue is that it's a little wordy and I learn best by example; not by reading. I understand that the first stack map frame is derived from the method descriptor, but I don't understand how (which is supposedly explained here .) Also, I don't entirely understand what the

Find out which classes of a given API are used

蓝咒 提交于 2019-11-27 01:38:23
In a Java Project of mine, I would like to find out programmatically which classes from a given API are used. Is there a good way to do that? Through source code parsing or bytecode parsing maybe? Because Reflection won't be of any use, I'm afraid. To make things simpler: there are no wildcard imports ( import com.mycompany.api.*; ) anywhere in my project, no fully qualified field or variable definitions ( private com.mycompany.api.MyThingy thingy; ) nor any Class.forName(...) constructs. Given these limitations, it boils down to parsing import statements, I guess. Is there a preferred

Compiler optimization: Java bytecode

喜夏-厌秋 提交于 2019-11-27 01:10:16
问题 I'm currently writing a toy compiler targeting Java bytecode in the translation. I would like to know if there is some kind of catalog, maybe a summary, of various simple peephole optimizations that can be made in the emitted bytecode before writing the .class file. I actually am aware of some libraries that have this functionality, but I'd like to implement that myself. 回答1: You are aware of Proguard? http://proguard.sourceforge.net/ This is a great bytecode optimizer which implements a lot