bytecode

Relation between bytecode instructions and processor operations

人盡茶涼 提交于 2019-12-03 12:29:51
问题 Java specification guarantees primitive variable assignments are always atomic (expect for long and double types . On the contrary, Fetch-and-Add operation corresponding to the famous i++ increment operation, would be non-atomic because leading to a read-modify-write operation. Assuming this code: public void assign(int b) { int a = b; } The generated bytecode is: public void assign(int); Code: 0: iload_1 1: istore_2 2: return Thus, we see the assignment is composed of two steps (loading and

Generating methods with generic types with Asm bytecode generator (ClassWriter)

时光毁灭记忆、已成空白 提交于 2019-12-03 11:52:32
Defining simple getters and setters is easy using Asm (and fortunately it is even explained in their FAQ). But one thing that is not mentioned, and for which I have been unable to find documentation, is how to implement these using generic type information. I am actually able to determine generic type information itself quite easily (since code will take existing fields and/or methods and full generic type handling and resolution exists). I just need to generate generics version for types that have generic type included. I hope this is something as easy as modifying signature Asm ClassWriter

Is it possible to implement an interface at runtime in Java?

ぃ、小莉子 提交于 2019-12-03 09:41:16
问题 I am working on a project where there are a lot of objects that are created by a library, and I have no access to the creation process of these objects. The following snippets serve as a good example to illustrate my problem. Code: public class Clazz { //The contents of Clazz are irrelevant //Clazz is NOT my class. I have no access to its internal structure. //However, I do have access to Clazz objects that were created elsewhere. } ExampleInterface is an interface that Clazz may or may not

What are motivations behind compiling to byte-code?

与世无争的帅哥 提交于 2019-12-03 09:13:15
问题 I'm working on my own toy programming language. For now I'm interpreting the source language from AST and I'm wondering what advantages compiling to a byte-code and then interpreting it could provide me. For now I have three things in mind: Traversing the syntax tree hundreds of time may be slower than running instructions in an array, especially if the array support O(1) random access(ie. jumping 10 instructions up and down). In typed execution environment, I have some run-time costs because

What kind of Java code requires stackmap frames?

拈花ヽ惹草 提交于 2019-12-03 09:00:46
问题 I'm trying to write a unit tests for a workaround to an issue about missing stackmap frames, but for that purpose I will need to generate a class that will fail to validate on Java 8 if it's missing stackmap frames. Below you can see my test case (dependencies: ASM, Guava, JUnit). It removes the stackmap frames from the GuineaPig class in hopes of causing its bytecode to fail to validate. The part that I'm having problems with is filling in the TODO in GuineaPig with minimal code that

Why is it so easy to decompile .NET IL code?

别等时光非礼了梦想. 提交于 2019-12-03 08:54:03
问题 Why is it so easy to decompile .NET IL-code into source code, compared to decompiling native x86 binaries? (Reflector produces quite good source code most of the time, while decompiling the output of a C++ compiler is almost impossible.) Is it because IL contains a lot of meta data? Or is it because IL is a higher abstraction than x86 instructions? I did some research and found the following two usefull articles, but neither of them answers my question. MSIL Decompiler Theory C Decompiler -

Intercepting calls to Java 8 lambda-expressions using Byte Buddy

隐身守侯 提交于 2019-12-03 08:18:54
I try to intercept calls to methods and calls to Java 8 lambda expressions using a Byte Buddy AgentBuilder as follows: static { final Instrumentation inst = ByteBuddyAgent.install(); new AgentBuilder.Default() .type(ElementMatchers.nameContainsIgnoreCase("foo")) .transform((builder, typeDescription) -> builder.method(ElementMatchers.any()) .intercept(MethodDelegation.to(LogInterceptor.class))) .installOn(inst); } public static class LogInterceptor { @RuntimeType public static Object log(@SuperCall Callable<?> superCall) throws Exception { System.out.println("yeah..."); return superCall.call();

Java bytecode equivalents for ilasm / ildasm

余生长醉 提交于 2019-12-03 08:07:02
For CIL / MSIL, I can write the code in a text editor and compile / decompile with ilasm / ildasm. I can use Reflector to see the CIL generated by a .NET class. In the Java world, javap -c shows the disassembled byte code. How do I compile Java bytecode? (i.e. the Java equivalent of ilasm / ildasm). Is there an IDE that supports Java bytecode? Does the IDE support debugging i.e. single stepping / breakpoints etc.? Bytecode Outline plugin for Eclipse to play with bytecode you can use ASM or BCEL Take a look at org.apache.bcel.util.BCELifier, it takes a given class and converts it to a BCEL

How to strip source from distutils binary distributions?

ぃ、小莉子 提交于 2019-12-03 07:49:37
I want to create a bytecode-only distribution from distutils (no really, I do; I know what I'm doing). Using setuptools and the bdist_egg command, you can simply provide the --exclude-source parameter. Unfortunately the standard commands don't have such an option. Is there an easy way to strip the source files just before the tar.gz, zip, rpm or deb is created. Is there a relatively clean per-command way to do this (eg just for tar.gz or zip). The distutils "build_py" command is the one that matters, as it's (indirectly) reused by all the commands that create distributions. If you override the

Developing a heuristic to test simple anonymous Python functions for equivalency

北城以北 提交于 2019-12-03 07:20:40
问题 I know how function comparison works in Python 3 (just comparing address in memory), and I understand why. I also understand that "true" comparison (do functions f and g return the same result given the same arguments, for any arguments?) is practically impossible. I am looking for something in between. I want the comparison to work on the simplest cases of identical functions, and possibly some less trivial ones: lambda x : x == lambda x : x # True lambda x : 2 * x == lambda y : 2 * y # True