bytecode

How to generate bytecode and save to .class file?

陌路散爱 提交于 2019-12-10 03:05:59
问题 I have the following weird requirement. I am given: A list of some method names. Names and types of parameters of the above methods. The functionality of the above methods. This is as follows: For each parameter, the method converts it to string using toString and obtains an array of strings. To this array, the method applies a function foo . The function foo takes as input a String [] type and outputs String . The methods return what foo returns. foo 's code is given inside a Java object and

java decompilation

倖福魔咒の 提交于 2019-12-09 16:16:11
问题 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 ? 回答1: Synthetic methods like this get created to support acessing private methods of inner classes. Since inner classes were not part of the

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

怎甘沉沦 提交于 2019-12-09 16:12:02
问题 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

How Translate ByteCode to Machine Native Code

浪子不回头ぞ 提交于 2019-12-09 16:08:09
问题 I am looking for a translator for translate Java ByteCode to Machine Native Code before execution to improve performance. I heard that OpenOffice is made with JAVA, but I can't see any jar file in his installation folder, therefore, maybe there is a translator but I can't find it. Does anyone know some tool or comercial product to do that? Thanks! 回答1: There are multiple solutions. All are not ideal. Take a look here (exe4j). To learn more read this article. 回答2: Give a look to Avian JVM. See

When is the JVM bytecode access modifier flag 0x1000 (hex) “synthetic” set?

懵懂的女人 提交于 2019-12-09 15:41:57
问题 For some Java byte code parser project I read the JVM spec and figured out that the bit mask values of the Java virtual machine class file format access modifier fields are ACC_PUBLIC = 0x0001 ACC_FINAL = 0x0010 ACC_SUPER = 0x0020 # old invokespecial instruction semantics (Java 1.0x?) ACC_INTERFACE = 0x0200 ACC_ABSTRACT = 0x0400 ACC_SYNTHETIC = 0x1000 ACC_ANNOTATION = 0x2000 ACC_ENUM = 0x4000 Somehow I have no idea what 0x1000 is for. I saw it once in an inner class, but for all inner classes

Inject a function into a Java .class file using Haskell

爱⌒轻易说出口 提交于 2019-12-09 10:53:59
问题 I have written a Java bytecode parser using Haskell, and it works just fine. However the next step has me completely stumped. My Haskell program needs to modify the .class file so that, when executed, the Java program prints: " Entering [method name here] " before executing a method, and " Exiting [method name here] " after executing a method. All I know is that we will need to append the constant pool and method table with calls to System.out.println , but I feel I'm still missing something.

ByteBuddy fails when trying to redefine sun.reflect.GeneratedMethodAccessor1

点点圈 提交于 2019-12-09 04:27:27
Driven by curiosity, I tried to export the bytecode of GeneratedMethodAccessor1 (generated by the JVM when using reflection). I try to get the bytecode of the class the following way: public class MethodExtractor { public static void main(String[] args) throws Exception { ExampleClass example = new ExampleClass(); Method exampleMethod = ExampleClass.class .getDeclaredMethod("exampleMethod"); exampleMethod.setAccessible(true); int rndSum = 0; for (int i = 0; i < 20; i++) { rndSum += (Integer) exampleMethod.invoke(example); } Field field = Method.class.getDeclaredField("methodAccessor"); field

What are the difference between byte code and bit code [duplicate]

风格不统一 提交于 2019-12-08 18:56:31
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: What are the differences between LLVM and java bytecode? For example, in LLVM, it said.. What is commonly known as the LLVM bitcode file format (also, sometimes anachronistically known as bytecode) is actually two things: a bitstream container format and an encoding of LLVM IR into the container format. I only know Java Bytecode which is platform independent which can be run by the JVM But for the LLVM bit code,

Why does java bytecode “store” often followed by “load”?

会有一股神秘感。 提交于 2019-12-08 18:12:43
问题 When I read jvm bytecode which from some small java function, I found that when a new local variable is caculated on the operand stack, assuming that it will be stored in the local variable table, but usually it will be loaded to the operand stack immediately (just in the terms of bytecode literally). I don't understand the operation well, is it unnecessary operation? 回答1: The Java compiler tends to compile things in a very simple and straightforward manner, leaving optimization to the JIT.

Intelligent solution to computing jump addresses in a bytecode compiler?

纵饮孤独 提交于 2019-12-08 17:41:48
问题 Let's say I'm implementing a bytecode compiler, similar to Lua's/Python's... so on. I'm traversing the AST, generating bytecode instructions, and I run into a break inside of an if-else inside of a while loop: while (cond1) if (cond2) ... else break (I tried writing out equivalent bytecode but it didn't look too helpful.) The point is, there are at least 4 "jump" instructions in that example, and I want to find an elegant solution to filling in the jump addresses as I compile the AST... I don