use of com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorDefinition in project pinpoint by naver.
the class ASMMethod method addInterceptor0.
private void addInterceptor0(Interceptor interceptor, int interceptorId) {
if (interceptor == null) {
throw new NullPointerException("interceptor must not be null");
}
final InterceptorDefinition interceptorDefinition = this.interceptorDefinitionFactory.createInterceptorDefinition(interceptor.getClass());
final Class<?> interceptorClass = interceptorDefinition.getInterceptorClass();
final CaptureType captureType = interceptorDefinition.getCaptureType();
if (this.methodNode.hasInterceptor()) {
logger.warn("Skip adding interceptor. 'already intercepted method' class={}, interceptor={}", this.declaringClass.getName(), interceptorClass.getName());
return;
}
if (this.methodNode.isAbstract() || this.methodNode.isNative()) {
logger.warn("Skip adding interceptor. 'abstract or native method' class={}, interceptor={}", this.declaringClass.getName(), interceptorClass.getName());
return;
}
int apiId = -1;
if (interceptorDefinition.getInterceptorType() == InterceptorType.API_ID_AWARE) {
apiId = this.apiMetaDataService.cacheApi(this.descriptor);
}
// add before interceptor.
if (isBeforeInterceptor(captureType) && interceptorDefinition.getBeforeMethod() != null) {
this.methodNode.addBeforeInterceptor(interceptorId, interceptorDefinition, apiId);
this.declaringClass.setModified(true);
} else {
if (isDebug) {
logger.debug("Skip adding before interceptorDefinition because the interceptorDefinition doesn't have before method: {}", interceptorClass.getName());
}
}
// add after interface.
if (isAfterInterceptor(captureType) && interceptorDefinition.getAfterMethod() != null) {
this.methodNode.addAfterInterceptor(interceptorId, interceptorDefinition, apiId);
this.declaringClass.setModified(true);
} else {
if (isDebug) {
logger.debug("Skip adding after interceptor because the interceptor doesn't have after method: {}", interceptorClass.getName());
}
}
}
use of com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorDefinition in project pinpoint by naver.
the class ASMMethodNodeAdapterTest method isVisited.
@Test
public void isVisited() throws Exception {
// init
final int interceptorId = interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(new ArgsArrayInterceptor());
final InterceptorDefinition interceptorDefinition = new InterceptorDefinitionFactory().createInterceptorDefinition(ArgsArrayInterceptor.class);
final String targetClassName = "com.navercorp.pinpoint.profiler.instrument.mock.ArgsClass";
final MethodNode methodNode = ASMClassNodeLoader.get(targetClassName, "arg");
ASMMethodNodeAdapter adapter = new ASMMethodNodeAdapter(JavaAssistUtils.javaNameToJvmName(targetClassName), methodNode);
assertEquals(false, adapter.hasInterceptor());
adapter.addBeforeInterceptor(interceptorId, interceptorDefinition, -1);
assertEquals(true, adapter.hasInterceptor());
}
use of com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorDefinition in project pinpoint by naver.
the class ASMMethodVariablesTest method initInterceptorLocalVariables.
@Test
public void initInterceptorLocalVariables() throws Exception {
MethodNode methodNode = ASMClassNodeLoader.get("com.navercorp.pinpoint.profiler.instrument.mock.ConstructorChildClass", "<init>");
ASMMethodVariables variables = new ASMMethodVariables("com/navercorp/pinpoint/profiler/instrument/mock/ConstructorChildClass", methodNode);
assertNull(variables.getEnterInsnNode());
assertNull(variables.getEnterInsnNode());
InterceptorRegistryBinder interceptorRegistryBinder = new DefaultInterceptorRegistryBinder();
int interceptorId = interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(new ArgsArrayInterceptor());
final InterceptorDefinition interceptorDefinition = new InterceptorDefinitionFactory().createInterceptorDefinition(ArgsArrayInterceptor.class);
InsnList instructions = new InsnList();
boolean first = variables.initInterceptorLocalVariables(instructions, interceptorId, interceptorDefinition, -1);
assertEquals(true, first);
assertNotNull(variables.getEnterInsnNode());
assertNotNull(variables.getEnterInsnNode());
}
use of com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorDefinition in project pinpoint by naver.
the class ASMMethodVariablesTest method hasInterceptor.
@Test
public void hasInterceptor() throws Exception {
InterceptorRegistryBinder interceptorRegistryBinder = new DefaultInterceptorRegistryBinder();
int interceptorId = interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(new ArgsArrayInterceptor());
final InterceptorDefinition interceptorDefinition = new InterceptorDefinitionFactory().createInterceptorDefinition(ArgsArrayInterceptor.class);
final ClassNode classNode = ASMClassNodeLoader.get("com.navercorp.pinpoint.profiler.instrument.mock.ArgsClass");
List<MethodNode> methodNodes = classNode.methods;
for (MethodNode methodNode : methodNodes) {
ASMMethodNodeAdapter methodNodeAdapter = new ASMMethodNodeAdapter(classNode.name, methodNode);
assertEquals(false, methodNodeAdapter.hasInterceptor());
methodNodeAdapter.addBeforeInterceptor(interceptorId, interceptorDefinition, -1);
assertEquals(true, methodNodeAdapter.hasInterceptor());
}
}
use of com.navercorp.pinpoint.profiler.instrument.interceptor.InterceptorDefinition in project pinpoint by naver.
the class ASMMethodNodeAdapterAddInterceptorTest method addInterceptor.
private Class addInterceptor(final int interceptorId, final String targetClassName, final Class<?> interceptorClass) {
final InterceptorDefinition interceptorDefinition = new InterceptorDefinitionFactory().createInterceptorDefinition(interceptorClass);
try {
classLoader.setTrace(false);
classLoader.setVerify(false);
classLoader.setTargetClassName(targetClassName);
classLoader.setCallbackHandler(new ASMClassNodeLoader.CallbackHandler() {
@Override
public void handle(ClassNode classNode) {
List<MethodNode> methodNodes = classNode.methods;
for (MethodNode methodNode : methodNodes) {
if (methodNode.name.equals("<clinit>")) {
continue;
}
ASMMethodNodeAdapter methodNodeAdapter = new ASMMethodNodeAdapter(classNode.name, methodNode);
if (methodNodeAdapter.isAbstract() || methodNodeAdapter.isNative()) {
continue;
}
methodNodeAdapter.addBeforeInterceptor(interceptorId, interceptorDefinition, 99);
methodNodeAdapter.addAfterInterceptor(interceptorId, interceptorDefinition, 99);
}
}
});
return classLoader.loadClass(targetClassName);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Aggregations