bytecode

Java's Virtual Machine and CLR

大憨熊 提交于 2019-11-26 11:44:58
问题 As a sort of follow up to the question called Differences between MSIL and Java bytecode?, what is the (major) differences or similarity in how the Java Virtual Machine works versus how the .NET Framework Common Language Runtime (CLR) works? Also, is the .NET framework CLR a \"virtual machine\" or does it not have the attributes of a virtual machine? 回答1: There are a lot of similarities between both implementations (and in my opinion: yes, they're both "virtual machines"). For one thing, they

Gradle sourceCompatibility has no effect to subprojects

≯℡__Kan透↙ 提交于 2019-11-26 10:39:33
问题 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

How are Scala traits compiled into Java bytecode?

血红的双手。 提交于 2019-11-26 10:33:18
问题 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

What is a stack map frame

我们两清 提交于 2019-11-26 10:09:16
问题 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

Avoiding getfield opcode

江枫思渺然 提交于 2019-11-26 09:54:20
问题 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? 回答1: My guess is that the point is to copy the values into local

Find out which classes of a given API are used

限于喜欢 提交于 2019-11-26 09:44:37
问题 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.

What are bytecodes and how does the JVM handle them

一曲冷凌霜 提交于 2019-11-26 09:39:40
问题 I heard many times that Java implemments JIT(just-in-time) compilation, and its bytecodes which are portable across platforms get \"interpreted\" by JVM. However, I don\'t really know what the bytecodes are, and what the JVM actually mean in Java language architecture; I would like to know more about them. 回答1: The JVM (Java Virtual Machine) has an instruction set just like a real machine. The name given to this instruction set is Java Bytecode. It is described in the Java Virtual Machine

Does unused import and objects have an performance impact

大兔子大兔子 提交于 2019-11-26 09:38:31
问题 I have a doubt, whether the unused imports and unused objects in Java code creates any performance impact? Suppose an object is initialized and never used, what happens? And what is the cost of unused imports 回答1: Its a very common question. Like most performance questions the best approach is to write the clearest and simplest code you can as this improves the maintainability of the code and helps ensure it performs reasonably well even after it is changed. (Clever/Obtuse/Needlessly Verbose

Difference between JVM's LookupSwitch and TableSwitch?

假装没事ソ 提交于 2019-11-26 07:18:05
问题 I have some difficulty to understand LookUpSwitch and TableSwitch in Java bytecode. If I understand well, both LookUpSwitch and TableSwitch correspond to the switch statement of Java source? Why one JAVA statement generates 2 different bytecodes? Jasmin documentation of each: LookupSwitch tableswitch 回答1: The difference is that lookupswitch uses a table with keys and labels tableswitch uses a table with labels only . When performing a tableswitch , the int value on top of stack is directly

Create simple POJO classes (bytecode) at runtime (dynamically)

 ̄綄美尐妖づ 提交于 2019-11-26 06:41:40
问题 I\'ve the following scenario.. I am writing some tool that run user-entered query against the database and return the result.. The simplest way is to return the result as: List<String[]> but I need to take this a step further. I need to create (at runtime ) some POJO (or DTO) with some name and create fields and setters and getters for it and populate it with the data returned and then return it to the user among with the .class file generated... So the idea here is How to Create simple class