/** * Sorts the given list of local variable types and trims their code blocks * when necessary. The block is trimmed at the end, which is a bit * arbitrary. */ private void trimLocalVariableTypes(LocalVariableTypeInfo[] localVariableTypeInfos, int localVariableTypeInfoCount, int maxLocals) { // Sort the local variable entries. Arrays.sort(localVariableTypeInfos, 0, localVariableTypeInfoCount); int[] startPCs = createMaxArray(maxLocals); // Trim the local variable entries, starting at the last one. for (int index = localVariableTypeInfoCount-1; index >= 0; index--) { LocalVariableTypeInfo localVariableTypeInfo = localVariableTypeInfos[index]; // Make sure the variable's code block doesn't overlap with the // next one for the same variable. int maxLength = startPCs[localVariableTypeInfo.u2index] - localVariableTypeInfo.u2startPC; if (localVariableTypeInfo.u2length > maxLength) { localVariableTypeInfo.u2length = maxLength; } startPCs[localVariableTypeInfo.u2index] = localVariableTypeInfo.u2startPC; } }
public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute) { // Clean up local variables that aren't used. localVariableTypeTableAttribute.u2localVariableTypeTableLength = removeUnusedLocalVariableTypes(localVariableTypeTableAttribute.localVariableTypeTable, localVariableTypeTableAttribute.u2localVariableTypeTableLength, codeAttribute.u2maxLocals); // Trim the code blocks of the local variables. trimLocalVariableTypes(localVariableTypeTableAttribute.localVariableTypeTable, localVariableTypeTableAttribute.u2localVariableTypeTableLength, codeAttribute.u2maxLocals); // Delete the attribute in a moment, if it is empty. if (localVariableTypeTableAttribute.u2localVariableTypeTableLength == 0) { deleteLocalVariableTypeTableAttribute = true; } }
public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute) { // Clean up local variables that aren't used. localVariableTableAttribute.u2localVariableTableLength = removeUnusedLocalVariables(localVariableTableAttribute.localVariableTable, localVariableTableAttribute.u2localVariableTableLength, codeAttribute.u2maxLocals); // Trim the code blocks of the local variables. trimLocalVariables(localVariableTableAttribute.localVariableTable, localVariableTableAttribute.u2localVariableTableLength, codeAttribute.u2maxLocals); // Delete the attribute in a moment, if it is empty. if (localVariableTableAttribute.u2localVariableTableLength == 0) { deleteLocalVariableTableAttribute = true; } }
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) { // DEBUG = // clazz.getName().equals("abc/Def") && // method.getName(clazz).equals("abc"); // The minimum variable size is determined by the arguments. codeAttribute.u2maxLocals = ClassUtil.internalMethodParameterSize(method.getDescriptor(clazz), method.getAccessFlags()); if (DEBUG) { System.out.println("VariableSizeUpdater: "+clazz.getName()+"."+method.getName(clazz)+method.getDescriptor(clazz)); System.out.println(" Max locals: "+codeAttribute.u2maxLocals+" <- parameters"); } // Go over all instructions. codeAttribute.instructionsAccept(clazz, method, this); // Remove the unused variables of the attributes. variableCleaner.visitCodeAttribute(clazz, method, codeAttribute); }
public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute) { // Clean up local variables that aren't used. localVariableTypeTableAttribute.u2localVariableTypeTableLength = removeEmptyLocalVariableTypes(localVariableTypeTableAttribute.localVariableTypeTable, localVariableTypeTableAttribute.u2localVariableTypeTableLength, codeAttribute.u2maxLocals); }
public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute) { // Clean up local variables that aren't used. localVariableTableAttribute.u2localVariableTableLength = removeEmptyLocalVariables(localVariableTableAttribute.localVariableTable, localVariableTableAttribute.u2localVariableTableLength, codeAttribute.u2maxLocals); }
new AllMethodVisitor( new AllAttributeVisitor( new VariableCleaner())));
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) { // DEBUG = // clazz.getName().equals("abc/Def") && // method.getName(clazz).equals("abc"); // The minimum variable size is determined by the arguments. codeAttribute.u2maxLocals = ClassUtil.internalMethodParameterSize(method.getDescriptor(clazz), method.getAccessFlags()); if (DEBUG) { System.out.println("VariableSizeUpdater: "+clazz.getName()+"."+method.getName(clazz)+method.getDescriptor(clazz)); System.out.println(" Max locals: "+codeAttribute.u2maxLocals+" <- parameters"); } // Go over all instructions. codeAttribute.instructionsAccept(clazz, method, this); // Remove the unused variables of the attributes. variableCleaner.visitCodeAttribute(clazz, method, codeAttribute); }
public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute) { // Clean up local variables that aren't used. localVariableTypeTableAttribute.u2localVariableTypeTableLength = removeUnusedLocalVariableTypes(localVariableTypeTableAttribute.localVariableTypeTable, localVariableTypeTableAttribute.u2localVariableTypeTableLength, codeAttribute.u2maxLocals); // Trim the code blocks of the local variables. trimLocalVariableTypes(localVariableTypeTableAttribute.localVariableTypeTable, localVariableTypeTableAttribute.u2localVariableTypeTableLength, codeAttribute.u2maxLocals); // Delete the attribute in a moment, if it is empty. if (localVariableTypeTableAttribute.u2localVariableTypeTableLength == 0) { deleteLocalVariableTypeTableAttribute = true; } }
public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute) { // Clean up local variables that aren't used. localVariableTableAttribute.u2localVariableTableLength = removeUnusedLocalVariables(localVariableTableAttribute.localVariableTable, localVariableTableAttribute.u2localVariableTableLength, codeAttribute.u2maxLocals); // Trim the code blocks of the local variables. trimLocalVariables(localVariableTableAttribute.localVariableTable, localVariableTableAttribute.u2localVariableTableLength, codeAttribute.u2maxLocals); // Delete the attribute in a moment, if it is empty. if (localVariableTableAttribute.u2localVariableTableLength == 0) { deleteLocalVariableTableAttribute = true; } }
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) { // DEBUG = // clazz.getName().equals("abc/Def") && // method.getName(clazz).equals("abc"); // The minimum variable size is determined by the arguments. codeAttribute.u2maxLocals = ClassUtil.internalMethodParameterSize(method.getDescriptor(clazz), method.getAccessFlags()); if (DEBUG) { System.out.println("VariableSizeUpdater: "+clazz.getName()+"."+method.getName(clazz)+method.getDescriptor(clazz)); System.out.println(" Max locals: "+codeAttribute.u2maxLocals+" <- parameters"); } // Go over all instructions. codeAttribute.instructionsAccept(clazz, method, this); // Remove the unused variables of the attributes. variableCleaner.visitCodeAttribute(clazz, method, codeAttribute); }
/** * Sorts the given list of local variables and trims their code blocks * when necessary. The block is trimmed at the end, which is a bit * arbitrary. */ private void trimLocalVariables(LocalVariableInfo[] localVariableInfos, int localVariableInfoCount, int maxLocals) { // Sort the local variable entries. Arrays.sort(localVariableInfos, 0, localVariableInfoCount); int[] startPCs = createMaxArray(maxLocals); // Trim the local variable entries, starting at the last one. for (int index = localVariableInfoCount-1; index >= 0; index--) { LocalVariableInfo localVariableInfo = localVariableInfos[index]; // Make sure the variable's code block doesn't overlap with the // next one for the same variable. int maxLength = startPCs[localVariableInfo.u2index] - localVariableInfo.u2startPC; if (localVariableInfo.u2length > maxLength) { localVariableInfo.u2length = maxLength; } startPCs[localVariableInfo.u2index] = localVariableInfo.u2startPC; } }
public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute) { // Clean up local variables that aren't used. localVariableTypeTableAttribute.u2localVariableTypeTableLength = removeUnusedLocalVariableTypes(localVariableTypeTableAttribute.localVariableTypeTable, localVariableTypeTableAttribute.u2localVariableTypeTableLength, codeAttribute.u2maxLocals); // Trim the code blocks of the local variables. trimLocalVariableTypes(localVariableTypeTableAttribute.localVariableTypeTable, localVariableTypeTableAttribute.u2localVariableTypeTableLength, codeAttribute.u2maxLocals); // Delete the attribute in a moment, if it is empty. if (localVariableTypeTableAttribute.u2localVariableTypeTableLength == 0) { deleteLocalVariableTypeTableAttribute = true; } }
public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute) { // Clean up local variables that aren't used. localVariableTableAttribute.u2localVariableTableLength = removeUnusedLocalVariables(localVariableTableAttribute.localVariableTable, localVariableTableAttribute.u2localVariableTableLength, codeAttribute.u2maxLocals); // Trim the code blocks of the local variables. trimLocalVariables(localVariableTableAttribute.localVariableTable, localVariableTableAttribute.u2localVariableTableLength, codeAttribute.u2maxLocals); // Delete the attribute in a moment, if it is empty. if (localVariableTableAttribute.u2localVariableTableLength == 0) { deleteLocalVariableTableAttribute = true; } }
variableCleaner.visitCodeAttribute(clazz, method, codeAttribute);
/** * Sorts the given list of local variable types and trims their code blocks * when necessary. The block is trimmed at the end, which is a bit * arbitrary. */ private void trimLocalVariableTypes(LocalVariableTypeInfo[] localVariableTypeInfos, int localVariableTypeInfoCount, int maxLocals) { // Sort the local variable entries. Arrays.sort(localVariableTypeInfos, 0, localVariableTypeInfoCount); int[] startPCs = createMaxArray(maxLocals); // Trim the local variable entries, starting at the last one. for (int index = localVariableTypeInfoCount-1; index >= 0; index--) { LocalVariableTypeInfo localVariableTypeInfo = localVariableTypeInfos[index]; // Make sure the variable's code block doesn't overlap with the // next one for the same variable. int maxLength = startPCs[localVariableTypeInfo.u2index] - localVariableTypeInfo.u2startPC; if (localVariableTypeInfo.u2length > maxLength) { localVariableTypeInfo.u2length = maxLength; } startPCs[localVariableTypeInfo.u2index] = localVariableTypeInfo.u2startPC; } }
variableCleaner.visitCodeAttribute(clazz, method, codeAttribute);
/** * Sorts the given list of local variables and trims their code blocks * when necessary. The block is trimmed at the end, which is a bit * arbitrary. */ private void trimLocalVariables(LocalVariableInfo[] localVariableInfos, int localVariableInfoCount, int maxLocals) { // Sort the local variable entries. Arrays.sort(localVariableInfos, 0, localVariableInfoCount); int[] startPCs = createMaxArray(maxLocals); // Trim the local variable entries, starting at the last one. for (int index = localVariableInfoCount-1; index >= 0; index--) { LocalVariableInfo localVariableInfo = localVariableInfos[index]; // Make sure the variable's code block doesn't overlap with the // next one for the same variable. int maxLength = startPCs[localVariableInfo.u2index] - localVariableInfo.u2startPC; if (localVariableInfo.u2length > maxLength) { localVariableInfo.u2length = maxLength; } startPCs[localVariableInfo.u2index] = localVariableInfo.u2startPC; } }
variableCleaner.visitCodeAttribute(clazz, method, codeAttribute);
/** * Sorts the given list of local variable types and trims their code blocks * when necessary. The block is trimmed at the end, which is a bit * arbitrary. */ private void trimLocalVariableTypes(LocalVariableTypeInfo[] localVariableTypeInfos, int localVariableTypeInfoCount, int maxLocals) { // Sort the local variable entries. Arrays.sort(localVariableTypeInfos, 0, localVariableTypeInfoCount); int[] startPCs = createMaxArray(maxLocals); // Trim the local variable entries, starting at the last one. for (int index = localVariableTypeInfoCount-1; index >= 0; index--) { LocalVariableTypeInfo localVariableTypeInfo = localVariableTypeInfos[index]; // Make sure the variable's code block doesn't overlap with the // next one for the same variable. int maxLength = startPCs[localVariableTypeInfo.u2index] - localVariableTypeInfo.u2startPC; if (localVariableTypeInfo.u2length > maxLength) { localVariableTypeInfo.u2length = maxLength; } startPCs[localVariableTypeInfo.u2index] = localVariableTypeInfo.u2startPC; } }