Since Byteman only needs access to bytecode this means it can modify library code whose source is either unavailable or unable to be recompiled. Byteman works out how to rewrite the bytecode so it behaves as if the the original Java code included the source level changes you have requested. You give Byteman one or more rules which specify the Java code you want to be executed and the location in methods of application or runtime classes where you want it to be injected. However, unlike many other bytecode transformers it operates at the level of Java not bytecode. BMUnit is easily integrated into maven and ant projects.īyteman works by modifying the bytecode of your application classes at runtime. The Byteman BMUnit package integrates Byteman with JUnit and TestNG making it easy for you to use Byteman to extend the range of your unit and integration tests. One very useful option, commonly used when testing multi-threaded applications, is to inject delays or synchronization operations which engineer at test time execution timings that are normally only encountered on rare occasions at deployment time. Alternatively, you might need to reset (method) local or (static) global state or call out to other parts of the application or runtime. The required side-effect might be as simple as forcing a method to throw an exception or to return a synthetic result. This allows you to force a test to enter and fully exercise a test scenario reliably and repeatably. Secondly, it can inject faults or other side effects which cause your application to perform unusual or unexpected operations. Firstly, Byteman can inject code which checks the flow of control or the state of application and runtime data, failing the test if the program does not operate as expected. Two more complex use cases arise when you use Byteman to test your application. It doesn't need the original source code to be available in order to do so. Byteman will inject into any Java methods, including Java libraries and the JDK runtime. Finally, you are not just limited to tracing your own code. Also, you get to decide what to trace when you run your application rather than when you write it so, you don't need 100% hindsight to be able to display the information you need. By injecting code at very specific locations you avoid the expensive performance overheads which normally arise when you switch on debug or product trace. This can be used for monitoring or debugging live deployments as well as for instrumenting code under test so that you can be sure it has operated correctly. Note that not all hangs are going to be due to deadlocks, and there are many tools (including Eclipse) that will help you analyse thread dumps.The simplest use of Byteman is to inject print statements that trace what your application is doing, identifying control flow through your code and displaying the values of static or instance data. Unfortunately this never happens and all the philosophers starve.ĭownload the thread dump from here (7 KB). In the example below (shown using tda), we can see that the 5 Philosopher threads each have a lock on a Fork object and are each waiting to obtain a lock on a second Fork object before they can eat. Taking example code from Concurrency: State Models & Java Programs, we can cause a deadlock situation and then create a thread dump. You can generate a thread dump under Unix/Linux by running kill -QUIT, and under Windows by hitting Ctl + Break.Ī great example of where this would be useful is the well-known Dining Philosophers deadlocking problem. This is especially useful if your Java application sometimes seems to hang when running under load, as an analysis of the dump will show where the threads are stuck. A Java thread dump is a way of finding out what every thread in the JVM is doing at a particular point in time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |