當前位置: 首頁>>代碼示例>>Java>>正文


Java Tracer.traceln方法代碼示例

本文整理匯總了Java中com.sun.squawk.util.Tracer.traceln方法的典型用法代碼示例。如果您正苦於以下問題:Java Tracer.traceln方法的具體用法?Java Tracer.traceln怎麽用?Java Tracer.traceln使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.squawk.util.Tracer的用法示例。


在下文中一共展示了Tracer.traceln方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: mergeMethodsObjectTable

import com.sun.squawk.util.Tracer; //導入方法依賴的package包/類
void mergeMethodsObjectTable(Translator translator, Code[] methodsCode, boolean isStatic) {
    for (int i = 0; i < methodsCode.length; i++) {
        Method method = definedClass.getMethod(i, isStatic);
        Code code = methodsCode[i];
        if (!method.isHosted() && !method.isAbstract() && !method.isNative()) {
            Assert.that(code != null);
            boolean unusedMethod = safeToDoDeadMethodElim && !translator.dme.isMarkedUsed(method);
            if (unusedMethod) {
                if (safeToDoDeadStringElim) {
                    if (Translator.TRACING_ENABLED && Tracer.isTracing("converting", method.toString())) {
                        Tracer.traceln("Ignoring objects used by unused method " + method);
                    }
                } else {
                    mergeObjectTable(code.getObjectTable(), true);
                }
            } else {
                mergeObjectTable(code.getObjectTable(), false);
            }
        }
    }
}
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:22,代碼來源:ObjectTable.java

示例2: traceType

import com.sun.squawk.util.Tracer; //導入方法依賴的package包/類
/**
 * Traces a type on the operand stack or in a local variable.
 *
 * @param type       the type to trace
 * @param prefix     the prefix to use if <code>isDerived</code> is true
 *                   otherwise a prefix of spaces the same length as
 *                   <code>prefix</code> is used instead
 * @param isDerived  specifies if this a type derived by the verifer or
 *                   is specified by a stack map entry
 */
private void traceType(Klass type, String prefix, boolean isDerived) {
    if (Translator.TRACING_ENABLED) {
        if (!isDerived) {
            char[] spaces = new char[prefix.length()];
            Arrays.fill(spaces, ' ');
            Tracer.trace(new String(spaces));
        } else {
            Tracer.trace(prefix);
        }
        String name = (type == null ? "-T-" : type.getInternalName());
        if (isDerived) {
            Tracer.traceln(" "+name);
        } else {
            Tracer.traceln("{"+name+"}");
        }
    }
}
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:28,代碼來源:Frame.java

示例3: traceFrameState

import com.sun.squawk.util.Tracer; //導入方法依賴的package包/類
/**
 * Traces the frame state at the current verification address.
 *
 * @param  opcode   the opcode of the instruction at <code>address</code>
 * @param  address  the current verification address
 */
public void traceFrameState(int opcode, int address) {
    /*
     * Trace the recorded and derived types
     */
    if (Translator.TRACING_ENABLED) {
        Target target = null;
        try {
            target = codeParser.getTarget(address);
        } catch (NoClassDefFoundError e) {
            /* Just means there is no stack map at this address */
        }
        Tracer.traceln("Frame state @ "+address+" [ "+ Opcode.mnemonics[opcode]+" ]");
        traceLocals(target);
        traceStack(target);
    }
}
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:23,代碼來源:Frame.java

示例4: convert0

import com.sun.squawk.util.Tracer; //導入方法依賴的package包/類
/**
 * Convert the code of this method from it Java bytecode form to its
 * Squawk bytecode form. This must only be called once and cannot be called
 * for an abstract or native <code>Method</code>.
 *
 * @param  translator   the translation context
 * @param  method       the method owning this code
 * @param  index        the index of this method in the symbols table of the enclosing class
 * @param  phase        the compilation phase (1 or 2)
 * @param  bodies       {@link Vector} to insert method body into
 */
