Skip Headers
Oracle® Java Micro Edition Software Development Kit Developer's Guide
Release 8.1 for Windows
E50624-02
  Go To Table Of Contents
Contents

Previous
Previous
 
Next
Next
 

6 Debugging Java ME Embedded Applications

Stable operation of an application depends on the ability to avoid as many errors during development as possible. You have to be able to detect errors and deal with them before your application is released.

Debugging in general refers to a complex set of methods for extensive diagnostics and troubleshooting of applications both at the source code level and during runtime. Besides interactive debugging, this may include analyzing log files, monitoring the application at runtime, and collecting profiling information.

The Java Platform, Standard Edition Development Kit (JDK) provides various diagnostic and monitoring tools, such as the jdb Java Debugger. There are also tools that are specific to various operating systems (OS), such as the userdump utility on Windows and dbx on Solaris.

For more information about debugging Java applications, see the Java Platform, Standard Edition Troubleshooting Guide at

http://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot

Oracle Java ME SDK maintains several logs and includes dedicated monitoring and profiling tools specifically for Java ME Embedded applications. You can also use general Java debugging and profiling features, as well as those provided by the IDE and the OS.

Interactive Debugging

Interactive debugging is accomplished by setting breakpoints and watchpoints in the source code and running the application with a debugger. This enables you to execute your code one line at a time and examine the state of your application to discover problems.

By default, both NetBeans IDE and Eclipse IDE use the Java Debugger based on the Java Platform Debugger Architecture (JPDA). Before debugging a project, connect the device on which you want to perform debugging and select it as the default for this project.

To debug a project in NetBeans IDE, right-click the project name and select Debug.

To debug a project in Eclipse IDE, select the project name in the Package Explorer view, open the Run menu, and select Debug.

Profiling Java ME Embedded Applications

Profiling refers to collecting information about the runtime behavior of an application. Oracle Java ME SDK provides a dedicated CPU profiler that keeps track of every method in your Java ME Embedded application.

As data is collected during the emulation session, the profiler figures out how much time was spent in each method. After you close the emulator, you can export the data to an NPS file (from NetBeans IDE) or to a PRF file (from Eclipse IDE) that you can load and view later. As you view the snapshot, you can investigate particular methods, classes, and packages, and save a customized snapshot (as a PNG file) for future reference.


Note:

The profiling values obtained from the emulator do not reflect the actual values on an external device, because the emulator does not represent the actual device, it is one possible implementation of its supported APIs.

Before profiling a project, connect the device on which you want to perform profiling and select it as the default for this project.


Note:

The profiler collects large amounts of data, so profiled IMlets require a larger heap to run on the device. To increase the heap size, configure the Heapsize property for the device. For more information about device properties, see Viewing and Editing Device Properties.

To profile a Java ME Embedded Application project in NetBeans IDE:

  1. In the Projects view, right-click the project and select Profile.

    If this is the first time profiling this project, you are prompted to integrate the profiler. Click Yes to perform the integration.

  2. Select CPU Profiler and click Run.

    When the application stops, profiling data is displayed in a tab labeled cpu with the time when the data was displayed.

To profile a Java ME project in Eclipse IDE:

  1. In the Package Explorer view, select the project.

  2. Open the Run menu and select Profile.

  3. Select CPU Profiler and click OK.

    When the application stops, profiling data is displayed in a tab labeled CPU with the time and date when the data was collected.

In NetBeans IDE, to export the profile data to an NPS file, click the Export to button in the CPU Profiler tab and specify the file name and location. This data can be loaded at a later time.

In Eclipse IDE, to export the profile data to a PRF file, open the File menu and select Save As, then specify the file name and location. This data can be loaded at a later time.

Monitoring Memory Usage of Java ME Embedded Applications

The Java ME SDK plug-ins include a Memory Monitor that shows memory usage of a running Java ME Embedded application from within the IDE. It displays a dynamic detailed listing of the current memory usage per object in table form, and a graphical representation of the memory usage over time.

You can take a snapshot of the Memory Monitor data (as an MMS file, short for memory monitor snapshot). Snapshots can be loaded and analyzed later.


Note:

The memory usage values obtained from the emulator do not reflect the actual values on an external device, because the emulator does not represent the actual device, it is one possible implementation of its supported APIs.

To monitor memory usage of a Java ME Embedded Application project in NetBeans IDE:

  1. In the Projects view, right-click the project and select Profile.

    If this is the first time profiling this project, you are prompted to integrate the profiler. Click Yes to perform the integration.

  2. Select Memory Monitor and click Run.

    The Memory Monitor tab opens in the main working area of NetBeans IDE.

To monitor memory usage of a Java ME project in Eclipse IDE:

  1. In the Package Explorer view, select the project name.

  2. Open the Run menu and select Memory Monitor.

    The Memory Monitor view opens in the main working area of Eclipse IDE.

The top part of the Memory Monitor tab contains a graph, while the bottom part of the tab contains an object table. To the left of the graph is the current memory usage in bytes. The green line plots this values over time. The red line is the maximum amount of memory used since program execution, corresponding to the maximum size in bytes on the left.

