jrunx.instrument
Class MethodInstrumentor

jrunx.kernel.ServiceAdapter
  |
  +--jrunx.instrument.MethodInstrumentor
All Implemented Interfaces:
Instrumentor, MethodInstrumentorMBean, javax.naming.Referenceable, java.io.Serializable, Service, ServiceMBean

public class MethodInstrumentor
extends ServiceAdapter
implements MethodInstrumentorMBean

See Also:
Serialized Form

Field Summary
static int CALL_ENTER
           
static int CALL_EXIT
           
protected static java.lang.reflect.Method currentTimeMillisMethod
           
static int DEFAULT_LOGGER
           
protected static java.lang.reflect.Method hashCodeMethod
           
protected static java.lang.reflect.Method logMethod
           
static int METHOD_ENTER
           
static int METHOD_EXIT
           
static int REQUEST_THREAD
           
protected static java.lang.ThreadLocal threadResults
           
 
Fields inherited from class jrunx.kernel.ServiceAdapter
DEFAULT_DEACTIVATED, DEFAULT_DOMAIN, DOMAIN_NAME_SEPARATOR, DOMAIN_NAME_SUFFIX, domainName, jndiBindable, LOGGER_CACHE_TIME, SCHEDULER_SERVICE, SECURITY_MANAGER, server, status, TRANSACTION_MANAGER
 
Fields inherited from interface jrunx.kernel.Service
INITIALIZED, STARTED, STARTING, STOPPED, STOPPING, UNINITIALIZED
 
Constructor Summary
MethodInstrumentor()
           
 
Method Summary
protected  int callCurrentTimeMillis(jrunx.instrument.BCMethod method, jrunx.instrument.Code code)
           
protected  jrunx.instrument.Instruction callLog(jrunx.instrument.BCMethod method, jrunx.instrument.Code code, jrunx.instrument.Instruction currentIns, int type, jrunx.instrument.MethodInstruction callMethod, int timerVar)
          Invokes the log method.
static void clearRequestThreadResults()
          Clears the instrumentation results
 java.util.List getClassNameList()
          Returns the list of className attributes
 boolean getDirectSubclasses()
          Returns the directSubclasses flag
 java.util.List getExcludeCallsToList()
          Returns the list of excludeCallsTo attributes
 boolean getInstrumentCalls()
          Returns the instrumentCalls flag
 java.util.List getInstrumentCallsToList()
          Returns the list of the instrumentCallsTo attributes
 java.util.List getInstrumentMethodList()
          Returns the list of the instrumentMethod attributes
 boolean getInstrumentMethods()
          Returns the instrumentMethods flag
protected static int getLineNumber(jrunx.instrument.BCMethod method, jrunx.instrument.Code code, jrunx.instrument.Instruction ins)
           
 java.lang.String getLoggingCallEnterLabel()
          Gets the method call entry description
 java.lang.String getLoggingCallExitLabel()
          Gets the method call exit description
 java.lang.String getLoggingDelimiter()
          Returns the logging delimiter
 java.lang.String getLoggingMethodEnterLabel()
          Gets the method entry description
 java.lang.String getLoggingMethodExitLabel()
          Gets the method exit description
 boolean getOutputToRequestThread()
          Returns the outputToRequestThread flag
 boolean getOutputToStandardLogger()
          Returns the outputToStandardLogger flag
static java.util.Set getRequestThreadResults()
          Gets the Set of MethodInstrumentationResult objects accumulated for this request.
protected static java.lang.String getSignature(java.lang.String[] types)
           
protected static void initMethods()
           
 byte[] instrument(java.lang.String name, byte[] bytes, java.lang.ClassLoader loader)
          Instrument the bytes of the class file.
protected  void instrumentCall(jrunx.instrument.BCMethod method, jrunx.instrument.Code code, jrunx.instrument.MethodInstruction ins, jrunx.instrument.Instruction lastValidLine, int timerVar)
           
protected  void instrumentMethod(jrunx.instrument.BCMethod method)
          Instrument the given method
protected  void instrumentMethods(com.techtrader.modules.tools.bytecode.BCClass bcClass)
          Instrument the methods of the given class
protected  void instrumentReturn(jrunx.instrument.BCMethod method, jrunx.instrument.Code code, jrunx.instrument.ReturnInstruction ret, jrunx.instrument.Instruction lastValidLine, int timerVar)
           
