001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: MetricsClassVisitor.java 3810 2007-06-25 13:36:58Z gbevin $
007: */
008: package com.uwyn.rife.continuations.instrument;
009:
010: import com.uwyn.rife.asm.*;
011:
012: import com.uwyn.rife.continuations.ContinuationConfigInstrument;
013: import com.uwyn.rife.continuations.instrument.ContinuationDebug;
014: import com.uwyn.rife.continuations.instrument.MetricsMethodVisitor;
015: import com.uwyn.rife.continuations.instrument.NoOpAnnotationVisitor;
016: import java.util.ArrayList;
017: import java.util.logging.Level;
018:
019: class MetricsClassVisitor implements ClassVisitor {
020: private ContinuationConfigInstrument mConfig = null;
021: private String mClassName = null;
022: private String mEntryMethodName = null;
023: private String mEntryMethodDesc = null;
024: private int mMaxLocals = -1;
025: private int mPauseCount = -1;
026: private int mAnswerCount = -1;
027: private ArrayList<String> mExceptionTypes = null;
028: private NoOpAnnotationVisitor mAnnotationVisitor = new NoOpAnnotationVisitor();
029:
030: MetricsClassVisitor(ContinuationConfigInstrument config,
031: String className) {
032: mConfig = config;
033: mClassName = className;
034: mEntryMethodName = config.getEntryMethodName();
035: mEntryMethodDesc = Type.getMethodDescriptor(config
036: .getEntryMethodReturnType(), config
037: .getEntryMethodArgumentTypes());
038: }
039:
040: void setMaxLocals(int maxLocals) {
041: ///CLOVER:OFF
042: if (ContinuationDebug.LOGGER.isLoggable(Level.FINEST))
043: ContinuationDebug.LOGGER.finest("maxlocals = " + maxLocals);
044: ///CLOVER:ON
045:
046: mMaxLocals = maxLocals;
047: }
048:
049: int getMaxLocals() {
050: return mMaxLocals;
051: }
052:
053: void setPauseCount(int pauseCount) {
054: ///CLOVER:OFF
055: if (ContinuationDebug.LOGGER.isLoggable(Level.FINEST))
056: ContinuationDebug.LOGGER.finest("pauseCount = "
057: + pauseCount);
058: ///CLOVER:ON
059:
060: mPauseCount = pauseCount;
061: }
062:
063: void setAnswerCount(int answerCount) {
064: ///CLOVER:OFF
065: if (ContinuationDebug.LOGGER.isLoggable(Level.FINEST))
066: ContinuationDebug.LOGGER.finest("answerCount = "
067: + answerCount);
068: ///CLOVER:ON
069:
070: mAnswerCount = answerCount;
071: }
072:
073: void setExceptionTypes(ArrayList<String> exceptionTypes) {
074: mExceptionTypes = exceptionTypes;
075: }
076:
077: String nextExceptionType() {
078: return mExceptionTypes.remove(0);
079: }
080:
081: int getPauseCount() {
082: return mPauseCount;
083: }
084:
085: int getAnswerCount() {
086: return mAnswerCount;
087: }
088:
089: boolean makeResumable() {
090: return mPauseCount > 0 || mAnswerCount > 0;
091: }
092:
093: public MethodVisitor visitMethod(int access, String name,
094: String desc, String signature, String[] exceptions) {
095: if (mEntryMethodName.equals(name)
096: && mEntryMethodDesc.equals(desc)) {
097: return new MetricsMethodVisitor(mConfig, this , mClassName);
098: }
099:
100: return null;
101: }
102:
103: public void visitInnerClass(String name, String outerName,
104: String innerName, int access) {
105: }
106:
107: public void visit(int version, int access, String name,
108: String signature, String super Name, String[] interfaces) {
109: }
110:
111: public FieldVisitor visitField(int access, String name,
112: String desc, String signature, Object value) {
113: return null;
114: }
115:
116: public void visitAttribute(Attribute attr) {
117: }
118:
119: public void visitSource(String source, String debug) {
120: }
121:
122: public void visitOuterClass(String owner, String name, String desc) {
123: }
124:
125: public AnnotationVisitor visitAnnotation(String desc,
126: boolean visible) {
127: return mAnnotationVisitor;
128: }
129:
130: public void visitEnd() {
131: }
132: }
|