private void convert0(Translator translator, Method method, int index, int phase, final Vector bodies) {
    try {
        if (phase == 1) {
            convertPhase1(translator, method, index);
        } else {
            MethodBody b = convertPhase2(translator, method, index);
            if (bodies != null)
                bodies.addElement(b);
        }
    } catch (NoClassDefFoundError e) {
        /*
         * Write trace message and re-throw exception.
         */
        if (Translator.TRACING_ENABLED && Tracer.isTracing("converting", method.toString())) {
            Tracer.traceln("[error converting method " + method + ": " + e + "]");
        }
        code = null;
        irBuilder = null;
        codeParser = null;
        throw e;
    }
}
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:34,代碼來源:Code.java

示例5: trace

import com.sun.squawk.util.Tracer; //導入方法依賴的package包/類
public static void trace(MethodBody mb) {
    if (Translator.TRACING_ENABLED ) {
        Method method = mb.getDefiningMethod();
        Tracer.traceln("++++ Method for " + method + " ++++");
        new MethodBodyTracer(mb).traceAll();
        Tracer.traceln("---- Method for " + method + " ----");
    }
}
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:9,代碼來源:Translator.java

示例6: traceTarget

import com.sun.squawk.util.Tracer; //導入方法依賴的package包/類
/**
 * Traces the frame state at the current verification address.
 *
 * @param  opcode   the opcode of the instruction at <code>address</code>
 * @param  address  the current verification address
 */
public void traceTarget(Target target) {
    /*
     * Trace the recorded and derived types
     */
    if (Translator.TRACING_ENABLED) {
        Tracer.traceln("target "+target);
        traceLocals(target);
        traceStack(target);
    }
}
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:17,代碼來源:Frame.java

示例7: parseOpcode

import com.sun.squawk.util.Tracer; //導入方法依賴的package包/類
/**
 * Read an opcode from the bytecode stream. The returned value will be
 * one of the <code>opc_...</code> defined in {@link Opcode}.
 *
 * @return  the opcode read
 */
public int parseOpcode() {
    lastOpcodeAddress = bcin.getCurrentIndex();
    int opcode = cfr.readUnsignedByte(null);
    if (Translator.TRACING_ENABLED && trace) {
        Tracer.traceln("["+lastOpcodeAddress+"]:opcode:"+Opcode.mnemonics[opcode]);
    }
    return opcode;
}
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:15,代碼來源:CodeParser.java

示例8: stripFields

import com.sun.squawk.util.Tracer; //導入方法依賴的package包/類
/**
 * Prunes the fields based on a given suite type.
 *
 * @param klass     the enclosing class
 * @param type      specifies a closed suite type. Must be {@link Suite#LIBRARY} or {@link Suite#EXTENDABLE_LIBRARY}.
 * @param category  specifies instance or static fields
 * @param types     the collection to which the types in the signatures of the remaining fields should be added
 * @return an integer with the only the bit in position 'category' set if at least one field was not stripped otherwise 0
 */
private int stripFields(Klass klass, int type, int category, SquawkVector types) {
    Assert.that(category == INSTANCE_FIELDS || category == STATIC_FIELDS);
    int count = getMemberCount(category);
    boolean keptAtLeastOne = false;
    if (count != 0) {
        for (int i = 0; i != count; ++i) {
            select(category, i);
            Klass fieldType = getSignatureType(getSignatureAt(0));
            Field field = klass.getField(i, category == STATIC_FIELDS);
            if (keepForRuntimeStatics(klass, fieldType, category)
                    || (retainMember(type, modifiers, fieldType) && VM.isExported(field))) {
                if (!keptAtLeastOne) {
                    symbolsBuffer.addUnsignedByte(category);
                    keptAtLeastOne = true;
                }
                membersBuffer.reset();
                membersBuffer.addUnsignedShort(modifiers);
                membersBuffer.addUnsignedShort(getOffset());
                membersBuffer.addUtf8(getName());
                if (Modifier.hasPragmas(modifiers)) {
                    membersBuffer.addUnsignedShort(0);
                }
                membersBuffer.addUnsignedShort(KlassMetadata.addSignatureType(types, fieldType));
                if (Modifier.hasConstant(modifiers)) {
                    if (!fieldType.isPrimitive()) {
                        membersBuffer.addUtf8(getStringConstantValue());
                    } else {
                        long value = getPrimitiveConstantValue();
                        int dataSize = fieldType.getDataSize();
                        for (int bite = 0; bite != dataSize; ++bite) {
                            membersBuffer.addUnencodedByte((byte)value);
                            value = value >> 8;
                        }
                    }
                }
                symbolsBuffer.add(membersBuffer);
            } else if (Klass.TRACING_ENABLED && Tracer.isTracing("stripping")) {
                Tracer.trace("  discarded metadata for field: " + fieldType.getInternalName() + " " + getName());
                if (Modifier.hasConstant(modifiers)) {
                    Tracer.trace(" [constantValue=" + (fieldType.isPrimitive() ? ""+getPrimitiveConstantValue() : getStringConstantValue()) + "]");
                }
                Tracer.traceln("");
            }

        }
    }
    return keptAtLeastOne ? 1 << category : 0;
}
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:58,代碼來源:SymbolParser.java

