bytecode

Remapper variables during bytecode method inlining by ASM

一世执手 提交于 2019-12-03 06:48:01
I am doing an online bytecode method inlining optimization using ASM. My changes are based on the example 3.2.6 Inline Method ( http://asm.ow2.org/current/asm-transformations.pdf ). The test example (inline callee's calculate(int,int) at Caller::test) is: public class Caller { final Callee _callee; public Caller(Callee callee){ _callee = callee; } public static void main(String[] args) { new Caller(new Callee("xu", "shijie")).test(5, 100); } public void test(int a, int b){ int t = a; int p = b; int r = t+p-_callee.calculate(a, b); int m = t-p; System.out.println(t); } } public class Callee {

Pushing variables to Stack and Variables living in the Stack difference?

混江龙づ霸主 提交于 2019-12-03 05:45:45
So I know that there exists 2 memory areas: Stack and Heap . I also know that if you create a local variable it will live in the Stack, not in the heap. Stack will grow as we push data into it as in: Now I will try to pass the confusion I am having to you: For example this simple Java Code: public class TestClass { public static void main(String[] args) { Object foo = null; Object bar = null; } } is translated into this byte code: public static void main(java.lang.String[]); Code: Stack=1, Locals=3, Args_size=1 0: aconst_null 1: astore_1 2: aconst_null 3: astore_2 4: return LineNumberTable:

Why does a class definition always produce the same bytecode?

 ̄綄美尐妖づ 提交于 2019-12-03 05:44:53
Say I do: #!/usr/bin/env python # encoding: utf-8 class A(object): pass Now I disassemble it: python -m dis test0.py 4 0 LOAD_CONST 0 ('A') 3 LOAD_NAME 0 (object) 6 BUILD_TUPLE 1 9 LOAD_CONST 1 (<code object A at 0x1004ebb30, file "test0.py", line 4>) 12 MAKE_FUNCTION 0 15 CALL_FUNCTION 0 18 BUILD_CLASS 19 STORE_NAME 1 (A) 22 LOAD_CONST 2 (None) 25 RETURN_VALUE Now I add some statements in the class definition: #!/usr/bin/env python # encoding: utf-8 class A(object): print 'hello' 1+1 pass And I disassemble again: 4 0 LOAD_CONST 0 ('A') 3 LOAD_NAME 0 (object) 6 BUILD_TUPLE 1 9 LOAD_CONST 1 (

Generate .pyc from Python AST?

孤街醉人 提交于 2019-12-03 05:34:53
How would I generate a .pyc file from a Python AST such that I could import the file from Python? I've used compile to create a code object, then written the co_code attribute to a file, but when I try to import the file from Python, I get an ImportError: Bad magic number in output.pyc . exupero The solution can be adapted from the py_compile module: import marshal import py_compile import time import ast codeobject = compile(ast.parse('print "Hello World"'), '<string>', 'exec') with open('output.pyc', 'wb') as fc: fc.write('\0\0\0\0') py_compile.wr_long(fc, long(time.time())) marshal.dump

How to create a code object in python?

核能气质少年 提交于 2019-12-03 04:22:26
问题 I'd like to create a new code object with the function types.CodeType() . There is almost no documentation about this and the existing one says "not for faint of heart" Tell me what i need and give me some information about each argument passed to types.CodeType , possibly posting an example. Note : In normal use cases you will just need the builtin function compile() You should use types.CodeType() only if you want to create new instructions that couldn't be obtained writing normal source

Java - Is binary code the same as ByteCode?

烈酒焚心 提交于 2019-12-03 04:16:44
问题 In Java, does "binary code" means the same as "Java bytecode?" Is this the flow in Java ? Java File (.java) -> [javac] -> ByteCode File (.class) -> [JVM/Java Interpreter] -> Running it(by first converting it into binary code specific to the machine) Thanks! 回答1: The answer depends on what you mean by binary code . Java bytecode is a binary data format that includes loading information and execution instructions for the Java virtual machine. In that sense, Java bytecode is a special kind of

How to read python bytecode?

 ̄綄美尐妖づ 提交于 2019-12-03 03:51:11
问题 I am having a lot of difficulty understanding Python's bytecode and its dis module. import dis def func(): x = 1 dis.dis(func) The above code when typed in the interpreter produces the following output: 0 LOAD_CONST 1(1) 3 STORE_FAST 0(x) 6 LOAD_CONST 0(NONE) 9 RETURN_VALUE E.g.: What is the meaning of LOAD_CONST , STORE_FAST and the numbers like 0 , 3 , 6 and 9 ? A specific resource, where I can find this information would be much appreciated. 回答1: The numbers before the bytecodes are

How does an interpreter interpret the code?

大城市里の小女人 提交于 2019-12-03 03:43:38
问题 For simplicity imagine this scenario, we have a 2-bit computer, which has a pair of 2 bit registers called r1 and r2 and only works with immediate addressing. Lets say the bit sequence 00 means add to our cpu. Also 01 means move data to r1 and 10 means move data to r2. So there is an Assembly Language for this computer and a Assembler, where a sample code would be written like mov r1,1 mov r2,2 add r1,r2 Simply, when I assemble this code to native language and the file will be something like:

Understanding Java Byte Code

时间秒杀一切 提交于 2019-12-03 02:25:54
问题 Often I am stuck with a java class file with no source and I am trying to understand the problem I have at hand. Note a decompiler is useful but not sufficient in all situation... I have two question What tools are available to view java byte code (preferably available from the linux command line ) What are good references to get familiar with java byte code syntax 回答1: Rather than looking directly at the Java bytecode, which will require familiarity with the Java virtual machine and its

Learning about Java bytecode and the JVM

末鹿安然 提交于 2019-12-03 01:42:55
问题 In a recent question asked recently my simple minded answer highlighted many of my misconceptions about Java, the JVM, and how the code gets compiled and run. This has created a desire in me to take my understanding to a lower level. I have no problems with the low level understanding like assembly how ever bytecode and the JVM confound me. How object oriented code gets broken down on a low level is lost to me. I was wondering if anyone had any suggestion on how to learn about the JVM,