¿Usar classmexer en la aplicación Eclipse RCP?

I tried to use classmexer in an Eclipse RCP application but I got only an IllegalStateException:

java.lang.IllegalStateException: Agent not initted
at com.javamex.classmexer.Agent.getInstrumentation(Agent.java:33)
at com.javamex.classmexer.MemoryUtil.deepMemoryUsageOf(MemoryUtil.java:104)
at com.javamex.classmexer.MemoryUtil.deepMemoryUsageOf(MemoryUtil.java:80)
at classmexertester.ViewPart.createPartControl(ViewPart.java:22)
at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:375)
at org.eclipse.ui.internal.ViewReference.createPart(ViewReference.java:229)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:313)
at org.eclipse.ui.internal.ViewPane.setVisible(ViewPane.java:534)
at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:180)
at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:270)
at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:473)
at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1245)
at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1198)
at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1597)
at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:643)
at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:570)
at org.eclipse.ui.internal.PartSashContainer.createControl(PartSashContainer.java:568)
at org.eclipse.ui.internal.PerspectiveHelper.activate(PerspectiveHelper.java:272)
at org.eclipse.ui.internal.Perspective.onActivate(Perspective.java:981)
at org.eclipse.ui.internal.WorkbenchPage.onActivate(WorkbenchPage.java:2714)
at org.eclipse.ui.internal.WorkbenchWindow$28.run(WorkbenchWindow.java:3030)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchWindow.setActivePage(WorkbenchWindow.java:3011)
at org.eclipse.ui.internal.WorkbenchWindow.busyOpenPage(WorkbenchWindow.java:799)
at org.eclipse.ui.internal.Workbench$23.runWithException(Workbench.java:1229)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:803)
at org.eclipse.ui.internal.Workbench$33.runWithException(Workbench.java:1600)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:180)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4683)
at org.eclipse.ui.internal.StartupThreading.runWithoutExceptions(StartupThreading.java:94)
at org.eclipse.ui.internal.Workbench.init(Workbench.java:1595)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2628)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at classmexertester.Application.start(Application.java:20)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)

in the runtime configuration I put:

-javaagent:C:/Users/kd/workspace/ClassmexerTester/classmexer.jar

can it be that I have to add something in the plugin.xml?

preguntado el 03 de mayo de 12 a las 14:05

3 Respuestas

in the runtime configuration I put:

-javaagent:C:/Users/kd/workspace/ClassmexerTester/classmexer.jar

That doesn't sound right. You need to pass -javaagent:C:/Users/kd/workspace/ClassmexerTester/classmexer.jar as a JVM argument. You specify these in the JM Arguments pane on your Product configuration's Launching tab.

You will also need the classmexer.jar in the list of included jars on the classpath pane of your plugin.xml's Runtime tab.

Respondido el 20 de junio de 20 a las 10:06

puse -javaagent:C:/Users/kd/workspace/ClassmexerTester/classmexer.jar as JVM Argument and add the .jar in the classpath pane of the plugin.xml. But I get still the same Exception. Here is also the MANIFEST.MF:Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: ClassmexerTester Bundle-SymbolicName: ClassmexerTester; singleton:=true Bundle-Version: 1.0.0.qualifier Bundle-Activator: classmexertester.Activator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ClassPath: classmexer.jar, . - kj249

I looked at this a bit more, and ended up in the same situation. I don't think there is a simple solution, as the problem stems from the OSGi framwework's use of separate classloaders for loading bundles. See ¿Cómo puedo usar java.lang.instrument en una aplicación Eclipse RCP?

The issue is the instance of the classmexer agent that is initialised by the -javaagent VM arg is not the same instance as the one we get in our plugin due to the different classloaders in play. The only way I can see of solving this issue is by modifiying the Agent class, either to use the System.properties based mechanism of object sharing given in the example above, or by implementing the Inicio de agentes después del inicio de la máquina virtual mechanism and attaching the agent programatically in your plugin. Both approaches require changing the classmexer Agent class, so aren't immediately viable as the source doesn't seem to be public.

You can however make use of the excelent Application Profiling tools available in the Plataforma de herramientas de prueba y rendimiento Eclipse

contestado el 23 de mayo de 17 a las 11:05

I spent a good amount of time reproducing your problem, researching the underlying cause and suggesting alternatives. You don't even show the courtesy of upvoting my answer, no matter accepting it. >:\ - Malcolm smith

The following step did the job for me. In Eclipse Java IDE, Go to Run Configuration->Arguments tab and enter "-javaagent:classmexer.jar" under VM arguments and Apply the changes. Make sure classmexer.jar is included in the Eclipse Build path as well.

Respondido 14 Oct 16, 08:10

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.