示例9: stripMethods

import com.sun.squawk.util.Tracer; //導入方法依賴的package包/類
/**
 * Prunes the methods based on a given suite type.
 * 
 * @todo Now we're keeping symbols for all methods if lnt is true. But we can strip symbols for methods that have been eliminated.
 *
 * @param klass     the enclosing class
 * @param type      specifies a closed suite type. Must be {@link Suite#LIBRARY} or {@link Suite#EXTENDABLE_LIBRARY}.
 * @param category  specifies virtual or static methods
 * @param types     the collection to which the types in the signatures of the remaining methods should be added
 * @return an integer with the only the bit in position 'category' set if at least one method was not stripped otherwise 0
 */
private int stripMethods(Klass klass, int type, int category, SquawkVector types) {
    Assert.that(category == VIRTUAL_METHODS || category == STATIC_METHODS);
    int count = getMemberCount(category);
    boolean keptAtLeastOne = false;
    if (count != 0) {
        for (int i = 0; i != count; ++i) {
            select(category, i);
            String name = getName();
            if (!PragmaException.isHosted(pragmas) &&               // strip methods called only in hosted VM mode
                !PragmaException.isInterpreterInvoked(pragmas) &&   // strip methods called from the interpreter
                (MethodMetadata.lineNumberTablesKept() ||           // if we want line numbers then we want method names too...
                    (retainMember(type, modifiers, null) &&
                    VM.isExported(klass.getMethod(i, category == STATIC_METHODS)))))
            {
                // keeping this method:
                if (!keptAtLeastOne) {
                    symbolsBuffer.addUnsignedByte(category);
                    keptAtLeastOne = true;
                }
                membersBuffer.reset();
                membersBuffer.addUnsignedShort(modifiers);
                membersBuffer.addUnsignedShort(getOffset());
                membersBuffer.addUtf8(name);
                if (Modifier.hasPragmas(modifiers)) {
                    membersBuffer.addUnsignedShort(pragmas);
                }
                int sigCount = getSignatureCount();
                for (int j = 0; j != sigCount; ++j) {
                    membersBuffer.addUnsignedShort(KlassMetadata.addSignatureType(types, getSignatureType(getSignatureAt(j))));
                }
                symbolsBuffer.add(membersBuffer);
            } else {
                // Stripping this method:
                if ((Modifier.isAbstract(modifiers) || klass.isInterface())
                    && !(Modifier.isPackagePrivate(modifiers) || Modifier.isSuitePrivate(klass.getModifiers()))) {
                    // If a class with abstract methods, or an interface, is exported from a suite, but the abstract methods are not exported,
                    // then there is no way to extend or implement the exported class or interface.
                    throw new IllegalStateException("Can't strip method " + name + " because it is abstract in a class exported from a suite: " + klass);
                }
                
                if (Klass.TRACING_ENABLED && Tracer.isTracing("stripping")) {
                    String signature = name;
                    int parameterCount = getSignatureCount() - 1;
                    if (parameterCount == 0) {
                        signature += "()";
                    } else {
                        StringBuffer strbuf = new StringBuffer(15);
                        strbuf.append('(');
                        for (int j = 0 ; j < parameterCount ; j++) {
                            Klass parameterType = getSignatureType(getSignatureAt(j + 1));
                            strbuf.append(parameterType.getInternalName());
                            if (j != parameterCount - 1) {
                                strbuf.append(',');
                            }
                        }
                        strbuf.append(')');
                        signature += strbuf.toString();
                    }
                    signature = getSignatureType(getSignatureAt(0)).getInternalName() + " " + signature;
                    Tracer.traceln("  discarded metadata for method: " + signature);
                }
            }
        }
    }
    return keptAtLeastOne ? 1 << category : 0;
}
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:78,代碼來源:SymbolParser.java

示例10: close

import com.sun.squawk.util.Tracer; //導入方法依賴的package包/類
/**
     * {@inheritDoc}
     */
    public void close(int suiteType) throws NoClassDefFoundError {
        long time = 0;
        this.suiteType = suiteType;
        
        if (verbose()) {
            Tracer.trace("[Translator: computing closure...");
            time = System.currentTimeMillis();
        }
        
        computeClosure();
        
        if (translationStrategy == BY_SUITE || translationStrategy == BY_TRANSLATION) {
            if (verbose()) {
                time = System.currentTimeMillis() - time;
                Tracer.traceln(time + "ms.]");
                Tracer.trace("[Translator: whole-suite optimizing and inlining...");
                time = System.currentTimeMillis();
            }
            // bytecode optimizations and inlining go here
            
            if (Arg.get(Arg.DEAD_METHOD_ELIMINATION).getBool()) {
                dme = new DeadMethodEliminator(this);
                dme.computeMethodsUsed();
            }
            
            if (Arg.get(Arg.DEAD_CLASS_ELIMINATION).getBool()) {
                dce = new DeadClassEliminator(this);
                dce.computeClassesUsed();
            }

            if (Arg.get(Arg.DEAD_METHOD_ELIMINATION).getBool()) {
                dme = new DeadMethodEliminator(this);
                dme.computeMethodsUsed();
            }
	    
            if (verbose()) {
                time = System.currentTimeMillis() - time;
                Tracer.traceln(time + "ms.]");
                Tracer.trace("[Translator: phase2...");
                time = System.currentTimeMillis();
            }
            
            for (int cno = 0; cno < suite.getClassCount(); cno++) {
                Klass klass = suite.getKlass(cno);
                Assert.always(Arg.get(Arg.DEAD_CLASS_ELIMINATION).getBool() || (klass != null));
                if (klass != null) {
                    convertPhase2(klass);
                }
            }
        }
        classFiles.clear();
        
        if (verbose()) {
            time = System.currentTimeMillis() - time;
            Tracer.traceln(time + "ms.]");
/*if[ENABLE_VERBOSE]*/
            if (VM.isVeryVerbose()) {
                InstructionEmitter.printUncalledNativeMethods();
            }
/*end[ENABLE_VERBOSE]*/	    
        }
        Assert.always(lastClassNameStack.empty());
    }
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:67,代碼來源:Translator.java

示例11: emit

import com.sun.squawk.util.Tracer; //導入方法依賴的package包/類
/**
     * Emit the Squawk bytecodes.
     */
    void emit() {

        /*
         * Visit all the instructions to establish the minimum bytecode length.
         */
        needAnotherPass = false;
        state = INIT;
        int last = visitAll();
        int size = last;

        /*
         * Visit all the instructions checking that the length has reached its asymptote.
         */
        if (needAnotherPass) {
            state = CHECK;
            size = visitAll();
            while (size != last) {
                last = size;
                visitAll();
                size = visitAll();
            }
        }

        /*
         * Visit all the instructions producing the final bytecode sequence.
         */
        code = new byte[size];
/*if[TYPEMAP]*/
        if (VM.usingTypeMap()) {
            typeMap = new byte[size];
        }
/*end[TYPEMAP]*/
        state = EMIT;
        last = visitAll();
        Assert.always(last == size);

        methodsProcessed++;

        /*
         * Trace.
         */
        if (trace) {
            Tracer.traceln("**** InstructionEmitter summary -- methodsProcessed = "+methodsProcessed+ " passes = "+passes
/*if[FLOATS]*/
                      + " avg="+((float)passes/methodsProcessed)
/*end[FLOATS]*/
                      + " ****");
        }

    }
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:54,代碼來源:InstructionEmitter.java

示例12: loadStackMap

import com.sun.squawk.util.Tracer; //導入方法依賴的package包/類
/**
 * Loads a "StackMap" attribute and builds a table of <code>Target</code>
 * instances representing the entries in the stack map.
 *
 * @param   codeParser    the "Code" attribute parser
 * @param   cfr           the class file reader used to read the attribute
 * @param   constantPool  the constant pool of the enclosing class
 * @param   codeLength    the length of the bytecode array for the enclosing method
 * @return  a table of <code>Target</code> instances indexed by address
 *          representing the entries in the stack map
 */
public static IntHashtable loadStackMap(CodeParser codeParser, ClassFileReader cfr, ConstantPool constantPool, int codeLength) {
    /*
     * Read number_of_entries
     */
    int nmaps  = cfr.readUnsignedShort("map-nmaps");
    if (nmaps == 0) {
        return null;
    } else {
        IntHashtable table = new IntHashtable(nmaps + (nmaps/4) + 1);
        int lastAddress = -1;
        final boolean trace = Translator.TRACING_ENABLED && Tracer.isTracing("maps", codeParser.getMethod().toString());

        for (int i = 0 ; i < nmaps ; i++) {
            int address = cfr.readUnsignedShort("map-address");
            if (address <= lastAddress) {
                throw cfr.formatError("stack map ip addresses not in order");
            }
            lastAddress = address;

            /*
             * Load the list of types in the local variables array
             */
            Klass[] locals = loadStackMapList(codeParser, cfr, constantPool, codeLength);
            if (locals.length > codeParser.getMaxLocals()) {
                throw cfr.formatError("stack map locals greater than max_locals");
            }

            /*
             * Load the list of types on the operand stack
             */
            Klass[] stack = loadStackMapList(codeParser, cfr, constantPool, codeLength);
            if (stack.length > codeParser.getMaxStack()) {
                throw cfr.formatError("stack map stack greater than max_stack");
            }

            Target target = new Target(address, stack, locals);
            table.put(address, target);

            /*
             * Trace.
             */
            if (trace) {
                Tracer.traceln("Stackmap @"+ target);
            }

        }
        return table;
    }
}
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:61,代碼來源:StackMap.java

示例13: convertPhase1

import com.sun.squawk.util.Tracer; //導入方法依賴的package包/類
/**
 * Convert the code of this method from its Java bytecode form to its
 * Squawk bytecode form. This must only be called once and cannot be called
 * for an abstract or native <code>Method</code>.
 *
 * @param  translator   the translation context
 * @param  method       the method owning this code
 * @param  index        the index of this method in the symbols table of the enclosing class
 */
private void convertPhase1(Translator translator, Method method, int index) {
    try {
        Assert.that(code != null, "code is null for " + method);
        Klass declaringClass = method.getDefiningClass();
        ClassFile cf = translator.getClassFile(declaringClass);

        /*
         * Write trace message.
         */
        if (Translator.TRACING_ENABLED && Tracer.isTracing("converting", method.toString())) {
            Tracer.traceln("[converting method " + method + "]");
        }

        /*
         * Get or create the constant pool.
         */
        ConstantPool constantPool;
        if (code == SYNTHESIZED_DEFAULT_CONSTRUCTOR_CODE) {
            constantPool = getConstantPoolForSynthesizedConstructor(translator, method.getDefiningClass());
            code = getCodeForSynthesizedConstructor();
        } else {
            constantPool = cf.getConstantPool();
        }

        /*
         * Ensure the parameter and return types are loaded.
         */
        translator.load(method.getReturnType());
        Klass[] parameterTypes = method.getParameterTypes();
        for (int i = 0 ; i < parameterTypes.length ; i++) {
            translator.load(parameterTypes[i]);
        }

        /*
         * Get the code parser and build the IR.
         */
        codeParser = new CodeParser(translator, method, code, constantPool);
        irBuilder = new IRBuilder(translator, codeParser);
        IR ir = irBuilder.getIR();

        /*
         * Add the object references into the table of constants.
         */
        objectTable = new ObjectTable(declaringClass);
        for (Instruction instruction = ir.getHead() ; instruction != null ; instruction = instruction.getNext()) {
            Object object = instruction.getConstantObject();
            if (object != null) {
                if (instruction instanceof FieldAccessor) {         // ignore special cases:
                    Klass fieldDefiningClass = ((FieldAccessor)instruction).getField().getDefiningClass();
                    if (fieldDefiningClass.hasGlobalStatics() || fieldDefiningClass == declaringClass) {
                        // getstatic/putstatic on global globals doesn't really use the class object table
                        // getstatic/putstatic on "this class" doesn't really use the class object table
                        continue;
                    }
                }
                objectTable.addConstantObject(object);
            }
        }
        
        /*
         * Transform the IR.
         */
        IRTransformer transformer = new IRTransformer(ir, method, getFrame());
        transformer.transform(translator);
    } finally {
        code = null; // Allow the code to be garbage collected
    }
}
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:78,代碼來源:Code.java

示例14: stripFields

import com.sun.squawk.util.Tracer; //導入方法依賴的package包/類
/**
 * Prunes the fields based on a given suite type.
 *
 * @param klass     the enclosing class
 * @param type      specifies a closed suite type. Must be {@link Suite#LIBRARY} or {@link Suite#EXTENDABLE_LIBRARY}.
 * @param category  specifies instance or static fields
 * @param types     the collection to which the types in the signatures of the remaining fields should be added
 * @return an integer with the only the bit in position 'category' set if at least one field was not stripped otherwise 0
 */
private int stripFields(Klass klass, int type, int category, SquawkVector types) {
    if (false) Assert.that(category == INSTANCE_FIELDS || category == STATIC_FIELDS);
    int count = getMemberCount(category);
    boolean keptAtLeastOne = false;
    if (count != 0) {
        for (int i = 0; i != count; ++i) {
            select(category, i);
            Klass fieldType = getSignatureType(getSignatureAt(0));
            Field field = klass.getField(i, category == STATIC_FIELDS);
            if (keepForRuntimeStatics(klass, fieldType, category)
                    || (retainMember(type, modifiers, fieldType) && VM.isExported(field))) {
                if (!keptAtLeastOne) {
                    symbolsBuffer.addUnsignedByte(category);
                    keptAtLeastOne = true;
                }
                membersBuffer.reset();
                membersBuffer.addUnsignedShort(modifiers);
                membersBuffer.addUnsignedShort(getOffset());
                membersBuffer.addUtf8(getName());
                if (Modifier.hasPragmas(modifiers)) {
                    membersBuffer.addUnsignedShort(0);
                }
                membersBuffer.addUnsignedShort(KlassMetadata.addSignatureType(types, fieldType));
                if (Modifier.hasConstant(modifiers)) {
                    if (!fieldType.isPrimitive()) {
                        membersBuffer.addUtf8(getStringConstantValue());
                    } else {
                        long value = getPrimitiveConstantValue();
                        int dataSize = fieldType.getDataSize();
                        for (int bite = 0; bite != dataSize; ++bite) {
                            membersBuffer.addUnencodedByte((byte)value);
                            value = value >> 8;
                        }
                    }
                }
                symbolsBuffer.add(membersBuffer);
            } else if (Klass.TRACING_ENABLED && Tracer.isTracing("stripping")) {
                Tracer.trace("  discarded metadata for field: " + fieldType.getInternalName() + " " + getName());
                if (Modifier.hasConstant(modifiers)) {
                    Tracer.trace(" [constantValue=" + (fieldType.isPrimitive() ? ""+getPrimitiveConstantValue() : getStringConstantValue()) + "]");
                }
                Tracer.traceln("");
            }

        }
    }
    return keptAtLeastOne ? 1 << category : 0;
}
 
