Skip to content
This repository was archived by the owner on Mar 14, 2019. It is now read-only.
This repository was archived by the owner on Mar 14, 2019. It is now read-only.

Avoid external class dependency for injected classloader #17

Closed

Description

@zhongl

Use java implement AdviceProxy, Context, Advice, NullAdvice

@see also #12 #14

Activity

  1. ghost assigned on Jun 1, 2012
  2. zhongl commented on Jun 1, 2012

    @zhongl
    MemberAuthor

    实际应用中, 运行着的Java生产系统中会存在不遵守“双亲委派”原则的自定义ClassLoader, 它们会造成retransform的class中引入的新class找不到。

    为避免这个问题, 可以将要引入的class(如,AdviceProxy)的字节码, 人为的在目标ClassLoader进行定义,并使用反射注入Advice的实例, 即下面伪代码片段:

    byte[] bytes = bytesOf(AviceProxy.class);
    Class<?> apClass = someCustomizedClassLoader.defineClass(bytes, 0, bytes.length);
    
    ...
    Object advice = getAdviceInstance();
    apClass.getMethod("setAdvice", Object.class).invoke(advice);

    为保证这个思路简单可行, 有个原则是:

    引入的自定义class一定要少, 最好只有一个AdviceProxy, 且它仅仅依赖JDK.

    @see https://gist.github.com/2849396

  3. added a commit that references this issue on Jun 7, 2012
  4. added 2 commits that reference this issue on Jun 18, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions