java.lang.instrument.Instrumentation.appendToBootstrapClassLoaderSearch()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(97)

本文整理了Java中java.lang.instrument.Instrumentation.appendToBootstrapClassLoaderSearch()方法的一些代码示例,展示了Instrumentation.appendToBootstrapClassLoaderSearch()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instrumentation.appendToBootstrapClassLoaderSearch()方法的具体详情如下:
包路径:java.lang.instrument.Instrumentation
类名称:Instrumentation
方法名:appendToBootstrapClassLoaderSearch

Instrumentation.appendToBootstrapClassLoaderSearch介绍

暂无

代码示例

代码示例来源:origin: stagemonitor/stagemonitor

private static void ensureDispatcherIsAppendedToBootstrapClasspath(Instrumentation instrumentation)
    throws ClassNotFoundException, IOException {
  final ClassLoader bootstrapClassloader = ClassLoader.getSystemClassLoader().getParent();
  try {
    bootstrapClassloader.loadClass(DISPATCHER_CLASS_NAME);
    // already injected
  } catch (ClassNotFoundException e) {
    final JarFile jarfile = new JarFile(createTempDispatcherJar());
    instrumentation.appendToBootstrapClassLoaderSearch(jarfile);
    bootstrapClassloader.loadClass(DISPATCHER_CLASS_NAME);
  }
}

代码示例来源:origin: btraceio/btrace

private static void appendToBootClassPath(Path libFolder) {
  Path bootLibs = libFolder.resolve("boot");
  if (Files.exists(bootLibs)) {
    for (File f : bootLibs.toFile().listFiles()) {
      if (f.getName().toLowerCase().endsWith(".jar")) {
        try {
          if (isDebug()) {
            debugPrint("Adding " + f.getAbsolutePath() + " to bootstrap classpath");
          }
          inst.appendToBootstrapClassLoaderSearch(new JarFile(f));
        } catch (IOException e) {
        }
      }
    }
  }
}

代码示例来源:origin: oldmanpushcart/greys-anatomy

inst.appendToBootstrapClassLoaderSearch(
    new JarFile(AgentLauncher.class.getProtectionDomain().getCodeSource().getLocation().getFile())
);

代码示例来源:origin: scouter-project/scouter

private static void appendToBootLoader(Instrumentation inst, String key) {
  byte[] bytes = deployJarBytes(key);
  try {
    File tempJar = FileUtil.saveAsTemp(key, ".jar", bytes);
    inst.appendToBootstrapClassLoaderSearch(new JarFile(tempJar));
  } catch (IOException e) {
    Logger.println("A138", "Error on load " + key + ".jar " + e);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: scouter-project/scouter

private static void appendToBootLoader(Instrumentation inst, String key) {
  byte[] bytes = deployJarBytes(key);
  try {
    File tempJar = FileUtil.saveAsTemp(key, ".jar", bytes);
    inst.appendToBootstrapClassLoaderSearch(new JarFile(tempJar));
  } catch (IOException e) {
    Logger.println("A138", "Error on load " + key + ".jar " + e);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: alibaba/jvm-sandbox

inst.appendToBootstrapClassLoaderSearch(new JarFile(new File(
    getSandboxSpyJarPath(getSandboxHome(featureMap))

代码示例来源:origin: btraceio/btrace

if (f.isFile() && f.getName().toLowerCase().endsWith(".jar")) {
  JarFile jf = new JarFile(f);
  inst.appendToBootstrapClassLoaderSearch(jf);
} else {
  debugPrint("ignoring boot classpath element '" + path

代码示例来源:origin: glowroot/glowroot

public static void premain(@SuppressWarnings("unused") String agentArgs,
    Instrumentation instrumentation) {
  try {
    Class<?>[] allPriorLoadedClasses;
    if (PRE_CHECK_LOADED_CLASSES) {
      allPriorLoadedClasses = instrumentation.getAllLoadedClasses();
    } else {
      allPriorLoadedClasses = new Class<?>[0];
    }
    CodeSource codeSource = AgentPremain.class.getProtectionDomain().getCodeSource();
    // suppress warnings is used instead of annotating this method with @Nullable
    // just to avoid dependencies on other classes (in this case the @Nullable annotation)
    @SuppressWarnings("argument.type.incompatible")
    File glowrootJarFile = getGlowrootJarFile(codeSource);
    Class<?> mainEntryPointClass;
    if (glowrootJarFile != null) {
      instrumentation.appendToBootstrapClassLoaderSearch(new JarFile(glowrootJarFile));
    }
    mainEntryPointClass = Class.forName("org.glowroot.agent.MainEntryPoint", true,
        AgentPremain.class.getClassLoader());
    Method premainMethod = mainEntryPointClass.getMethod("premain", Instrumentation.class,
        Class[].class, File.class);
    premainMethod.invoke(null, instrumentation, allPriorLoadedClasses, glowrootJarFile);
  } catch (Throwable t) {
    // log error but don't re-throw which would prevent monitored app from starting
    System.err.println("Glowroot failed to start: " + t.getMessage());
    t.printStackTrace();
  }
}

代码示例来源:origin: glowroot/glowroot

static void defineClassesInBootstrapClassLoader(Collection<LazyDefinedClass> lazyDefinedClasses,
    Instrumentation instrumentation, File generatedJarFile) throws IOException {
  Closer closer = Closer.create();
  try {
    FileOutputStream out = closer.register(new FileOutputStream(generatedJarFile));
    JarOutputStream jarOut = closer.register(new JarOutputStream(out));
    generate(lazyDefinedClasses, jarOut);
  } catch (Throwable t) {
    throw closer.rethrow(t);
  } finally {
    closer.close();
  }
  instrumentation.appendToBootstrapClassLoaderSearch(new JarFile(generatedJarFile));
  // appendToBootstrapClassLoaderSearch() line above does not add to the bootstrap resource
  // search path, only to the bootstrap class search path (this is different from
  // appendToSystemClassLoaderSearch() which adds to both the system resource search path and
  // the system class search path)
  //
  // adding the generated jar file to the bootstrap resource search path is probably needed
  // more generally, but it is at least needed to support jboss 4.2.0 - 4.2.3 because
  // org.jboss.mx.loading.LoadMgr3.beginLoadTask() checks that the class loader has the class
  // as a resource before loading it, so without adding the generated jar file to the
  // bootstrap resource search path, jboss ends up throwing ClassNotFoundException for the
  // glowroot generated classes that have been added to the bootstrap class loader search path
  // (see issue #101 for more info on this particular jboss issue)
  appendToBootstrapResourcePath(generatedJarFile);
}

代码示例来源:origin: glowroot/glowroot

.appendToBootstrapClassLoaderSearch(new JarFile(centralCollectorHttpsJarFile));

代码示例来源:origin: org.testifyproject.external/external-bytebuddy

@Override
  protected void inject(Instrumentation instrumentation, JarFile jarFile) {
    instrumentation.appendToBootstrapClassLoaderSearch(jarFile);
  }
},

代码示例来源:origin: com.fitbur.external/external-bytebuddy

@Override
  protected void inject(Instrumentation instrumentation, JarFile jarFile) {
    instrumentation.appendToBootstrapClassLoaderSearch(jarFile);
  }
},

代码示例来源:origin: glowroot/glowroot

if (instrumentation != null) {
  for (File pluginJar : pluginCache.pluginJars()) {
    instrumentation.appendToBootstrapClassLoaderSearch(new JarFile(pluginJar));

代码示例来源:origin: LatencyUtils/jRT

private static void commonmain(String arguments, Instrumentation instrumentation) {
  // Exclude CLI option Xbootclasspath
  try {
    instrumentation.appendToBootstrapClassLoaderSearch(new JarFile(
            Agentmain.class.getProtectionDomain().
            getCodeSource().getLocation().getPath()));
  } catch (Exception e) {
    // can throw NPE when jar file is already in Xbootclasspath (f.e. by 
    // cli argument)
    e.printStackTrace();
  }
  
}

代码示例来源:origin: bytemanproject/byteman

public void appendJarFile(PrintWriter out, JarFile jarfile, boolean isBoot) throws Exception
{
  if (isBoot) {
    inst.appendToBootstrapClassLoaderSearch(jarfile);
    bootJars.add(jarfile.getName());
    out.println("append boot jar " + jarfile.getName());
  } else {
    inst.appendToSystemClassLoaderSearch(jarfile);
    sysJars.add(jarfile.getName());
    out.println("append sys jar " + jarfile.getName());
  }
}

代码示例来源:origin: bytemanproject/byteman

public void appendJarFile(PrintWriter out, JarFile jarfile, boolean isBoot) throws Exception
{
  if (isBoot) {
    inst.appendToBootstrapClassLoaderSearch(jarfile);
    bootJars.add(jarfile.getName());
    out.println("append boot jar " + jarfile.getName());
  } else {
    inst.appendToSystemClassLoaderSearch(jarfile);
    sysJars.add(jarfile.getName());
    out.println("append sys jar " + jarfile.getName());
  }
}

代码示例来源:origin: stackoverflow.com

Instrumentation instrumentation = ByteBuddyAgent.install();
// Append the jar containing the stub replacement to the bootstrap classpath
instrumentation.appendToBootstrapClassLoaderSearch(jarFile);

AgentBuilder agentBuilder = new AgentBuilder.Default()
    .disableClassFormatChanges()
    .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
    .ignore(none()); // disable default ignores so we can transform Java classes
    .type(ElementMatchers.named("java.lang.reflect.AccessibleObject"))
    .transform(transformer)
    .installOnByteBuddyAgent();

代码示例来源:origin: io.kamon/kanela-agent

private static void appendToBootstrapClassloader(String agentLocation, Instrumentation instrumentation) {
    Logger.debug(() -> "append jar to BootstrapClassloader ==> " + agentLocation);
    Try.run(() -> instrumentation.appendToBootstrapClassLoaderSearch(new JarFile(agentLocation)));
  }
}

代码示例来源:origin: net.orfjackal.retrolambda/retrolambda

public static void premain(String agentArgs, Instrumentation inst) throws Exception {
  // Append the agent JAR to the bootstrap search path so that the instrumented InnerClassLambdaMetaFactory
  // could refer to Agent.
  inst.appendToBootstrapClassLoaderSearch(new JarFile(getAgentJarFile()));
  inst.addTransformer(new InnerClassLambdaMetafactoryTransformer(), true);
  inst.retransformClasses(Class.forName("java.lang.invoke.InnerClassLambdaMetafactory"));
}

代码示例来源:origin: io.kamon/kanela-agent

public static void injectJar(Instrumentation instrumentation, String jarName) {
  val jarFile = Jar.getEmbeddedJar(jarName + ".jar")
      .onFailure(error -> Logger.error(error::getMessage, error))
      .get();
  instrumentation.appendToBootstrapClassLoaderSearch(jarFile);
}

相关文章