Getting Rid of Unwanted Preference Pages in Eclipse

I recently wanted to get rid of a preference page I did not want to expose in Mission Control (an Eclipse RCP based application), and ended up with the following code in my ApplicationWorkbenchWindowAdvisor:

private void removeUnwantedPreferencesPages() {
    PreferenceManager pm = PlatformUI.getWorkbench().getPreferenceManager();
    IPreferenceNode root = getRoot(pm);
    removePrefsPage(root, "org.eclipse.equinox.security.ui.category"); //$NON-NLS-1$
}


private IPreferenceNode getRoot(PreferenceManager pm) {
    try {
        Method m = PreferenceManager.class.getDeclaredMethod("getRoot", (Class[]) null); //$NON-NLS-1$
        m.setAccessible(true);
        return (IPreferenceNode) m.invoke(pm);
    } catch (Exception e) {
       LoggingToolkit.getLogger().log(Level.WARNING, "Could not get the root node for the preferences, and will not be able to prune unwanted prefs pages.", e); //$NON-NLS-1$
    }
    return null;
}

private void removePrefsPage(IPreferenceNode root, String id) {
    for (IPreferenceNode node : root.getSubNodes()) {
        logPrefsNode(node);
        if (node.getId().equals(id)) {
           root.remove(node);
           LoggingToolkit.getLogger().log(Level.INFO, String.format("Removed preference page %s (ID:%s)", node.getLabelText(), node.getId()));   //$NON-NLS-1$
        } else {
           removePrefsPage(node, id);
        }
    }
}

If you need to know the ID of the preference page you wish to remove, simply walk the tree and print all the nodes instead of removing selected ones.

Hope this helps someone. Blinkar

Could not enumerate processes (1) error?

With JRockit, you may sometimes see the following warning when starting the JVM (on Windows):

[WARN ][osal ] Could not enumerate processes (1) error=-1073738819
[WARN ][osal ] Could not add counter (null)\ for query
[WARN ][osal ] Failed to init virtual size counter

It may also look something like this:

[JRockit] WARNING: Could not initialize the virtualbytes counter, some functionality in jrockit.management.Memory will not be available. Message was: failed to create counter query. String was: (null)\Virtual Bytes

Or like this:

[JRockit] WARNING: Could not initialize the JVM process load counter, CPU load generated by the JVM will not be available. Message was: failed to create counter query. String was: (null)\% Processor Time

This means the JRockit cannot access the relevant PDH counters. Sometimes the counter is disabled, and then it can simply be re-enabled.  Worst case, the counters can be corrupt, and the metadata needs to be rebuilt from system backup store.

To check the status of the counters, open a command prompt as admin, and run lodctr /q, as follows:

C:\Windows\system32>lodctr /q
Performance Counter ID Queries [PERFLIB]:
Base Index: 0x00000737 (1847)
Last Counter Text ID: 0x00001572 (5490)
Last Help Text ID: 0x00001573 (5491)
[.NET CLR Data] Performance Counters (Enabled)
DLL Name: netfxperf.dll
Open Procedure: OpenPerformanceData
Collect Procedure: CollectPerformanceData
Close Procedure: ClosePerformanceData
First Counter ID: 0x00001092 (4242)
Last Counter ID: 0x0000109E (4254)
First Help ID: 0x00001093 (4243)
Last Help ID: 0x0000109F (4255)
[.NET CLR Networking] Performance Counters (Enabled)
DLL Name: netfxperf.dll
Open Procedure: OpenPerformanceData
Collect Procedure: CollectPerformanceData
Close Procedure: ClosePerformanceData
First Counter ID: 0x00001086 (4230)
Last Counter ID: 0x00001090 (4240)
First Help ID: 0x00001087 (4231)
Last Help ID: 0x00001091 (4241)
[.NET Data Provider for Oracle] Performance Counters (Enabled)
DLL Name: netfxperf.dll
Open Procedure: OpenPerformanceData
Collect Procedure: CollectPerformanceData
Close Procedure: ClosePerformanceData
First Counter ID: 0x00001068 (4200)
Last Counter ID: 0x00001084 (4228)
First Help ID: 0x00001069 (4201)
Last Help ID: 0x00001085 (4229)

If it says (Disabled) next to a provider, the provider can be enabled with:

C:\Windows\system32>lodctr /e:<provider name> (where <provider name> is the string between the brackets at the beginning of the entry).

If the performance counters still behave badly, rebuild them from system backup store by running:

C:\Windows\system32>lodctr /r

Some counters may still be disabled after this. Use lodctr /q and lodctrl /e as described above to enable the ones you need.

If lodctrl is not available on your version of Windows, this article may help.

Java One Latin America Schedule Update

Since there was a bit of overlap in the previous schedule, my session has been moved to 14:15. The Hands-On-Lab remains at 11:15. These are the new times for my sessions:

