bytecode

How is scala generating byte code? Using some libraries like ASM, or write binary directly?

Deadly 提交于 2019-11-27 00:57:35
问题 I'm wondering how is scala generating byte code, does it use some libraries like ASM? Or just write binary to .class files for performance? 回答1: Starting with 2.10 the Scala compiler uses ASM 4 to emit bytecode, supporting -target:jvm-1.5 , -target:jvm-1.6 , and -target:jvm-1.7 Implementation aspects of the backend are described in: Emitting Scala classfiles via ASM http://lamp.epfl.ch/~magarcia/ScalaCompilerCornerReloaded/2012Q2/GenASM.pdf The bytecode emitter (GenASM, source linked below)

How to identify a missing method (Binary Compatibility) in a JAR statically

自古美人都是妖i 提交于 2019-11-27 00:56:49
问题 I want to verify binary compatibility between 2 JARs. Following the suggestions in this answer I used jboss tattletale but it can find only missing classes. How can I find if there are missing methods? Is it possible at all? E.g. "Depends - on" class Foo depends on Bar (like many other middle class workers) import org.overlyusedclassnames.Bar public class Foo{ public void someMethod(){ Bar tender = new Bar(); tender.getJohnnyRedLabel(); tender.getJohnnyBlueLabel(); //this method is new in the

Difference between JVM's LookupSwitch and TableSwitch?

梦想与她 提交于 2019-11-26 23:55:56
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 The difference is that a lookupswitch uses a table with keys and labels , yet a tableswitch uses a table with labels only . When performing a tableswitch , the int value on top of stack is directly used as an index into the table to grab the jump destination and perform the jump immediately. The

How many objects are created

a 夏天 提交于 2019-11-26 22:19:03
问题 I was having a discussion about usage of String s and StringBuffer s in Java. How many objects are created in each of these two examples? Ex 1: String s = "a"; s = s + "b"; s = s + "c"; Ex 2: StringBuilder sb = new StringBuilder("a"); sb.append("b"); sb.append("c"); In my opinion, Ex 1 will create 5 and Ex 2 will create 4 objects. 回答1: You can determine the answer by analyzing the java bytecode (use javap -c ). Example 1 creates two StringBuilder objects (see line #4) and two String objects

What is the Java 7 try-with-resources bytecode equivalent using try-catch-finally?

给你一囗甜甜゛ 提交于 2019-11-26 19:45:34
问题 I'm trying to understand how the new try-with-resources statement works by recreating it using regular try-catch-finally statements. Given the following test class using Java 7 try-with-resources: import java.io.IOException; import java.util.zip.GZIPOutputStream; public class TryWithResources { public static void main(String[] args) { try (GZIPOutputStream gzip = new GZIPOutputStream(System.out)) { gzip.write("TEST".getBytes("UTF-8")); } catch (IOException ioe) { ioe.printStackTrace(); } } }

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

旧巷老猫 提交于 2019-11-26 18:56:58
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(bytecode) at runtime (dynamically) I do a basic search and found many lib including Apache BCEL But I

is it possible to disable javac's inlining of static final variables?

老子叫甜甜 提交于 2019-11-26 18:48:55
The Java static compiler (javac) inlines some static final variables and brings the values directly to the constant pool. Consider the following example. Class A defines some constants (public static final variables): public class A { public static final int INT_VALUE = 1000; public static final String STRING_VALUE = "foo"; } Class B uses these constants: public class B { public static void main(String[] args) { int i = A.INT_VALUE; System.out.println(i); String s = A.STRING_VALUE; System.out.println(s); } } When you compile class B, javac gets the values of these constants from class A and

How is pattern matching in Scala implemented at the bytecode level?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 18:47:31
问题 How is pattern matching in Scala implemented at the bytecode level? Is it like a series of if (x instanceof Foo) constructs, or something else? What are its performance implications? For example, given the following code (from Scala By Example pages 46-48), how would the equivalent Java code for the eval method look like? abstract class Expr case class Number(n: Int) extends Expr case class Sum(e1: Expr, e2: Expr) extends Expr def eval(e: Expr): Int = e match { case Number(x) => x case Sum(l,

What Java compilers use the jsr instruction, and what for?

末鹿安然 提交于 2019-11-26 16:50:45
问题 The Java bytecode language has the JSR instruction. None of the code I've compiled with the Java 7 compiler uses this instruction. However, sometimes Java binaries I've downloaded do use it, although rarely. I'd be interested to know what compilers do use the instruction, and what Java code constructs would cause them to use it. Edit this is not a duplicate as it refers to the JSR bytecode instruction and not a Java Specification Request 回答1: The JSR instruction is actually not even allowed

Check if Java bytecode contains debug symbols

断了今生、忘了曾经 提交于 2019-11-26 16:40:39
问题 I would like to know how can I check if a compiled Java class contains debug symbols. The problem is that I compile an application from ant with debug="on", but a specific JVM throws an exception: it says that the debug symbols are missing. Thanks. 回答1: If you run javap -v on the class file, you will see the debug information that is present in the file. It is worth compiling a simple test class with different -g option settings and looking at the results with javap . If, you need to know