static void log(int target, int type, java.lang.String className, int hashCode, java.lang.String methodName, java.lang.String methodType, java.lang.String callClassName, java.lang.String callMethodName, java.lang.String callMethodType, int lineNo, long elapsed)
          Logs instrumentation info.
static void main(java.lang.String[] args)
          Just a test
protected  boolean match(java.lang.String name, java.util.List list)
          Determine if the given name matches an entry in the list.
protected  boolean match(java.lang.String name, java.util.List list, java.util.List excludeList)
          Determine if the given name matches an entry in the list.
protected  boolean match(java.lang.String name, java.lang.String value)
          Determine if the given name matches the value.
protected  boolean match(java.lang.String name, java.lang.String value, java.util.List excludeList)
          Determine if the given name matches the value.
 void setClassName(java.lang.String className)
          The name of the class(es) to instrument.
 void setDirectSubclasses(boolean direct)
          If true all direct subclasses of the class(es) given will also be instrumented
 void setExcludeCallsTo(java.lang.String exclude)
          The excludeCallsTo attribute specifies the method calls that will excluded when using method call instrumentation.
 void setInstrumentCalls(boolean instrumentCalls)
          If true method call instrumentation will be done.
 void setInstrumentCallsTo(java.lang.String callsTo)
          If using method call instrumentation, specifies which method calls will be instrumented.
 void setInstrumentMethod(java.lang.String method)
          The name of the method(s) to instrument within the class.
 void setInstrumentMethods(boolean instrumentMethods)
          If true method instrumentation will be done.
 void setLoggingCallEnterLabel(java.lang.String desc)
          Sets the description name used when logging instrumented method calls.
 void setLoggingCallExitLabel(java.lang.String desc)
          Sets the description name used when logging instrumented method calls.
 void setLoggingDelimiter(java.lang.String delimiter)
          Sets the delimiter used for the standard logger.
 void setLoggingMethodEnterLabel(java.lang.String desc)
          Sets the description name used when logging instrumented methods.
 void setLoggingMethodExitLabel(java.lang.String desc)
          Sets the description name used when logging instrumented methods.
 void setOutputToRequestThread(boolean requestThread)
          If true output from instrumentation will be sent to the request thread
 void setOutputToStandardLogger(boolean standardLogger)
          If true output from instrumentation will be sent to the standard logger
protected  boolean shouldInstrument(com.techtrader.modules.tools.bytecode.BCClass bcClass)
           
 void start()
          Every service other than mere data collections should start
 
Methods inherited from class jrunx.kernel.ServiceAdapter
bind, destroy, findObjectInstance, findObjectInstance, findObjectInstance, getBindToJNDI, getDeactivated, getDomainName, getDomainSearchPath, getJRunService, getLogger, getName, getParentService, getReference, getResourceManager, getServerName, getServerProperties, getStatus, init, invokeMethod, isInPartition, isPartition, lookup, postDeregister, postRegister, preDeregister, preRegister, requestServer, scheduleRunnable, setBindToJNDI, setDeactivated, setDomainName, setName, setParentService, stop, toString, unbind, unscheduleRunnable, updateStatus
 
Methods inherited from interface jrunx.kernel.ServiceMBean
bind, getBindToJNDI, getDeactivated, getDomainName, getJRunService, getLogger, getName, getParentService, getServerName, requestServer, setBindToJNDI, setDeactivated, setDomainName, setName, setParentService, unbind
 
Methods inherited from interface jrunx.kernel.Service
destroy, getStatus, init, stop, updateStatus
 

Field Detail

DEFAULT_LOGGER

public static final int DEFAULT_LOGGER

REQUEST_THREAD

public static final int REQUEST_THREAD

METHOD_ENTER

public static final int METHOD_ENTER

METHOD_EXIT

public static final int METHOD_EXIT

CALL_ENTER

public static final int CALL_ENTER

CALL_EXIT

public static final int CALL_EXIT

logMethod

protected static java.lang.reflect.Method logMethod

currentTimeMillisMethod

protected static java.lang.reflect.Method currentTimeMillisMethod

hashCodeMethod

protected static java.lang.reflect.Method hashCodeMethod

threadResults

protected static java.lang.ThreadLocal threadResults
Constructor Detail

MethodInstrumentor

public MethodInstrumentor()
Method Detail