Wednesday, December 7
Time Room Title Abstract Type
11:15 – 13:15
Mezannine: Room 1 Production-Time Problem Solving This tutorial looks at some common problems and pitfalls in Java applications. It focuses on noninvasive profiling and diagnostics of running production systems. Problems tackled:

  • Excessive GC
  • Finding hotspots and optimizing them
  • Optimizing the choice of data structures
  • Synchronization problems
  • Finding out where exceptions are thrown
  • Finding memory leaks
  • The presentation demonstrates all problems and solves them, running both the bad-behaving applications and the tools to analyze them from within the Eclipse Java IDE with the upcoming Oracle JRockit Mission Control Release 4.1.

    Hands-on Lab
    Java Core Platform
    14:15 – 15:15 Exposition Hall: Auditorium 6 HotRockit: What to Expect from Oracle’s Converged JVM Oracle is converging the HotSpot and Oracle JRockit JVMs to produce a “best-of-breed JVM.” Internally, the project is sometimes referred to as the HotRockit project. This presentation discusses what to expect from the converged JVM over the next two years and how this will benefit the Java community.
    Conference Session
    Core Java Platform

    Looking forward to seeing you there! Ler

    image

    JavaOne 2011–Sao Paulo

    I will be presenting the following two sessions at Java One in Brazil in December:

    Wednesday, December 7
    Time Room Title Abstract Type
    11:15 – 13:15
    Mezannine: Room 1 Production-Time Problem Solving

    This tutorial looks at some common problems and pitfalls in Java applications. It focuses on noninvasive profiling and diagnostics of running production systems. Problems tackled:

  • Excessive GC
  • Finding hotspots and optimizing them
  • Optimizing the choice of data structures
  • Synchronization problems
  • Finding out where exceptions are thrown
  • Finding memory leaks
  • The presentation demonstrates all problems and solves them, running both the bad-behaving applications and the tools to analyze them from within the Eclipse Java IDE with the upcoming Oracle JRockit Mission Control Release 4.1.

    Hands-on Lab
    Java Core Platform
    12:30 – 13:30 Exposition Hall: Auditorium 6 HotRockit: What to Expect from Oracle’s Converged JVM Oracle is converging the HotSpot and Oracle JRockit JVMs to produce a "best-of-breed JVM." Internally, the project is sometimes referred to as the HotRockit project. This presentation discusses what to expect from the converged JVM over the next two years and how this will benefit the Java community.
    Conference Session
    Core Java Platform

    Looking forward to seeing you there! Ler

    image

    WordFeud Word Generator

    My friend complained that his app for generating Swedish words did not work with Swedish characters. I complained that he should not be using such an app to begin with, but was challenged into whipping together this:

    http://hirt.se:8080/WordFinderWeb/

    I don’t recommend using this, as it really is cheating. If you are using this, let the friend you are playing with know! It really changes the character of the game to a pure strategy game.

    Time Problem When Dual-Booting Your Mac?

    I’ve been the proud owner of a Mac Book Air for a little while now. Because of work, I am dual booting it into Windows. A major annoyance, however, has been that everytime I switch to Windows, the Windows system clock has jumped two hours back in time (difference between CEST and UTC).

    There reason is that Mac OS X is expecting the real time clock (RTC) to be in UTC, and Windows expects it to be in local time. Luckily, there is a simple fix to this (if you are using Vista SP 2 or Windows 7). Simply set the registry key DWORD value to 1: HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\RealTimeIsUniversal

    This will make Windows use UTC for the real time clock as well!

    For more information:
    http://www.insanelymac.com/forum/index.php?showtopic=226287
    http://linux.wxs.ro/2011/05/16/windows-rtc-utc/

    JavaOne / Oracle Open World 2011 Update

    There has been a slight update to the schedule. The HOL on Wednesday has been moved to 10:15. The finalized schedule is thus:

    This year my sessions are:

    Day Time TItle Location Type Length Session ID
    Monday 11:00 Production-Time Problem Solving

    Hilton San Francisco – Franciscan Room A/B/C/D

    HOL 2h

    22220

    Monday

    14:30

    HotRockit: What to Expect from Oracle’s Converged JVM

    Hilton San Francisco – Yosemite A/B/C

    Session

    1h

    22260

    Tuesday 13:30

    What’s New in Oracle JRockit Mission Control?

    Parc 55 – Market Street

    Session 1h

    22261

    Wednesday 10:15

    Production-Time Problem Solving

    Marriott Marquis – Salon 3/4

    HOL 1h

    31140

    Other sessions by the JRockit gang include:

    Day Time TItle Location Type Length Session ID
    Tuesday 20:30

    Meet the JDK Project Leads

    Hilton San Francisco – Plaza A/B

    BoF 45min 25148
    Wednesday 10:00 Showdown at the JVM Corral: Java 7 Edition

    Hilton San Francisco – Plaza A/B

    Panel 1h 23832

    Looking forward to seeing you in San Francisco! Smile    

     J12011OOW2011

    register_now_banner

    Adding Lock Instance Visualization

    As promised in the blog entry before this one, I’m going to show how to easily add a new tab for visualizing lock instances. This can be done more elegantly in 4.1, so I will post an update to this once 4.1 is out the door.

    This is roughly what we need to do:

    1. Start JRMC in design mode.
    2. Add a new tab.
    3. Edit the new tab to add a histogram of all the locking events grouped by lock instance, and a trace tree slaved to that histogram, showing the traces for all the events of a selected lock instance.
    4. Optionally export the tab to a plug-in that can be shared with colleagues.

    Starting with #1, we need to start JRMC in design mode. This can be done by providing the parameter –designer to the jrmc launcher.

    On windows you can simply provide a shortcut to JRMC and add –designer to the target:

    shortcut

    The designer parameter will make available an additional view in JRMC which controls switching between design and run mode in Mission Control.

    Next start up Mission Control, and open up a recording you know contains some Java Blocking events. Next open up the designer view, by clicking Window | Show View | Designer View, as shown below. This view will only be available if you started Mission Control with –designer.

    designer_view

    I like to have the Designer View to the left, but feel free to drag-and-drop it to dock the view wherever you find is most convenient.

    designer_view2

    Now, to change the structure of the tabs, such as adding a new tab, you actually need to close the recording. This will show the structure of the tabs in the Designer View. Click on the CPU/Threads tab group, and select New | New Tab.

    add_tab

    Fill out the information about the new tab:

    new_tab2

    Feel free to add a nice icon. 😉 Once the information is filled out, press OK and load the recording again. You should now have an empty Lock Instances tab available.

    new_tab3

    Press the stop button in the Designer View to enter design mode. First thing we need to do is to choose how to layout the component. Right click the surface and select Vertical Split:

    vertical_split

    Add a histogram to the top half, by right clicking the top half and selecting Assign Component | Histogram | Event Histogram. In the dialog that appears, do the following changes:

    • Change the Name to “Lock Instances”
    • Change General | Role to Master
    • Change General | Pie chart position to East
    • In Columns, click the Browse button, then Browse again. Select the Java Blocked event type.
    • Next click Add to add the columns to show.
      • Add the Monitor Address attribute.
      • Add the Duration field, and change the name to Count, the description to “The event count”. Change the Aggregate Function to Count. Also change the Content Type to Count. Click Pie Chart, and Sorted.
    • In Group By, click Browse and select the Monitor Address attribute.

    Click the play button to see your new histogram in action:

    histogram_action

    To add the trace tree, press stop to enter design view. Right click the bottom space and select Assign Component | Tree | Trace Tree. In the dialog that opens, modify:

    • Change General | Role to Slave
    • Set Expanded Tree Depth to 0
    • In Columns click Browse and then Browse again in the next dialog. Select the Java Blocked event type.
    • Click add to add the Duration attribute. Select Count as Aggregate Function and Count as Content Type. Click the sorted checkbox.
    • In  Group By, click Browse and select the Stacktrace attribute.

    Press play to show the ready made tab ( don’t forget to select a Lock instance in the master histogram):

    done

    Last but not least, export the tab to a plug-in that you can share. First close the recording to see the tab structure again. Next right click on the Flight Recording root node. Select Export UI to Plug-in. In the dialog that follows, select only the Lock Instances tab. Press OK. You will now be presented with a dialog where the plug-in name and version can be changed. Once you are happy with the settings, click OK. Next select a place to save the plug-in. Once you’ve chosen a memorable spot, press OK.

    Done!

    The resulting .jar file can be used by anyone simply by placing it in the missioncontrol/plugins folder.

    Tip: To add a Range Selector at the top, look at how the other tabs are configured in design mode.

    Visualize Those Locks!

    There you are, submitting your poor application to the worst load imaginable. However, after looking at the profiling data in Mission Control, the evil grin on your face is quickly replaced by a look of surprise. The [CPU] load on the machine is only a fraction of what should be available to your application. You’ve got a throughput problem.

    low_load

    Picture of heavily loaded multi-threaded app running on a multi-core machine

    Mission Control contains a lot of information about why your application isn’t spending time executing Java code. Events are produced for almost everything that can make your threads halt. For example, in the Contention tab there is aggregated information, per class, about what classes of locks are blocking your threads (on monitor enter) the most.

    Contention

    Sometimes, however, you really want to look at the information on a per lock instance basis. Take the following example:

    example

    You may, for example, want to know if all the sun.misc.Launcher$AppClassLoader locks are one and the same [instance], or if there are several in play. The easiest way to check this is to set the operative set to the events for that lock class, and then view those events in a histogram grouped by the monitor address (don’t let the name confuse you – it’s actually the lock address).

    First add to the operative set:

    set_selection

    Then build the histogram (don’t forget to check Show Only Operative Set):

    histogram

    Indeed, in this case they are blocking on the same instance. Admittedly a silly example, but you get the idea. Note that one drawback is that the monitor address information is only guaranteed to be coherent in between garbage collections, as the lock object may have been moved due to propagation and/or compaction during a garbage collection. If it is very important to not have a certain lock instance being reported more than once, make sure you study a range between two garbage collections.

    Now, if you find yourself looking at this kind of information a lot, you may want to redesign the GUI to contain this information in a separate tab. This is easier to accomplish than you may think; I’ll post another blog with step-by-step instructions on how to accomplish that in a bit.