bytecode

Rewriting Java native methods using ASM

*爱你&永不变心* 提交于 2021-02-07 04:55:30
问题 I'm trying to do this by re-writing the bytecode of the class using ASM 4.0 to replace all the native methods with non- native stubs. So far I have this: class ClassAdapter extends ClassVisitor { public ClassAdapter(ClassVisitor cv) { super(Opcodes.ASM4, cv); } @Override public MethodVisitor visitMethod(int access, String base, String desc, String signature, String[] exceptions) { return cv.visitMethod(access & ~Opcodes.ACC_NATIVE, base, desc, signature, exceptions); } } which is executed by

Same bytecode for method with or without synchronized keyword in method signature

痞子三分冷 提交于 2021-02-05 06:56:25
问题 For the following 2 classes got the same Java bytecode. java version: java version "1.8.0_181" Java(TM) SE Runtime Environment (build 1.8.0_181-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode) javac and javap version: 1.8.0_181 My doubt is shouldn't method with synchronized keyword have different bytecode as we can see in synchronized block has monitorenter and monitorexit , or let us assume I should not mix synchronized block and synchronized method then How does JVM

Java LineNumberTable: Entry explanation

不打扰是莪最后的温柔 提交于 2021-02-04 21:39:32
问题 If I disassemble my class file, I get LineNumberTables of the form LineNumberTable: line 204: 0 line 205: 9 line 208: 57 line 209: 63 line 210: 72 line 211: 75 line 212: 78 line 213: 87 line 216: 90 line 218: 118 line 221: 126 line 222: 131 line 223: 138 line 224: 143 line 227: 150 line 230: 157 line 231: 160 line 232: 170 line 235: 194 line 237: 228 line 240: 249 line 241: 259 line 243: 266 line 245: 269 line 246: 292 line 248: 295 line 249: 301 line 250: 308 line 251: 315 line 252: 322 line

Java ByteCode arithmetic operation

守給你的承諾、 提交于 2021-01-29 18:19:54
问题 I'm going to make a simple compiler for a school project, i want generate .class file, i read the file format but to understand better the .class file format and the java bytecode i have this class: public class Me { public void myMethod() { int a = 5 * 4 + 3 - 2 + 1 / 7 + 28; } } with javap command i get this(for 'myMethod'): public void myMethod(); flags: ACC_PUBLIC Code: stack=1, locals=2, args_size=1 0: bipush 49 2: istore_1 3: return LineNumberTable: line 3: 0 line 4: 3

Why does Java have an IINC bytecode instruction?

前提是你 提交于 2021-01-29 03:37:48
问题 Why does Java have an IINC bytecode instruction? There is already an IADD bytecode instruction that can be used to accomplish the same. So why does IINC exist? 回答1: Only the original designers of Java can answer why they made particular design decisions. However, we can speculate: IINC does not let you do anything that can't already be accomplished by a ILOAD / SIPUSH / IADD / ISTORE combo. The difference is that IINC is a single instruction, which only takes 3 or 6 bytes, while the 4

Modify java.util class using byte-buddy-agent

隐身守侯 提交于 2021-01-28 15:07:30
问题 Is it possible to add a field in java.util class using byte-buddy? I am trying to add a field in java.util.concurrent.FutureTask and intercept constructor and an arbitrary method to set and get the field value. In short, I am trying to add a field to FutureTask so that I can pass some value to child thread from parent even if they are running in a thread pool. isn't it possible to add a field in FutureTask? FutureTaskTransofrmer @Override protected ElementMatcher.Junction<TypeDescription>

Modify java.util class using byte-buddy-agent

旧巷老猫 提交于 2021-01-28 15:05:34
问题 Is it possible to add a field in java.util class using byte-buddy? I am trying to add a field in java.util.concurrent.FutureTask and intercept constructor and an arbitrary method to set and get the field value. In short, I am trying to add a field to FutureTask so that I can pass some value to child thread from parent even if they are running in a thread pool. isn't it possible to add a field in FutureTask? FutureTaskTransofrmer @Override protected ElementMatcher.Junction<TypeDescription>

Modify java.util class using byte-buddy-agent

白昼怎懂夜的黑 提交于 2021-01-28 15:02:56
问题 Is it possible to add a field in java.util class using byte-buddy? I am trying to add a field in java.util.concurrent.FutureTask and intercept constructor and an arbitrary method to set and get the field value. In short, I am trying to add a field to FutureTask so that I can pass some value to child thread from parent even if they are running in a thread pool. isn't it possible to add a field in FutureTask? FutureTaskTransofrmer @Override protected ElementMatcher.Junction<TypeDescription>

Modify java.util class using byte-buddy-agent

萝らか妹 提交于 2021-01-28 15:01:00
问题 Is it possible to add a field in java.util class using byte-buddy? I am trying to add a field in java.util.concurrent.FutureTask and intercept constructor and an arbitrary method to set and get the field value. In short, I am trying to add a field to FutureTask so that I can pass some value to child thread from parent even if they are running in a thread pool. isn't it possible to add a field in FutureTask? FutureTaskTransofrmer @Override protected ElementMatcher.Junction<TypeDescription>

How to handle the unsigned types (especially u4) of a Java class file in a Java program?

本小妞迷上赌 提交于 2021-01-28 05:54:39
问题 From the Java Virtual Machine specification: A class file consists of a stream of 8-bit bytes. All 16-bit, 32-bit, and 64-bit quantities are constructed by reading in two, four, and eight consecutive 8-bit bytes, respectively. Multibyte data items are always stored in big-endian order, where the high bytes come first. In the Java platform, this format is supported by interfaces java.io.DataInput and java.io.DataOutput and classes such as java.io.DataInputStream and java.io.DataOutputStream.