Skip to content

Commit

Permalink
bugfix for segfault on Method.getName()
Browse files Browse the repository at this point in the history
the bug was caused by the fact that we used to use "ALOAD 1" although there is not even a local variable 1 in this context (getName() takes no arguments)
  • Loading branch information
Eric Bodden authored and Eric Bodden committed Jan 29, 2012
1 parent 620ae20 commit 2b3b338
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
******************************************************************************/
package de.bodden.tamiflex.playout.transformation.method;

import static org.objectweb.asm.Opcodes.ACONST_NULL;
import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.GETSTATIC;
import static org.objectweb.asm.Opcodes.INVOKESTATIC;
Expand Down Expand Up @@ -37,7 +38,7 @@ protected MethodVisitor getMethodVisitor(MethodVisitor parent) {
@Override
public void visitInsn(int opcode) {
if (IRETURN <= opcode && opcode <= RETURN) {
mv.visitVarInsn(ALOAD, 1); // Load designated receiver
mv.visitInsn(ACONST_NULL); //ignore first argument to method methodMethodInvoke
mv.visitVarInsn(ALOAD, 0); // Load Method instance
mv.visitFieldInsn(GETSTATIC, "de/bodden/tamiflex/playout/rt/Kind", methodKind().name(), Type.getDescriptor(Kind.class));
mv.visitMethodInsn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public MethodGetNameTransformation() {
protected Kind methodKind() {
return MethodGetName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
package de.bodden.tamiflex.playout.transformation.method;

import static de.bodden.tamiflex.playout.rt.Kind.MethodInvoke;
import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.GETSTATIC;
import static org.objectweb.asm.Opcodes.INVOKESTATIC;
import static org.objectweb.asm.Opcodes.IRETURN;
import static org.objectweb.asm.Opcodes.RETURN;

import org.objectweb.asm.MethodAdapter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.Method;

import de.bodden.tamiflex.playout.rt.Kind;
Expand All @@ -27,4 +35,26 @@ protected Kind methodKind() {
return MethodInvoke;
}

@Override
protected MethodVisitor getMethodVisitor(MethodVisitor parent) {
return new MethodAdapter(parent) {

@Override
public void visitInsn(int opcode) {
if (IRETURN <= opcode && opcode <= RETURN) {
mv.visitVarInsn(ALOAD, 1); // Load designated receiver
mv.visitVarInsn(ALOAD, 0); // Load Method instance
mv.visitFieldInsn(GETSTATIC, "de/bodden/tamiflex/playout/rt/Kind", methodKind().name(), Type.getDescriptor(Kind.class));
mv.visitMethodInsn(
INVOKESTATIC,
"de/bodden/tamiflex/playout/rt/ReflLogger",
"methodMethodInvoke",
"(Ljava/lang/Object;Ljava/lang/reflect/Method;Lde/bodden/tamiflex/playout/rt/Kind;)V"
);
}
super.visitInsn(opcode);
}
};
}

}

0 comments on commit 2b3b338

Please sign in to comment.