| Content Aware Intelligent Web Graphics | Table of contents | Indexes | XLink and Publishing Opportunities | |||
Dima, Alden Gaithersburg ![]() National Institute of Standards and Technology USA ![]() | Alden Dima |
| Computer Scientist |
| National Institute of Standards and Technology |
| 100 Bureau Dr. Stop 8970
Gaithersburg
(Maryland)
USA
(20899-8970)
Email: mailto:alden.dima@nist.gov |
| Biography |
Introduction |
What is VMView? |
| VMView has several potential uses including debugging Java applications and identifying potentially malicious code. These two uses are discussed below. |
Debugging Java Applications |
| Java programmers typically implement these two strategies in the following ways: |
public class HelloWorld { |
public static void main(String[] argv) { |
System.out.println("Hello, World!"); |
} |
} |
Tracing Java Applications with VMView |
THREAD_START: Thread[main,5,main] |
CLASS_LOAD |
THREAD: Thread[main,5,main] |
CLASS: [Ljava/lang/String; |
METHOD_TRACE |
METHOD: LSimpleExample; main([Ljava/lang/String;)V |
LOCATION: 0 (method start) |
THREAD: Thread[main,5,main] |
PARAMETERS: |
[Ljava/lang/String; s = [Ljava.lang.String;@48a82fb6 |
BYTECODE_TRACE |
METHOD: LSimpleExample; main([Ljava/lang/String;)V |
THREAD: Thread[main,5,main] |
00000: new |
00003: dup |
00004: invokespecial |
EXCEPTION |
TYPE: java.lang.ClassNotFoundException: javax/swing/plaf/basic/resources/basic_en_US |
THROWN_BY: Thread[main,5,main] |
THROWN_AT: Ljava/lang/ClassLoader; loadClass(Ljava/lang/String;Z)Ljava/lang/Class; @ 32 |
TARGET: Ljava/lang/ClassLoader; loadClass(Ljava/lang/String;Z)Ljava/lang/Class; @ 39 |
VMView Issues |
| Despite what has been accomplished with VMView, there is room for improvement in a number of areas. We have identified the following issues: |
VMView/XML Goals |
| We are currently in the process of reworking VMView to make use of XML. Our goals for this new version of VMView are: |
|
VMView/XML Architecture |
| We have re-architected VMView as shown in Figure 1. The VMView DLL has been modified to generate an XML-based trace. A new Swing/JFC-based GUI has been created that allows the user to filter the XML-based trace and invoke a standard Web browser to view the trace. |
|
Generating XML-based Traces |
| The VMView execution trace document type definition (DTD) evolved as we worked with filtering and translating the XML-based trace. The first two VMView/XML goals directly impacted the design of the XML-based trace output. Execution tracing is both processor- and disk-intensive. The structure of the execution trace has to be relatively efficient. However, a "human-friendly" structure also facilitates debugging and maintenance, so a balanced approach is essential, especially during early development. Since the new trace filtering capabilities are critical, the structure of the trace must also reflect its needs. We discovered that a flatter, less nested design simplified the design of the trace filter and took advantage of this fact in our work. |
| The major change required to generate an XML-based trace was to find and modify all the ASCII-text generating output code in the VMView DLL. The VMView execution trace DTD was also embedded with the DLL so that all VMView output contains its logical structure regardless of how the VMView DLL is used. |
| These changes were straightforward. The XML-based output is generated using C++'s iostream facility. Individual tags were defined in a header file - for example the following defines the tags for a method call event: |
const string CALL_O = string("<CALL>"); |
const string CALL_C = string("</CALL>"); |
| The trace itself is created using the C++ string concatenation operator to build up each item in the trace. For example, a portion of the method call element is created as: |
traceLine += IN_1 + CLASS_O + className + CLASS_C |
+ IN_1 + MTD_O + CDATA_O + methodName + CDATA_C + MTD_C |
+ IN_1 + SIG_O + methodSig + SIG_C |
+ IN_1 + LOC_O + locationString + LOC_C |
+ IN_1 + THRD_O + threadString + THRD_C; |
| IN_1 is a formatting instruction that indents the output one level. It is one of several formatting instructions that make the trace more human readable. |
| There were places where we had to use CDATA tags to avoid interpreting element data as tags. For example, the Java Virtual Machine uses the method name <init> for object constructors. Object instance string representations can also contain characters that can be misinterpreted as XML tags, requiring the use of CDATA tags. |
| The result of these design issues can be seen in the following trace event element: |
<THROW> |
<MSG><![CDATA[java.util.EmptyStackException]]></MSG> |
<THRD>Thread[main,5,main]</THRD> |
<CLASS>Ljava/util/Stack;</CLASS> |
<MTD><![CDATA[peek]]></MTD> |
<SIG>()Ljava/lang/Object;</SIG> |
<LOC>16</LOC> |
<CLASS2>Ljava/util/Stack;</CLASS2> |
<MTD2><![CDATA[main]]></MTD2> |
<SIG2>()Ljava/lang/Object;</SIG2> |
<LOC2>26</LOC2> |
</THROW> |
| As previously mentioned, the filtering of traces was also simplified by using a flatter format rather than a more deeply nested format. Evidence of this approach can be seen in the exception event element shown above. The last four elements have a "2" suffix instead of being nested inside a <HANDLER> element. |
Filtering Traces |
| Once a trace is generated, events can be filtered using a user-specified set of regular expressions. The user can filter on multiple event fields and across multiple event types simultaneously. The user interface associated with trace filtering is shown in Figure 2. |
|
| Two XML-related APIs were available to implement the trace filtering mechanism. The Simple API for XML (SAX) is an event-driven API for processing XML documents. It implements a simple method of processing XML documents - reading the content as a stream of data and treating markup tags as events. The Document Object Model (DOM) takes an alternative approach: it makes the entire document available to the processor in a "random-access" mode. [1] |
| Because of the potential for large documents, we have implemented the filter using SAX rather than DOM to avoid excessive memory requirements. The use of DOM implies the existence of a large number of Java objects, one for each XML element in an execution trace. With a SAX-based implementation, the trace filter only has to deal with one VM event at a time. With proper care, the filter can be implemented to reduce the burden on Java's garbage collector and improve overall performance. The IBM SAX-based parser has worked well with some rather large traces. |
| The trace filter extends org.xml.sax.HandlerBase that serves as the default behavior for four of the SAX interfaces including the document handler interface. It is associated with a new parser instance via the parser's setDocumentHandler method and responds to events generated by the parser. For example, the parser will call the trace filter's character method when an element's character data is parsed. The trace filter will respond by adding this content to the Java object that represents the current element being parsed. When the parser generates the endElement event and the element in question represents a VM event, the element object will check itself against a set of user-specified regular expressions to determine if it belongs in the trace. If it does, it will print itself. Figure 3 illustrates trace filtering as a Unified Modeling Language (UML) sequence diagram. UML is rapidly becoming the dominant notation in object-oriented programming and consists of a number of standardized diagrams. UML sequence diagrams are particularly useful for illustrating the handling of messages and events within a system. |
|
Viewing Traces |
| To minimize the development effort, we chose to make use of existing Internet browsers to view the output traces. At present VMView implements a Java-based XML to HTML 4.0 translator that translates the execution trace and embeds a cascading style sheet prior to viewing. We investigated directly browsing the XML-based trace via style sheets, but in the end decided to use HTML translation. We looked at using CSS2 but the current browser implementations do not provide the needed CSS2 functionality for our application. The key missing feature was the ability to generate text via the CSS2 content keyword. This is necessary since for our application, we want to generate a field label next to the element value when viewing the trace. Future implementations will re-implement this functionality using XSL. |
| The translation to HTML is not a problem since the trace format suits our current needs. There is no need to perform radical transformations - yet. In the future, we plan to directly browse the XML traces via XSL-based style sheets. The XML to HTML translation is accomplished via a relatively simple Java program that uses regular expression to match and replace the XML tags with HTML tags and generated text. We made use of the HTML 4.0 class feature and span tags and embedded a CSS stylesheet into the output. Figure 4 shows how a VMView trace appears in Microsoft Internet Explorer 5. |
|
Searching Traces |
| A VMView trace can be searched for events through repeated filtering. What is currently lacking however, is the ability to relate an element in a filtered trace back to its original trace so that a better picture of its context emerges. A simple way of accomplishing this would be to give each VM event a unique ID, so that it can quickly be found in the original trace after filtering. A better approach would involve modifying the trace filter to maintain an index of the events in the original trace for quick lookup afterwards. We plan to further develop this approach. |
| We are also considering other means of building XML-based trace searching into VMView/XML. Web browsers such as Microsoft Internet Explorer do provide simple text searching capabilities, but we would like to create a browser-based search facility for complex context-sensitive searches. This could be implemented either using the browser's internal XML parser or a Java applet. |
Benefits of using XML |
| While working on VMView/XML, we discovered several benefits to using a XML-based approach when implementing diagnostic tools such as VMView. We were able to use a validating XML parser to automatically ensure that the tool's output is well formed and follows the logical structure defined in the DTD. This saved us from either having to perform additional tedious manual verification of the output or having to create a custom parser for this purpose. |
| It was easy to implement output filtering using existing XML parsers and to translate the trace to other formats even when using our simple "brute force" techniques. The alternative would have been to implement a traditional parser or to restrict the tool's plain ASCII text output to a format that can be more easily filtered by utilities that use regular expressions. Future work with XSL promises to extend and further simplify transformations of VMView traces. |
| We were able to use existing Web browsers to view the tool's output. As a result, we gained the basic navigation and printing without having to re-implement this functionality for our needs. This reduced our development time and tool installation footprint. |
Conclusions |
| The use of an XML-based output format for software diagnostic tools solves several problems. It gives the output a convenient format suitable for filtering - allowing the user to more effectively manage the data complexity. For VMView, trace filtering is an important feature because of the size of unfiltered traces. |
| XML also allows for the separation of the data from its presentation - something that is more difficult to accomplish with the standard text formatting techniques used by most tools. This in turn also allows for the use of standard Web browsers to view the tool output, reducing development time and effort. VMView's XML-based trace was easily converted to HTML for browsing by browsers such as Microsoft's Internet Explorer. This allows us to spend more time on VMView's core functionality rather than on its user interface. |
Use of trade name products and trademarks |
| The presence or absence of a particular trade name product does not imply criticism or endorsement by the National Institute of Standards and Technology, nor does it imply that the products identified are necessarily the best available. |
| Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. |
References |
|
| Content Aware Intelligent Web Graphics | Table of contents | Indexes | XLink and Publishing Opportunities | |||