当前位置: 首页>>代码示例>>Java>>正文


Java Instrumentation.appendToBootstrapClassLoaderSearch方法代码示例

本文整理汇总了Java中java.lang.instrument.Instrumentation.appendToBootstrapClassLoaderSearch方法的典型用法代码示例。如果您正苦于以下问题:Java Instrumentation.appendToBootstrapClassLoaderSearch方法的具体用法?Java Instrumentation.appendToBootstrapClassLoaderSearch怎么用?Java Instrumentation.appendToBootstrapClassLoaderSearch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.instrument.Instrumentation的用法示例。


在下文中一共展示了Instrumentation.appendToBootstrapClassLoaderSearch方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
public static void main(String args[]) throws IOException {
    JarFile bootclasses = new JarFile("BootSupport.jar");
    JarFile agentclasses = new JarFile("AgentSupport.jar");

    Instrumentation ins = Agent.getInstrumentation();

    // Test 1: Add BootSupport.jar to boot class path and check that
    // BootSupport is loaded by the bootstrap class loader
    ins.appendToBootstrapClassLoaderSearch(bootclasses);
    checkLoadedByLoader("BootSupport", null);

    // Test 2: Add AgentSupport.jar to the system class path and check that
    // AgentSupport is loaded by the system class loader.
    try {
        ins.appendToSystemClassLoaderSearch(agentclasses);
        checkLoadedByLoader("AgentSupport", ClassLoader.getSystemClassLoader());
    } catch (UnsupportedOperationException x) {
        System.out.println("System class loader does not support adding to class path");
    }

    // throw exception if a test failed
    if (failures > 0) {
        throw new RuntimeException(failures + " test(s) failed.");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:BasicTest.java

示例2: main0

import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
private static void main0(String agentArgs, Instrumentation instrumentation,
    BiConsumer<String, Instrumentation> delegate) {
  if (ClassLoader.getSystemResource(BTM_SCRIPTS_RESOURCE_PATH) == null) {
    System.err.println("Could not load " + BTM_SCRIPTS_RESOURCE_PATH + "."
        + "Agent will not be started.");
    return;
  }

  try {
    ConfigService.initialize();
  } catch (ConfigurationException | IOException | RuntimeException e) {
    System.err.println(e.getMessage());
    System.err.println("Agent will not be started.");
    return;
  }

  if (agentArgs != null && agentArgs.trim().length() > 0) {
    agentArgs += "," + AGENT_PARAMS;
  } else {
    agentArgs = AGENT_PARAMS;
  }

  JarFile bytemanJar = createBytemanJar();
  if (bytemanJar == null) {
    System.err.println("Could not locate: " + BYTEMAN_JAR_RESOURCE_NAME);
    System.err.println("Agent will not be started.");
    return;
  }

  instrumentation.appendToBootstrapClassLoaderSearch(bytemanJar);
  delegate.accept(agentArgs, instrumentation);
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:33,代码来源:Agent.java

示例3: premain

import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
public static void premain(String agentArgs, Instrumentation inst) {

        String jarPath = "D:/creditRepository/ce-datamonitorsystem/com.creditease.uav.ttl/target/com.creditease.uav.ttl-2.1.0-agent.jar";

        inst.addTransformer(new TtlTransformer());
        try {
            inst.appendToBootstrapClassLoaderSearch(new JarFile(jarPath));
        }
        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:14,代码来源:Iagent.java

示例4: installUAVjdk

import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
private static void installUAVjdk(Instrumentation inst, String extJdkLib) {

        URL[] jdkJars = JarUtil.loadJars(extJdkLib);
        try {
            for (URL temp : jdkJars) {
                inst.appendToBootstrapClassLoaderSearch(new JarFile(temp.getFile()));
            }
        }
        catch (IOException e) {
            // ignore
            e.printStackTrace();
        }
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:14,代码来源:MOFAgent.java

示例5: main

import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
private static synchronized InetSocketAddress main(final Map<String, String> featureMap,
                                                   final Instrumentation inst) {

    final String namespace = getNamespace(featureMap);
    final String propertiesFilePath = getPropertiesFilePath(featureMap);
    final String coreFeatureString = toFeatureString(featureMap);

    try {

        // 将Spy注入到BootstrapClassLoader
        inst.appendToBootstrapClassLoaderSearch(new JarFile(new File(SANDBOX_SPY_JAR_PATH)));

        // 构造自定义的类加载器,尽量减少Sandbox对现有工程的侵蚀
        final ClassLoader agentLoader = loadOrDefineClassLoader(namespace, SANDBOX_CORE_JAR_PATH);

        // CoreConfigure类定义
        final Class<?> classOfConfigure = agentLoader.loadClass(CLASS_OF_CORE_CONFIGURE);

        // 反序列化成CoreConfigure类实例
        final Object objectOfCoreConfigure = classOfConfigure.getMethod("toConfigure", String.class, String.class)
                .invoke(null, coreFeatureString, propertiesFilePath);

        // JtServer类定义
        final Class<?> classOfJtServer = agentLoader.loadClass(CLASS_OF_JETTY_CORE_SERVER);

        // 获取JtServer单例
        final Object objectOfJtServer = classOfJtServer
                .getMethod("getInstance")
                .invoke(null);

        // gaServer.isBind()
        final boolean isBind = (Boolean) classOfJtServer.getMethod("isBind").invoke(objectOfJtServer);


        // 如果未绑定,则需要绑定一个地址
        if (!isBind) {
            try {
                classOfJtServer
                        .getMethod("bind", classOfConfigure, Instrumentation.class)
                        .invoke(objectOfJtServer, objectOfCoreConfigure, inst);
            } catch (Throwable t) {
                classOfJtServer.getMethod("destroy").invoke(objectOfJtServer);
                throw t;
            }

        }

        // 返回服务器绑定的地址
        return (InetSocketAddress) classOfJtServer
                .getMethod("getLocal")
                .invoke(objectOfJtServer);


    } catch (Throwable cause) {
        throw new RuntimeException("sandbox attach failed.", cause);
    }

}
 
开发者ID:alibaba,项目名称:jvm-sandbox,代码行数:59,代码来源:AgentLauncher.java

示例6: addJarToBootstrap

import java.lang.instrument.Instrumentation; //导入方法依赖的package包/类
/**
 * 添加jar文件到jdk的跟路径下,优先加载
 *
 * @param inst {@link Instrumentation}
 */
public static void addJarToBootstrap(Instrumentation inst) throws IOException {
    String localJarPath = getLocalJarPath();
    inst.appendToBootstrapClassLoaderSearch(new JarFile(localJarPath));
}
 
开发者ID:baidu,项目名称:openrasp,代码行数:10,代码来源:JarFileHelper.java


注:本文中的java.lang.instrument.Instrumentation.appendToBootstrapClassLoaderSearch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。