setExcludeCallsTo

public void setExcludeCallsTo(java.lang.String exclude)
Description copied from interface: MethodInstrumentorMBean
The excludeCallsTo attribute specifies the method calls that will excluded when using method call instrumentation. This method may be called multiple times; the excludeCallsTo attribute is a list of method calls.
Specified by:
setExcludeCallsTo in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Parameters:
exclude - The exclude attribute

getExcludeCallsToList

public java.util.List getExcludeCallsToList()
Description copied from interface: MethodInstrumentorMBean
Returns the list of excludeCallsTo attributes
Specified by:
getExcludeCallsToList in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Returns:
The list of excluded method calls, each being a String value

setClassName

public void setClassName(java.lang.String className)
Description copied from interface: MethodInstrumentorMBean
The name of the class(es) to instrument. This can include a single wildcard '*' at the end of the class value. Any number of class attributes can be specified.
Specified by:
setClassName in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Parameters:
className - The class to instrument

getClassNameList

public java.util.List getClassNameList()
Description copied from interface: MethodInstrumentorMBean
Returns the list of className attributes
Specified by:
getClassNameList in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Returns:
The list of class(es) to instrument, each being a String value

setDirectSubclasses

public void setDirectSubclasses(boolean direct)
Description copied from interface: MethodInstrumentorMBean
If true all direct subclasses of the class(es) given will also be instrumented
Specified by:
setDirectSubclasses in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Parameters:
direct - Instrument direct subclasses

getDirectSubclasses

public boolean getDirectSubclasses()
Description copied from interface: MethodInstrumentorMBean
Returns the directSubclasses flag
Specified by:
getDirectSubclasses in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Returns:
true if direct subclasses should be instrumented

setInstrumentMethods

public void setInstrumentMethods(boolean instrumentMethods)
Description copied from interface: MethodInstrumentorMBean
If true method instrumentation will be done. This will cause only methods defined within the class to be instrumented.
Specified by:
setInstrumentMethods in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Parameters:
instrumentMethods - Instrument methods

getInstrumentMethods

public boolean getInstrumentMethods()
Description copied from interface: MethodInstrumentorMBean
Returns the instrumentMethods flag
Specified by:
getInstrumentMethods in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Returns:
true if methods should be instrumented

setInstrumentMethod

public void setInstrumentMethod(java.lang.String method)
Description copied from interface: MethodInstrumentorMBean
The name of the method(s) to instrument within the class. This can include a single wildcard '*' at the end of the method value. Any number of instrumentMethod attributes can be specified.
Specified by:
setInstrumentMethod in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Parameters:
instrumentMethod - The name of the method(s) to instrument

getInstrumentMethodList

public java.util.List getInstrumentMethodList()
Description copied from interface: MethodInstrumentorMBean
Returns the list of the instrumentMethod attributes
Specified by:
getInstrumentMethodList in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Returns:
The list of methods to instrument, each being a String value

setInstrumentCalls

public void setInstrumentCalls(boolean instrumentCalls)
Description copied from interface: MethodInstrumentorMBean
If true method call instrumentation will be done. This includes method instrumentation as well as all method calls within each instrumented method.
Specified by:
setInstrumentCalls in interface MethodInstrumentorMBean

getInstrumentCalls

public boolean getInstrumentCalls()
Description copied from interface: MethodInstrumentorMBean
Returns the instrumentCalls flag
Specified by:
getInstrumentCalls in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Returns:
true if method calls should be instrumented

setInstrumentCallsTo

public void setInstrumentCallsTo(java.lang.String callsTo)
Description copied from interface: MethodInstrumentorMBean
If using method call instrumentation, specifies which method calls will be instrumented. This can include a single wildcard '*' at the end of the value. Any number of instrumentCallsTo attributes can be specified.
Specified by:
setInstrumentCallsTo in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Parameters:
callstTo - The name of the method call(s) to instrument

getInstrumentCallsToList

public java.util.List getInstrumentCallsToList()
Description copied from interface: MethodInstrumentorMBean
Returns the list of the instrumentCallsTo attributes
Specified by:
getInstrumentCallsToList in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Returns:
The list of method calls to instrument, each being a String value

setOutputToStandardLogger

public void setOutputToStandardLogger(boolean standardLogger)
Description copied from interface: MethodInstrumentorMBean
If true output from instrumentation will be sent to the standard logger
Specified by:
setOutputToStandardLogger in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Parameters:
standardLogger - true if output should be sent to the standard logger

