bytecode

Change reference to function in run-time in Python

随声附和 提交于 2019-12-04 07:53:21
I need to change a call to a function inside another function during run-time. Consider the following code: def now(): print "Hello World!" class Sim: def __init__(self, arg, msg): self.msg = msg self.func = arg self.patch(self.func) def now(self): print self.msg def run(self): self.func() def patch(self, func): # Any references to the global now() in func # are replaced with the self.now() method. def myfunc(): now() Then ... >>> a = Sim(myfunc, "Hello Locals #1") >>> b = Sim(myfunc, "Hello Locals #2") >>> b.run() Hello Locals #2 >>> a.run() Hello Locals #1 One user has written code, myfunc()

What does “()V” mean in a class signature?

不想你离开。 提交于 2019-12-04 07:48:33
问题 I created a constructor with Javassist which has no real method CtConstructor c = CtNewConstructor.make ( argTypes, null, newClass ); When I'm trying to put out the signature of this class c.getSignature(); I get public Echo ()V I'm confused what "V" means? I expected either public Echo (); or something similar... 回答1: The JVM uses a compact way of storing method signatures, of which constructors are considered a special case. For your example: () indicates a method taking no arguments V

Why is a .class file not human readable? [closed]

。_饼干妹妹 提交于 2019-12-04 07:05:58
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . When a java file is compiled, it generates a .class file. Now this .class file has the bytecode which the JVM interprets. when we open the .class file in a text editor, it is not human readable. Now to view the bytecode a disassembler like javap can be used. My question is, why do

Is it possible to explicitly free memory with JVM Bytecode?

 ̄綄美尐妖づ 提交于 2019-12-04 06:12:24
There are several computer programming languages using JVM bytecode as, lets say, target language for their interpreter/compilers. It seems to me that many new programming languages (less than 15 years old) run over JVM and I wonder whether explicit memory deallocation is forbidden for all of them: Is it possible to explicitly allocate-deallocate memory using in bytecode through any instruction? Is, on de contrary, the garbage collector always resposible for memory liberation? The JVM abstracts away all memory management. There is no bytecode for memory deallocation, just as there is no

Determining in the bytecode where is the super() method call all constructors must do on the JVM

和自甴很熟 提交于 2019-12-04 03:52:49
I was wondering if there's an obvious and quick way of when analyzing a constructor's bytecode, to determine where the super() code ends in. More concretely, and in sharp contrast to Java, where a call in the constructor to any super() constructor method is optional (or rather, when not present -- implicit), in the bytecode world it is always needed. For black magic purposes I'm in need of knowing just by bytecode analysis and by the simplest method available, what's the INVOKESPECIAL call that corresponds to the Java world's super() call. I'll leave you here with a hard example: public static

java decompilation

邮差的信 提交于 2019-12-04 03:50:37
When decompiling a specific jar using java decompiler (http://java.decompiler.free.fr/) I got some strange code I cannot identify what is. can someone help me? the code is something like: Foo.access$004(Foo.this); or this Bar.access$006(Bar.this); or else Baz.access$102(Baz.this, true) What are these methods access$004 , access$006 and access$102 ? Synthetic methods like this get created to support acessing private methods of inner classes. Since inner classes were not part of the initial jvm version, the access modifiers could not really handle this case. The solution was to create additional

Why isn't null a compile time constant?

心已入冬 提交于 2019-12-04 02:53:58
问题 So if I have a static final Object CONSTANT = null , for some reason if I reference that in another piece of code like doSomething(CONSTANT) , it won't be in-lined onto the code during compilation. So instead of being doSomething(null) after being compiled, it would be doSomething(CONSTANT) . 回答1: Your CONSTANT is not a compile time constant because the JLS says it is not. The only types that can be used in constant expressions are the primitive types and String . The sense of it is that an

Java Bytecode DUP

女生的网名这么多〃 提交于 2019-12-04 02:34:42
I am wondering why the Exception in the following bytecode (used to throw an Exception) is duplicated. NEW java/lang/IllegalArgumentException DUP INVOKESPECIAL java/lang/IllegalArgumentException <init> ()V ATHROW I'll analyze this line by line where [] = new stack after that op is used: NEW puts a new IllegalArgumentException onto the stack [SomeIllegalArgumentException] DUP duplicates it [SomeIllegalArgumentException, SomeIllegalArgumentException] INVOKESPECIAL pops off the top one and initializes it by calling it's <init> method [SomeIllegalArgumentException] (The init method will not return

Differences in java bytecode produced by Oracle's and Eclipse's compilers

耗尽温柔 提交于 2019-12-04 01:10:22
Our project does some Java bytecode instrumentation. And we stumbled upon some strange behavior. Suppose the following code snippet: public void a() { new Integer(2); } Oracle's javac compiles the above into the following bytecode: 0: new #2; //class java/lang/Integer 3: dup 4: iconst_2 5: invokespecial #3; //Method java/lang/Integer."<init>":(I)V 8: pop 9: return and Eclipse's compiler into: 0: new #15; //class java/lang/Integer 3: iconst_2 4: invokespecial #17; //Method java/lang/Integer."<init>":(I)V 7: return As you can see, Oracle compiler produces "dup" after "new", whereas Eclipse doesn

Number of instructions in JVM

假装没事ソ 提交于 2019-12-03 22:44:56
I was asked the following question in an exam today. I still don't know the answer. Java uses stack for byte code in JVM. Each instruction is of one byte, so how many such instructions (per byte code) are possible in an operating system. All I know is that the stack is 32 bits wide. Can anybody help me (I am a beginner in JVM)? The expected answer was almost certainly 256, because there are 256 possible values of a byte. This of course has nothing to do with the actual JVM instruction set. The number of possible instructions can vary anywhere from a couple dozen to an exponentially large