|
Added
Link Here
|
| 1 |
/********************************************************************** |
| 2 |
* Copyright (c) 2007 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM - Initial API and implementation |
| 10 |
***********************************************************************/ |
| 11 |
package org.eclipse.tptp.trace.arm.internal.loader; |
| 12 |
|
| 13 |
import java.lang.reflect.InvocationTargetException; |
| 14 |
import java.lang.reflect.Method; |
| 15 |
|
| 16 |
/** |
| 17 |
* Brokers probe invocations from probekit probes to probe implementation found |
| 18 |
* in the src-model package. |
| 19 |
* |
| 20 |
* @author ashishp |
| 21 |
* @since 4.4 |
| 22 |
*/ |
| 23 |
public class ProbeHandler { |
| 24 |
|
| 25 |
/** |
| 26 |
* Returns a handle to the method in the probe for invocation purposes. |
| 27 |
* |
| 28 |
* @param probeClassName is the name of the class that implements the probe. |
| 29 |
* @param methodName is the entry point in the probe. |
| 30 |
* @param parameterTypes indicates teh method signature of the entry point in the probe. |
| 31 |
* @return handle to the method in the probe for invocation purposes. |
| 32 |
* @throws ClassNotFoundException |
| 33 |
* @throws SecurityException |
| 34 |
* @throws NoSuchMethodException |
| 35 |
*/ |
| 36 |
public static Method getMethod(String probeClassName, String methodName, Class[] parameterTypes) |
| 37 |
throws ClassNotFoundException, SecurityException, NoSuchMethodException { |
| 38 |
Class probeClass = BootClassLoader.getClass(probeClassName, true); |
| 39 |
return probeClass.getMethod(methodName, parameterTypes); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Entry point in the Probe. |
| 44 |
* |
| 45 |
* @param probeClassName is the name of the class that implements the probe. |
| 46 |
* @param _className is the class name that the probe was injected into. |
| 47 |
* @param _methodName is the name of the method that was injected. |
| 48 |
* @param _thisObject a reference to the object instance that this probe was invoked on. |
| 49 |
* @param _methodArgs is a reference to the arguments of the instrumented method. |
| 50 |
*/ |
| 51 |
public static void _entry(String probeClassName, |
| 52 |
String _className, String _methodName, |
| 53 |
Object _thisObject, Object[] _methodArgs) { |
| 54 |
try { |
| 55 |
Method m = getMethod(probeClassName, "_entry", |
| 56 |
new Class[] { String.class, String.class, Object.class, Object[].class }); |
| 57 |
m.invoke(null, new Object[] { _className, _methodName, _thisObject, _methodArgs }); |
| 58 |
} catch (IllegalArgumentException e) { |
| 59 |
e.printStackTrace(System.err); |
| 60 |
} catch (IllegalAccessException e) { |
| 61 |
e.printStackTrace(System.err); |
| 62 |
} catch (InvocationTargetException e) { |
| 63 |
e.printStackTrace(System.err); |
| 64 |
} catch (SecurityException e) { |
| 65 |
e.printStackTrace(System.err); |
| 66 |
} catch (ClassNotFoundException e) { |
| 67 |
e.printStackTrace(System.err); |
| 68 |
} catch (NoSuchMethodException e) { |
| 69 |
e.printStackTrace(System.err); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Exit point in the Probe. |
| 75 |
* |
| 76 |
* @param probeClassName is the name of the class that implements the probe. |
| 77 |
* @param _className is the class name that the probe was injected into. |
| 78 |
* @param _methodName is the name of the method that was injected. |
| 79 |
*/ |
| 80 |
public static void _exit(String probeClassName, |
| 81 |
String _className, String _methodName) { |
| 82 |
try { |
| 83 |
Method m = getMethod(probeClassName, "_exit", |
| 84 |
new Class[] { String.class, String.class }); |
| 85 |
m.invoke(null, new Object[] { _className, _methodName }); |
| 86 |
} catch (IllegalArgumentException e) { |
| 87 |
e.printStackTrace(System.err); |
| 88 |
} catch (IllegalAccessException e) { |
| 89 |
e.printStackTrace(System.err); |
| 90 |
} catch (InvocationTargetException e) { |
| 91 |
e.printStackTrace(System.err); |
| 92 |
} catch (SecurityException e) { |
| 93 |
e.printStackTrace(System.err); |
| 94 |
} catch (ClassNotFoundException e) { |
| 95 |
e.printStackTrace(System.err); |
| 96 |
} catch (NoSuchMethodException e) { |
| 97 |
e.printStackTrace(System.err); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Catch point in the Probe. |
| 103 |
* |
| 104 |
* @param probeClassName is the name of the class that implements the probe. |
| 105 |
* @param _className is the class name that the probe was injected into. |
| 106 |
* @param _methodName is the name of the method that was injected. |
| 107 |
*/ |
| 108 |
public static void _catch(String probeClassName, |
| 109 |
String _className, String _methodName) { |
| 110 |
try { |
| 111 |
Method m = getMethod(probeClassName, "_catch", |
| 112 |
new Class[] { String.class, String.class }); |
| 113 |
m.invoke(null, new Object[] { _className, _methodName }); |
| 114 |
} catch (IllegalArgumentException e) { |
| 115 |
e.printStackTrace(System.err); |
| 116 |
} catch (IllegalAccessException e) { |
| 117 |
e.printStackTrace(System.err); |
| 118 |
} catch (InvocationTargetException e) { |
| 119 |
e.printStackTrace(System.err); |
| 120 |
} catch (SecurityException e) { |
| 121 |
e.printStackTrace(System.err); |
| 122 |
} catch (ClassNotFoundException e) { |
| 123 |
e.printStackTrace(System.err); |
| 124 |
} catch (NoSuchMethodException e) { |
| 125 |
e.printStackTrace(System.err); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
} |