fixed AIOOB in MethodBytecodeUtil.visit

This commit is contained in:
Egor.Ushakov
2016-10-28 20:43:50 +03:00
parent b7d4657d26
commit 8900e8a1cd
4 changed files with 10 additions and 9 deletions
@@ -324,7 +324,7 @@ public class JavaSmartStepIntoHandler extends JvmSmartStepIntoHandler {
if (frameProxy != null) {
try {
Location location = frameProxy.location();
MethodBytecodeUtil.visit(location.declaringType(), location.method(), location.codeIndex(), new MethodVisitor(Opcodes.API_VERSION) {
MethodBytecodeUtil.visit(location.method(), location.codeIndex(), new MethodVisitor(Opcodes.API_VERSION) {
boolean myLineMatch = false;
@Override
@@ -288,7 +288,7 @@ public class LocalVariablesUtil {
if (bytecodes != null && bytecodes.length > 0) {
final int firstLocalVariableSlot = getFirstLocalsSlot(method);
final HashMap<Integer, DecompiledLocalVariable> usedVars = new HashMap<>();
MethodBytecodeUtil.visit(location.declaringType(), method, location.codeIndex(),
MethodBytecodeUtil.visit(method, location.codeIndex(),
new MethodVisitor(Opcodes.API_VERSION) {
@Override
public void visitVarInsn(int opcode, int slot) {
@@ -43,16 +43,16 @@ public class MethodBytecodeUtil {
/**
* Allows to use ASM MethodVisitor with jdi method bytecode
*/
public static void visit(ReferenceType classType, Method method, MethodVisitor methodVisitor) {
visit(classType, method, method.bytecodes(), methodVisitor);
public static void visit(Method method, MethodVisitor methodVisitor) {
visit(method, method.bytecodes(), methodVisitor);
}
public static void visit(ReferenceType classType, Method method, long maxOffset, MethodVisitor methodVisitor) {
public static void visit(Method method, long maxOffset, MethodVisitor methodVisitor) {
// need to keep the size, otherwise labels array will not be initialized correctly
byte[] originalBytecodes = method.bytecodes();
byte[] bytecodes = new byte[originalBytecodes.length];
System.arraycopy(originalBytecodes, 0, bytecodes, 0, (int)maxOffset);
visit(classType, method, bytecodes, methodVisitor);
visit(method, bytecodes, methodVisitor);
}
public static byte[] getConstantPool(ReferenceType type) {
@@ -65,7 +65,8 @@ public class MethodBytecodeUtil {
}
}
private static void visit(ReferenceType type, Method method, byte[] bytecodes, MethodVisitor methodVisitor) {
private static void visit(Method method, byte[] bytecodes, MethodVisitor methodVisitor) {
ReferenceType type = method.declaringType();
try {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos)) {
dos.writeInt(0xCAFEBABE); // magic
@@ -229,7 +230,7 @@ public class MethodBytecodeUtil {
if (DebuggerUtilsEx.isLambdaClassName(clsType.name())) {
List<Method> applicableMethods = ContainerUtil.filter(clsType.methods(), m -> m.isPublic() && !m.isBridge());
if (applicableMethods.size() == 1) {
visit(clsType, applicableMethods.get(0), new MethodVisitor(Opcodes.API_VERSION) {
visit(applicableMethods.get(0), new MethodVisitor(Opcodes.API_VERSION) {
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
ReferenceType cls = ContainerUtil.getFirstItem(clsType.virtualMachine().classesByName(owner));
@@ -169,7 +169,7 @@ public class MethodBreakpoint extends BreakpointWithHighlighter<JavaMethodBreakp
createLocationBreakpointRequest(ContainerUtil.getFirstItem(allLineLocations), debugProcess);
}
if (isWatchExit()) {
MethodBytecodeUtil.visit(classType, method, new MethodVisitor(Opcodes.API_VERSION) {
MethodBytecodeUtil.visit(method, new MethodVisitor(Opcodes.API_VERSION) {
int myLastLine = 0;
@Override
public void visitLineNumber(int line, Label start) {