使用Java工具运行Eclipse RCP应用程序 [英] Run Eclipse RCP application with Java instrumentation

查看:499
本文介绍了使用Java工具运行Eclipse RCP应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Java测试,我们可以访问Java类加载器从JVM加载的类,并通过插入我们的自定义代码来修改其字节码,所有这些都在运行时完成。我们不必担心安全性,它们受适用于Java类和相应类加载器的相同安全上下文的限制。

Using Java instrumentation, we can access a class that is loaded by the Java classloader from the JVM and modify its bytecode by inserting our custom code, all these done at runtime. We need not worry about security, these are governed by the same security context applicable for Java classes and respective classloaders.

我们可以使用这些方法来访问一些java应用程序运行在相同的类加载器。

We are able to access some java application using this as they run in same classloader.

现在我们要做的是使用java检测访问eclipse RCP应用程序,但在RCP中每个bundle都有自己的类加载器,我们的检测代码运行与java应用程序类加载器。
当我们正在访问它,它抛出Workbench尚未创建异常,而工作台已启动并运行(我希望这是因为两个不同的类加载器)。

Now what we are trying to do is to access eclipse RCP application using java instrumentation but in RCP each bundle has its own classloader and our instrumentation code runs with java application classloader. when we are accessing it, it is throwing "Workbench has not been created yet" exception whereas the workbench is up and running.(I hope this is because of diffrent classloaders for both of them).

我试过从这里,但是没有成功。
有什么办法可以使用java工具来处理RCP应用程序。

I have tried doing thing from here but to no success. Is there any way we can work RCP application out with java instrumentation.

推荐答案

当你上课时,插入的代码的引用由修改的类的 ClassLoader 解析。如果该类加载器未委托给应用程序加载器,例如因为它是基于规则的,并且不知道您的工具具体课程,您无法强制执行委派。

When you instrument a class, the references of the inserted code are resolved by the ClassLoader of the modified class. If that class loader does not delegate to the application loader, e.g. because it is rule based and doesn’t know your instrumentation specific classes you can’t enforce delegation.

您可以做什么:


  • 使用访问覆盖定义类在检测类的加载器的范围内。因为 defineClass final bundle类加载器不能拦截它。然而,这些注入类的引用再次由bundle加载器解析,所以你必须以这种方式添加所有需要的工具类。

  • 由于bundle类加载器将为官方Java API类别的父加载程序委托执行,您可以调用其中一个核心Java类来添加一个帮助程序方法,该方法将由被调用的类和代表调用到您的检测类,已经添加到boostrap加载程序

  • 您可以使用回答你已经链接,放一个 MethodHandle 进入系统道具ERTIES。仪器化类可以检索和调用它,因为 MethodHandle 是一个核心类,它将被bundle加载器正确解析,底层方法可以被调用而无需访问它的定义类(假设参数和返回类型都是原始类型或核心类)。

  • Use access override to define classes in the scope of the loader of the instrumented class. Since defineClass is final the bundle class loader can’t intercept it. However, the references of these injected classes are again resolved by the bundle loader so you have to add all required instrumentation classes this way.
  • Since the bundle class loader will do the parent loader delegation for the official Java API classes, you can instrument one of the core Java classes to add a helper method which will be called by the instrumented classes and delegates to your instrumentation classes which must have been added to the boostrap loader
  • You can use the trick described in the answer you have already linked to put a MethodHandle into the system properties. The instrumented classes can retrieve and invoke it as MethodHandle is a core class which will be correctly resolved by the bundle loader and the underlying method can be invoked without having access to its defining class (assuming that parameter and return types are all either primitive types or core classes).

这篇关于使用Java工具运行Eclipse RCP应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