Beneath the object table you see counters that display the total number of objects, the amount of memory used, the amount of free memory, and the total amount of heap memory on the device.

To sort the data in the object table, click a column header. Sorting is case sensitive.

To display the call stack tree, click a row in the object table. The call stack is displayed in a window to the right of the table. You can browse the call stack tree to see the methods that created the object by selecting the corresponding folder in the call stack.

Because data changes rapidly, it is convenient to take several snapshots of the memory monitor data and review them later. To save a snapshot, open the File menu and select Save As, then specify an MMS file name and location.

The graph data you see is cumulative for this emulator session. The Memory Monitor plots session data for any IMlet run on the current emulator until you exit the application and close the emulator.

To load a memory monitor snapshot.

  1. On the File menu, select Open File.

  2. Browse to find the necessary MMS file.

    The Memory Monitor opens in its own tab in the main window. Note that the tab displays the time when the snapshot was saved.

Monitoring Network Activity of Java ME Embedded Applications

The Java ME SDK plug-ins include a Network Monitor that provides a convenient way to see the data that your Java ME Embedded application is sending and receiving on the network. This is helpful if you are debugging network interactions or looking for ways to optimize network traffic through HTTP and other protocols.

You can take a snapshot of the Network Monitor data (as an NMD file, short for network monitor data). Snapshots can be loaded and analyzed later.

To monitor network activity of a Java ME Embedded Application project in NetBeans IDE:

  1. In the Projects view, right-click the project and select Profile.

    If this is the first time profiling this project, you are prompted to integrate the profiler. Click Yes to perform the integration.

  2. Select Network Monitor and click Run.

    The Network Monitor tab opens in the main working area of NetBeans IDE.

To monitor network activity of a Java ME project in Eclipse IDE:

  1. In the Package Explorer view, select the project name.

  2. Open the Run menu and select Network Monitor.

    The Network Monitor view opens in the main working area of Eclipse IDE.

When the application makes a network connection, information about the connection is captured and displayed in the table in the top frame. Click a connection to display its details in the bottom frame. Under Hex View, raw connection data is shown as raw hexadecimal values with the equivalent text.


Note:

To avoid memory issues, the Hex view display is currently limited to 16 kilobytes of data.

To save your network monitor session, open the File menu and select Save As, then specify an NMD file name and location.

To load a network monitor session:

  1. On the File menu, select Open File.

  2. Browse to find the necessary NMD file.

Filtering and Sorting Connections

Filters are used to examine a subset of the total network traffic.

  • In the Select Devices list, select only the devices you want to view.

  • In the Select Protocols list, select only the protocols you want to view. The list contains protocols that are available on the device.

  • In the URL Filter field, you can specify the URL for which you want to view connection data.

Click on a table header to sort the message data:

  • No.: Connections are sorted sequentially (according to the time when they were started).

  • Protocol: Connections are sorted by protocol name.

  • Device: Connections are sorted by device name.

  • URL: Connections are sorted by URL.

  • Time: Connections are sorted by duration.

  • Size: Connections are sorted by the size of data.

  • Active: Connections are sorted based on whether it is currently active.

Logging Capabilities Provided by Oracle Java ME SDK

Oracle Java ME SDK relies on a set of tools that help you with development, such as the Device Manager, Device Selector, Custom Device Editor, and so on. Each tool maintains a separate log file to record errors, warnings, and informational events. When you experience problems with any of the tools, you can review its log file to understand which events caused a particular issue.

These log files are located in the Oracle Java ME SDK user configuration directory under log. For example, the Device Manager saves logging data to JAVAME_SDK_USER\log\device-manager.log.

The Java ME Embedded Emulator maintains a separate log file for each device. The device log is named device.log and is located in the device's configuration directory. For example, the logging data for the default EmbeddedDevice1 is saved to JAVAME_SDK_USER\work\EmbeddedDevice1\device.log.

For more information about the Oracle Java ME SDK user configuration directory, see Chapter 3.

By default, device logs record high-level program usage events. Debugging may require lower-level information about the operation of the underlying runtime. Recording this tracing data in a device's log file can be enabled using the device properties.

To enable tracing for a device:

  1. Open the Device Selector and select the device. For more information about the Device Selector and device properties, see Chapter 7.

  2. Expand the Monitor node of the device properties and select the desired trace properties:

    • Trace GC: Tracing garbage collection information can help you determine object health. The garbage collector cannot delete objects that do not have a null reference. Null objects are garbage collected and not reported as active.

    • Trace Class Loading: Tracing class initialization and loading is useful for determining dependencies among classes.

    • Trace Exceptions: Tracing caught exceptions can be used for debugging when analyzing the log file.

    • Trace Method Calls: Tracing called and returned methods is useful to understand the operational sequence of the application. The output for this option is very verbose, and it can affect performance.

  3. (Optional) Verbose tracing output may cause your application to run out of memory on the device. To increase the device's heap memory size, expand the General node of the device properties and specify the value for the Heapsize property.