getOutputToStandardLogger

public boolean getOutputToStandardLogger()
Description copied from interface: MethodInstrumentorMBean
Returns the outputToStandardLogger flag
Specified by:
getOutputToStandardLogger in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Returns:
true if output should be sent to the standard logger

setOutputToRequestThread

public void setOutputToRequestThread(boolean requestThread)
Description copied from interface: MethodInstrumentorMBean
If true output from instrumentation will be sent to the request thread
Specified by:
setOutputToRequestThread in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Parameters:
requestThread - true if output should be sent to the request thread

getOutputToRequestThread

public boolean getOutputToRequestThread()
Description copied from interface: MethodInstrumentorMBean
Returns the outputToRequestThread flag
Specified by:
getOutputToRequestThread in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Returns:
true if output should be sent to the request thread

setLoggingDelimiter

public void setLoggingDelimiter(java.lang.String delimiter)
Description copied from interface: MethodInstrumentorMBean
Sets the delimiter used for the standard logger. A log message is creating using the instrumentation data; this delimiter is used to separate each entry. The default is a space " "
Specified by:
setLoggingDelimiter in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Parameters:
delimiter - The delimiter

getLoggingDelimiter

public java.lang.String getLoggingDelimiter()
Description copied from interface: MethodInstrumentorMBean
Returns the logging delimiter
Specified by:
getLoggingDelimiter in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Returns:
the logging delimiter

setLoggingMethodEnterLabel

public void setLoggingMethodEnterLabel(java.lang.String desc)
Description copied from interface: MethodInstrumentorMBean
Sets the description name used when logging instrumented methods. A log message is created using the instrumentation data; this description is used to identify that the message defines a method entry. The default is "METHOD ENTER"
Specified by:
setLoggingMethodEnterLabel in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Parameters:
desc - The description

getLoggingMethodEnterLabel

public java.lang.String getLoggingMethodEnterLabel()
Description copied from interface: MethodInstrumentorMBean
Gets the method entry description
Specified by:
getLoggingMethodEnterLabel in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Returns:
The description

setLoggingMethodExitLabel

public void setLoggingMethodExitLabel(java.lang.String desc)
Description copied from interface: MethodInstrumentorMBean
Sets the description name used when logging instrumented methods. A log message is created using the instrumentation data; this description is used to identify that the message defines a method exit. The default is "METHOD EXIT"
Specified by:
setLoggingMethodExitLabel in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Parameters:
desc - The description

getLoggingMethodExitLabel

public java.lang.String getLoggingMethodExitLabel()
Description copied from interface: MethodInstrumentorMBean
Gets the method exit description
Specified by:
getLoggingMethodExitLabel in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Returns:
The description

setLoggingCallEnterLabel

public void setLoggingCallEnterLabel(java.lang.String desc)
Description copied from interface: MethodInstrumentorMBean
Sets the description name used when logging instrumented method calls. A log message is created using the instrumentation data; this description is used to identify that the message defines a method call entry. The default is "CALL ENTER"
Specified by:
setLoggingCallEnterLabel in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Parameters:
desc - The description

getLoggingCallEnterLabel

public java.lang.String getLoggingCallEnterLabel()
Description copied from interface: MethodInstrumentorMBean
Gets the method call entry description
Specified by:
getLoggingCallEnterLabel in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Returns:
The description

setLoggingCallExitLabel

public void setLoggingCallExitLabel(java.lang.String desc)
Description copied from interface: MethodInstrumentorMBean
Sets the description name used when logging instrumented method calls. A log message is created using the instrumentation data; this description is used to identify that the message defines a method call exit. The default is "CALL EXIT"
Specified by:
setLoggingCallExitLabel in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Parameters:
desc - The description

getLoggingCallExitLabel

public java.lang.String getLoggingCallExitLabel()
Description copied from interface: MethodInstrumentorMBean
Gets the method call exit description
Specified by:
getLoggingCallExitLabel in interface MethodInstrumentorMBean
Following copied from interface: jrunx.instrument.MethodInstrumentorMBean
Returns:
The description

start

public void start()
           throws java.lang.Exception
Description copied from class: ServiceAdapter
Every service other than mere data collections should start
Specified by:
start in interface Service
Overrides:
start in class ServiceAdapter

