當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。