開發者ID:sics-sse,項目名稱:moped,代碼行數:58,代碼來源:SymbolParser.java

示例15: stripMethods

import com.sun.squawk.util.Tracer; //導入方法依賴的package包/類
/**
 * Prunes the methods based on a given suite type.
 * 
 * @todo Now we're keeping symbols for all methods if lnt is true. But we can strip symbols for methods that have been eliminated.
 *
 * @param klass     the enclosing class
 * @param type      specifies a closed suite type. Must be {@link Suite#LIBRARY} or {@link Suite#EXTENDABLE_LIBRARY}.
 * @param category  specifies virtual or static methods
 * @param types     the collection to which the types in the signatures of the remaining methods should be added
 * @return an integer with the only the bit in position 'category' set if at least one method was not stripped otherwise 0
 */
private int stripMethods(Klass klass, int type, int category, SquawkVector types) {
    if (false) Assert.that(category == VIRTUAL_METHODS || category == STATIC_METHODS);
    int count = getMemberCount(category);
    boolean keptAtLeastOne = false;
    if (count != 0) {
        for (int i = 0; i != count; ++i) {
            select(category, i);
            String name = getName();
            if (!PragmaException.isHosted(pragmas) &&               // strip methods called only in hosted VM mode
                !PragmaException.isInterpreterInvoked(pragmas) &&   // strip methods called from the interpreter
                (MethodMetadata.lineNumberTablesKept() ||           // if we want line numbers then we want method names too...
                    (retainMember(type, modifiers, null) &&
                    VM.isExported(klass.getMethod(i, category == STATIC_METHODS)))))
            {
                // keeping this method:
                if (!keptAtLeastOne) {
                    symbolsBuffer.addUnsignedByte(category);
                    keptAtLeastOne = true;
                }
                membersBuffer.reset();
                membersBuffer.addUnsignedShort(modifiers);
                membersBuffer.addUnsignedShort(getOffset());
                membersBuffer.addUtf8(name);
                if (Modifier.hasPragmas(modifiers)) {
                    membersBuffer.addUnsignedShort(pragmas);
                }
                int sigCount = getSignatureCount();
                for (int j = 0; j != sigCount; ++j) {
                    membersBuffer.addUnsignedShort(KlassMetadata.addSignatureType(types, getSignatureType(getSignatureAt(j))));
                }
                symbolsBuffer.add(membersBuffer);
            } else {
                // Stripping this method:
                if ((Modifier.isAbstract(modifiers) || klass.isInterface())
                    && !(Modifier.isPackagePrivate(modifiers) || Modifier.isSuitePrivate(klass.getModifiers()))) {
                    // If a class with abstract methods, or an interface, is exported from a suite, but the abstract methods are not exported,
                    // then there is no way to extend or implement the exported class or interface.
                    throw new IllegalStateException("Can't strip method " + name + " because it is abstract in a class exported from a suite: " + klass);
                }
                
                if (Klass.TRACING_ENABLED && Tracer.isTracing("stripping")) {
                    String signature = name;
                    int parameterCount = getSignatureCount() - 1;
                    if (parameterCount == 0) {
                        signature += "()";
                    } else {
                        StringBuffer strbuf = new StringBuffer(15);
                        strbuf.append('(');
                        for (int j = 0 ; j < parameterCount ; j++) {
                            Klass parameterType = getSignatureType(getSignatureAt(j + 1));
                            strbuf.append(parameterType.getInternalName());
                            if (j != parameterCount - 1) {
                                strbuf.append(',');
                            }
                        }
                        strbuf.append(')');
                        signature += strbuf.toString();
                    }
                    signature = getSignatureType(getSignatureAt(0)).getInternalName() + " " + signature;
                    Tracer.traceln("  discarded metadata for method: " + signature);
                }
            }
        }
    }
    return keptAtLeastOne ? 1 << category : 0;
}
 
開發者ID:sics-sse,項目名稱:moped,代碼行數:78,代碼來源:SymbolParser.java


注:本文中的com.sun.squawk.util.Tracer.traceln方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。