instrument

public byte[] instrument(java.lang.String name,
                         byte[] bytes,
                         java.lang.ClassLoader loader)
                  throws java.io.IOException
Description copied from interface: Instrumentor
Instrument the bytes of the class file.
Specified by:
instrument in interface Instrumentor
Following copied from interface: jrunx.instrument.Instrumentor
Parameters:
name - The class name
bytes - The class bytes
loader - The ClassLoader that loaded the class
Returns:
The (potentially) modified class

shouldInstrument

protected boolean shouldInstrument(com.techtrader.modules.tools.bytecode.BCClass bcClass)

match

protected boolean match(java.lang.String name,
                        java.util.List list)
Determine if the given name matches an entry in the list. Each entry is a String and may contain a single ending wildcard '*'

match

protected boolean match(java.lang.String name,
                        java.util.List list,
                        java.util.List excludeList)
Determine if the given name matches an entry in the list. Each entry is a String and may contain a single ending wildcard '*'

match

protected boolean match(java.lang.String name,
                        java.lang.String value)
Determine if the given name matches the value. the value may contain a single ending wildcard '*'

match

protected boolean match(java.lang.String name,
                        java.lang.String value,
                        java.util.List excludeList)
Determine if the given name matches the value. the value may contain a single ending wildcard '*'

instrumentMethods

protected void instrumentMethods(com.techtrader.modules.tools.bytecode.BCClass bcClass)
                          throws java.io.IOException
Instrument the methods of the given class

instrumentMethod

protected void instrumentMethod(jrunx.instrument.BCMethod method)
                         throws java.io.IOException
Instrument the given method

initMethods

protected static void initMethods()
                           throws java.io.IOException

instrumentReturn

protected void instrumentReturn(jrunx.instrument.BCMethod method,
                                jrunx.instrument.Code code,
                                jrunx.instrument.ReturnInstruction ret,
                                jrunx.instrument.Instruction lastValidLine,
                                int timerVar)

instrumentCall

protected void instrumentCall(jrunx.instrument.BCMethod method,
                              jrunx.instrument.Code code,
                              jrunx.instrument.MethodInstruction ins,
                              jrunx.instrument.Instruction lastValidLine,
                              int timerVar)

callCurrentTimeMillis

protected int callCurrentTimeMillis(jrunx.instrument.BCMethod method,
                                    jrunx.instrument.Code code)

callLog

protected jrunx.instrument.Instruction callLog(jrunx.instrument.BCMethod method,
                                               jrunx.instrument.Code code,
                                               jrunx.instrument.Instruction currentIns,
                                               int type,
                                               jrunx.instrument.MethodInstruction callMethod,
                                               int timerVar)
Invokes the log method.

getLineNumber

protected static int getLineNumber(jrunx.instrument.BCMethod method,
                                   jrunx.instrument.Code code,
                                   jrunx.instrument.Instruction ins)

getSignature

protected static java.lang.String getSignature(java.lang.String[] types)

log

public static void log(int target,
                       int type,
                       java.lang.String className,
                       int hashCode,
                       java.lang.String methodName,
                       java.lang.String methodType,
                       java.lang.String callClassName,
                       java.lang.String callMethodName,
                       java.lang.String callMethodType,
                       int lineNo,
                       long elapsed)
Logs instrumentation info. This is the single entry point for logging.
Parameters:
target - The logging target (DEFAULT_LOGGER, REQUEST_THREAD, or both)
type - The type of instrumentation (METHOD_ENTER, METHOD_EXIT, CALL_ENTER, CALL_EXIT)
className - The name of the class
hashCode - The object hashcode
methodName - The name of the method
methodType - The type (signature) of the method
callClassName - The class name of the method being called
callMethodName - The name of the method being called
callMethodType - The type (signature) of the method being called
lineNo - The source line number, or 0 if not known
elapsed - The elapsed time spent in the method or method call

getRequestThreadResults

public static java.util.Set getRequestThreadResults()
Gets the Set of MethodInstrumentationResult objects accumulated for this request. Returns null if not logging instrumentation to the request thread, or instrumentation is not currently active.

clearRequestThreadResults

public static void clearRequestThreadResults()
Clears the instrumentation results

main

public static void main(java.lang.String[] args)
Just a test


Copyright � 2002 Macromedia Corporation. All Rights Reserved.