⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 livenessanalyzer.java

📁 ProGuard 是一个免费的 Java类文件的压缩
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        for (int offset = 0; offset < codeLength; offset++)        {            if (partialEvaluator.isTraced(offset))            {                // Loop over all variables.                for (int variableIndex = 0; variableIndex < variablesSize; variableIndex++)                {                    // Is the variable alive and a category 2 type?                    if (isAliveBefore(offset, variableIndex))                    {                        Value value = partialEvaluator.getVariablesBefore(offset).getValue(variableIndex);                        if (value != null && value.isCategory2())                        {                            // Mark it as such.                            setCategory2(offset, variableIndex, true);                            // Mark the next variable as well.                            setAliveBefore(offset, variableIndex + 1, true);                            setCategory2(  offset, variableIndex + 1, true);                        }                    }                    // Is the variable alive and a category 2 type?                    if (isAliveAfter(offset, variableIndex))                    {                        Value value = partialEvaluator.getVariablesAfter(offset).getValue(variableIndex);                        if (value != null && value.isCategory2())                        {                            // Mark it as such.                            setCategory2(offset, variableIndex, true);                            // Mark the next variable as well.                            setAliveAfter(offset, variableIndex + 1, true);                            setCategory2( offset, variableIndex + 1, true);                        }                    }                }            }        }        if (DEBUG)        {            // Loop over all instructions.            for (int offset = 0; offset < codeLength; offset++)            {                if (partialEvaluator.isTraced(offset))                {                    long aliveBefore = isAliveBefore[offset];                    long aliveAfter  = isAliveAfter[offset];                    long category2   = isCategory2[offset];                    // Print out the liveness of all variables before the instruction.                    for (int variableIndex = 0; variableIndex < variablesSize; variableIndex++)                    {                        long variableMask = (1L << variableIndex);                        System.out.print((aliveBefore & variableMask) != 0L ? ((category2  & variableMask) == 0L ? 'x' : '*') :                                                                              '.');                    }                    // Print out the instruction itself.                    System.out.println(" "+ InstructionFactory.create(codeAttribute.code, offset).toString(offset));                    // Print out the liveness of all variables after the instruction.                    for (int variableIndex = 0; variableIndex < variablesSize; variableIndex++)                    {                        long variableMask = (1L << variableIndex);                        System.out.print((aliveAfter & variableMask) == 0L ? '.' :                                         (category2  & variableMask) == 0L ? 'x' :                                                                             '=');                    }                    System.out.println();                }            }        }    }    // Implementations for InstructionVisitor.    public void visitAnyInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, Instruction instruction) {}    public void visitVariableInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction)    {        int variableIndex = variableInstruction.variableIndex;        if (variableIndex < MAX_VARIABLES_SIZE)        {            long livenessMask = 1L << variableIndex;            // Is it a load instruction or a store instruction?            if (variableInstruction.isLoad())            {                // Start marking the variable before the load instruction.                alive |= livenessMask;            }            else if (variableInstruction.opcode != InstructionConstants.OP_IINC)            {                // Stop marking the variable before the store instruction.                alive &= ~livenessMask;                // But do mark the variable right after the store instruction.                isAliveAfter[offset] |= livenessMask;            }        }    }    public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)    {        // Special case: variable 0 ('this') in an initializer has to be alive        // as long as it hasn't been initialized.         if (offset == partialEvaluator.superInitializationOffset())        {            alive |= 1L;        }    }    // Implementations for ExceptionInfoVisitor.    public void visitExceptionInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, ExceptionInfo exceptionInfo)    {        // Are any variables alive at the start of the handler?        long alive = isAliveBefore[exceptionInfo.u2handlerPC];        if (alive != 0L)        {            // Set the same liveness flags for the entire try block.            int startOffset = exceptionInfo.u2startPC;            int endOffset   = exceptionInfo.u2endPC;            for (int offset = startOffset; offset < endOffset; offset++)            {                if (partialEvaluator.isTraced(offset))                {                    isAliveBefore[offset] |= alive;                    isAliveAfter[offset]  |= alive;                }            }        }    }    // Small utility methods.    /**     * Initializes the global arrays.     */    private void initializeArrays(CodeAttribute codeAttribute)    {        int codeLength = codeAttribute.u4codeLength;        // Create new arrays for storing information at each instruction offset.        if (isAliveBefore.length < codeLength)        {            isAliveBefore = new long[codeLength];            isAliveAfter  = new long[codeLength];            isCategory2   = new long[codeLength];        }        else        {            for (int index = 0; index < codeLength; index++)            {                isAliveBefore[index] = 0L;                isAliveAfter[index]  = 0L;                isCategory2[index]   = 0L;            }        }    }    private long combinedLiveness(InstructionOffsetValue instructionOffsetValue)    {        long alive = 0L;        int count = instructionOffsetValue.instructionOffsetCount();        for (int index = 0; index < count; index++)        {            alive |= isAliveBefore[instructionOffsetValue.instructionOffset(index)];        }        return alive;    }    /**     * Returns the minimum offset from the given instruction offsets.     */    private int minOffset(Value instructionOffsets)    {        return minOffset(instructionOffsets, Integer.MAX_VALUE);    }    /**     * Returns the minimum offset from the given instruction offsets.     */    private int minOffset(Value instructionOffsets, int minOffset)    {        if (instructionOffsets != null)        {            InstructionOffsetValue instructionOffsetValue =                instructionOffsets.instructionOffsetValue();            int count = instructionOffsetValue.instructionOffsetCount();            for (int index = 0; index < count; index++)            {                int offset = instructionOffsetValue.instructionOffset(index);                if (minOffset > offset)                {                    minOffset = offset;                }            }        }        return minOffset;    }    /**     * Returns the maximum offset from the given instruction offsets.     */    private int maxOffset(Value instructionOffsets)    {        return maxOffset(instructionOffsets, Integer.MIN_VALUE);    }    /**     * Returns the maximum offset from the given instruction offsets.     */    private int maxOffset(Value instructionOffsets, int maxOffset)    {        if (instructionOffsets != null)        {            InstructionOffsetValue instructionOffsetValue =                instructionOffsets.instructionOffsetValue();            int count = instructionOffsetValue.instructionOffsetCount();            for (int index = 0; index < count; index++)            {                int offset = instructionOffsetValue.instructionOffset(index);                if (maxOffset < offset)                {                    maxOffset = offset;                }            }        }        return maxOffset;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -