instrumentation

Embed the existing code of a method in a try-finally block

半世苍凉 提交于 2019-12-11 03:42:23
问题 I want to add instructions to the code of methods. These instructions should be executed after reaching and before leaving the method. In order to make sure that the latter instructions are always executed before leaving I want to put these in a finally block. (I know the class AdviceAdapter but it does not ensure the execution of exit-code when an invoked method throws an exception.) My problem is that the instructions in the result are in the wrong order. Method to be processed: @Test

Using Intel's PIN tool to count the number of cache hits/misses in a program

*爱你&永不变心* 提交于 2019-12-11 03:16:06
问题 I've been trying to write a pintool to instrument cache hits and misses in a given program. I found that there are calls such as INS_IsMemoryRead/Write to determine if the instruction is a LD/ST. Is there a way to determine if the instruction had a cache hit or miss? If so, is it also possible to get the number of cycles spent fetching the data from the cache/memory? 回答1: It is not possible to do neither of these. The cache tool, "Memory", which comes with pin is a very simple functional

How to create a jvmti agent to see all the loaded classes, objects and their field details

回眸只為那壹抹淺笑 提交于 2019-12-11 03:04:00
问题 I want to write a java agent to instrument some applications. I am interested in getting the details of the objects, (i.e. their fields) instantiated by the applications. I would also like to catch any read and write access to any of those objects/their fields while running. Can you please guide me in writing the agents and let me know what classes and methods should I explore. I just know about java.lang.instrument class. But I could not find anything there that could catch these events. I

AddressSanitizer Crash on GCC 4.8

China☆狼群 提交于 2019-12-11 02:15:32
问题 I've just tried out GCC 4.8's new exciting feature AddressSanitizer. The program #include <iostream> int main(int argc, const char * argv[], const char * envp[]) { int *x = nullptr; int y = *x; std::cout << y << std::endl; return 0; } compile find using g++-4.8 -std=gnu++0x -g -fsanitize=address -fno-omit-frame-pointer -Wall ~/h.cpp -o h but when I run the program I get ASAN:SIGSEGV ================================================================= ==7531== ERROR: AddressSanitizer crashed on

identifying ``method code too large`` origin

空扰寡人 提交于 2019-12-10 19:10:41
问题 So I've run into MY: WARNING cannot transform class XYZ java.lang.RuntimeException: Method code too large! at org.objectweb.asm.MethodWriter.a(Unknown Source) at org.objectweb.asm.ClassWriter.toByteArray(Unknown Source) at ... I am aware of Method code too large! exception using ASM and of the project it links to. However, I've been provided a modified version of ASM to work with and as such, using that project is not really an option. That will require my breaking up the offending methods

Observe running time of a Java code in cmd prompt

我的未来我决定 提交于 2019-12-10 12:03:14
问题 I have a java class file in my hand and can simply able to run it from windows cmd to view the output. Only thing I need to observe the running time of this java program depending on different input parameters. I don't have the source code so I can not modify it to generate the running time for me. Please suggest possible way out to observe this. Thanks in advance. 回答1: Wrap it in another class and run that. For example if your class (to which you dont have code) is called Runner then you may

bytecode instrumentation using ClassFileTransformer.transform

放肆的年华 提交于 2019-12-10 04:35:12
问题 I have written a Class with premain method and inside that method I have added a ClassFileTransformer to Instrumentation ( Instrumentation.addTransformer() ). I have invoked a application using java -javaagent:<path_to_agnet.jar> <application> However ClassFileTransformer.transform() method is not being invoked. I have observed that premain is being invoked. I have also observed that if I call Instrumentation.retransformClasses() , then ClassFileTransformer.transform() is being invoked. On

javassist loading a class file in the pre-main method (java instrumentation)

北城以北 提交于 2019-12-10 00:58:55
问题 I'm trying to load a specific class using javassist, I'm doing this inside a pre-main method as the follwoing: public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { byte[] byteCode = classfileBuffer; if(className.toLowerCase().endsWith("class1")) { ClassPool classPool = ClassPool.getDefault(); CtClass ctClass = classPool.get("com.class2"); } } but unfortuanetly

Cobertura : how to cover spring-data @Repository interfaces

半腔热情 提交于 2019-12-09 16:12:03
问题 Regarding following information : https://stackoverflow.com/a/14601831/704246 Cobertura does not instrument interfaces I'd like to know how to add spring-data interfaces to coverage results, since @Repository implementation classes are only declared and instantiated by Spring at runtime. Consider following interface : // src/main/java/my/package/MyObjectRepository.java @Repository public interface MyObjectRepository { MyObject findMyObjectByCodeAndName(String code, String name); } and

Difference between ActivityUnitTestCase and ActivityInstrumentationTestCase2

泄露秘密 提交于 2019-12-09 14:05:45
问题 I am new to Android Instrumentation cases. i have been looking at the API samples and see that sometimes we use ActivityUnitTestCase and the ActivityInstrumentationTestCase2. What is the difference between the two ? When would we use one over the other ? 回答1: See the difference discussed here: http://www.vogella.com/articles/AndroidTesting/article.html#activity_testing Key points: ActivityUnitTestCase can be used for testing layout and isolated methods. ActivityInstrumentationTestCase2 can be