Java Code Examples for java.lang.instrument.Instrumentation#isRedefineClassesSupported()
The following examples show how to use
java.lang.instrument.Instrumentation#isRedefineClassesSupported() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AgentAttachmentRule.java From garmadon with Apache License 2.0 | 6 votes |
@Override public Statement apply(Statement base, FrameworkMethod method, Object target) { Enforce enforce = method.getAnnotation(Enforce.class); if (enforce != null) { if (!available) { return new NoOpStatement("The executing JVM does not support runtime attachment"); } Instrumentation instrumentation = ByteBuddyAgent.install(ByteBuddyAgent.AttachmentProvider.DEFAULT); if (enforce.redefinesClasses() && !instrumentation.isRedefineClassesSupported()) { return new NoOpStatement("The executing JVM does not support class redefinition"); } else if (enforce.retransformsClasses() && !instrumentation.isRetransformClassesSupported()) { return new NoOpStatement("The executing JVM does not support class retransformation"); } else if (enforce.nativeMethodPrefix() && !instrumentation.isNativeMethodPrefixSupported()) { return new NoOpStatement("The executing JVM does not support class native method prefixes"); } } return base; }
Example 2
Source File: JByteMod.java From JByteMod-Beta with GNU General Public License v2.0 | 6 votes |
public static void agentmain(String agentArgs, Instrumentation ins) { if (!ins.isRedefineClassesSupported()) { JOptionPane.showMessageDialog(null, "Class redefinition is disabled, cannot attach!"); return; } agentInstrumentation = ins; workingDir = new File(agentArgs); initialize(); if (!lafInit) { LookUtils.setLAF(); lafInit = true; } JByteMod.file = new RuntimeJarArchive(ins); JByteMod frame = new JByteMod(true); frame.setTitleSuffix("Agent"); instance = frame; frame.setVisible(true); }
Example 3
Source File: AgentAttachmentRule.java From byte-buddy with Apache License 2.0 | 6 votes |
public Statement apply(Statement base, FrameworkMethod method, Object target) { Enforce enforce = method.getAnnotation(Enforce.class); if (enforce != null) { if (!available) { return new NoOpStatement("The executing JVM does not support runtime attachment"); } Instrumentation instrumentation = ByteBuddyAgent.install(ByteBuddyAgent.AttachmentProvider.DEFAULT); if (enforce.redefinesClasses() && !instrumentation.isRedefineClassesSupported()) { return new NoOpStatement("The executing JVM does not support class redefinition"); } else if (enforce.retransformsClasses() && !instrumentation.isRetransformClassesSupported()) { return new NoOpStatement("The executing JVM does not support class retransformation"); } else if (enforce.nativeMethodPrefix() && !instrumentation.isNativeMethodPrefixSupported()) { return new NoOpStatement("The executing JVM does not support class native method prefixes"); } } return base; }
Example 4
Source File: AgentAttachmentRule.java From byte-buddy with Apache License 2.0 | 6 votes |
public Statement apply(Statement base, FrameworkMethod method, Object target) { Enforce enforce = method.getAnnotation(Enforce.class); if (enforce != null) { if (!available) { return new NoOpStatement("The executing JVM does not support runtime attachment"); } Instrumentation instrumentation = ByteBuddyAgent.install(ByteBuddyAgent.AttachmentProvider.DEFAULT); if (enforce.redefinesClasses() && !instrumentation.isRedefineClassesSupported()) { return new NoOpStatement("The executing JVM does not support class redefinition"); } else if (enforce.retransformsClasses() && !instrumentation.isRetransformClassesSupported()) { return new NoOpStatement("The executing JVM does not support class retransformation"); } else if (enforce.nativeMethodPrefix() && !instrumentation.isNativeMethodPrefixSupported()) { return new NoOpStatement("The executing JVM does not support class native method prefixes"); } } return base; }
Example 5
Source File: JVMAgent.java From james with Apache License 2.0 | 5 votes |
/** * The entry point invoked when this agent is started after the JVM starts. */ public static void agentmain(String agentArgs, Instrumentation inst) throws Throwable { LOG.trace("JVMAgent agentmain"); if (!inst.isRedefineClassesSupported()) throw new RuntimeException("this JVM does not support redefinition of classes"); instrumentation = inst; setupAgent(instrumentation); }
Example 6
Source File: RedefineIntrinsicTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void agentmain(@SuppressWarnings("unused") String args, Instrumentation inst) throws Exception { if (inst.isRedefineClassesSupported() && inst.isRetransformClassesSupported()) { inst.addTransformer(new Redefiner(), true); Class<?>[] allClasses = inst.getAllLoadedClasses(); for (int i = 0; i < allClasses.length; i++) { Class<?> c = allClasses[i]; if (c == Intrinsic.class) { inst.retransformClasses(new Class<?>[]{c}); } } } }
Example 7
Source File: RedefineClassTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void agentmain(@SuppressWarnings("unused") String args, Instrumentation inst) throws Exception { if (inst.isRedefineClassesSupported() && inst.isRetransformClassesSupported()) { inst.addTransformer(new FooTransformer(), true); Class<?>[] allClasses = inst.getAllLoadedClasses(); for (int i = 0; i < allClasses.length; i++) { Class<?> c = allClasses[i]; if (c == Foo.class) { inst.retransformClasses(new Class<?>[]{c}); } } } }
Example 8
Source File: ClassReloadingStrategy.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Creates a class reloading strategy for the given instrumentation. The given instrumentation must either * support {@link java.lang.instrument.Instrumentation#isRedefineClassesSupported()} or * {@link java.lang.instrument.Instrumentation#isRetransformClassesSupported()}. If both modes are supported, * classes will be transformed using a class retransformation. * * @param instrumentation The instrumentation to be used by this reloading strategy. * @return A suitable class reloading strategy. */ public static ClassReloadingStrategy of(Instrumentation instrumentation) { if (DISPATCHER.isRetransformClassesSupported(instrumentation)) { return new ClassReloadingStrategy(instrumentation, Strategy.RETRANSFORMATION); } else if (instrumentation.isRedefineClassesSupported()) { return new ClassReloadingStrategy(instrumentation, Strategy.REDEFINITION); } else { throw new IllegalArgumentException("Instrumentation does not support reloading of classes: " + instrumentation); } }
Example 9
Source File: ClassReloadingStrategy.java From byte-buddy with Apache License 2.0 | 5 votes |
@Override protected Strategy validate(Instrumentation instrumentation) { if (!instrumentation.isRedefineClassesSupported()) { throw new IllegalArgumentException("Does not support redefinition: " + instrumentation); } return this; }
Example 10
Source File: HotSwapAgent.java From HotswapAgent with GNU General Public License v2.0 | 5 votes |
/** * The entry point invoked when this agent is started after the JVM starts. */ public static void agentmain(String agentArgs, Instrumentation inst) throws Throwable { if (!inst.isRedefineClassesSupported()) throw new RuntimeException("this JVM does not support redefinition of classes"); instrumentation = inst; }
Example 11
Source File: JVMAgent.java From james with Apache License 2.0 | 4 votes |
/** * should prepare whole james world to work * @param inst */ private static void setupAgent(Instrumentation inst) { LOG.trace("JVMAgent agentmain"); try { if (inst != null) { if (!inst.isRedefineClassesSupported()) { throw new RuntimeException("this JVM does not support redefinition of classes"); } } // init class - to be 100% sure that has been loaded GlobalValueStore.getValueStore(); AgentConfiguration configuration = AgentConfigurationFactory.create(); Logger.setCurrentLogLevel(configuration.getLogLevel()); printBanner(configuration); Stopwatch stopwatch = Stopwatch.createStarted(); PluginManager pluginManager = new PluginManager(configuration.getPluginIncludeDirectories(), configuration.getPluginIncludeFiles()); LOG.trace("pluginManager time=" + stopwatch.elapsed()); EventPublisher publisher = EventPublisherFactory.create(pluginManager, configuration.getPublishersConfigurations()); LOG.trace("publisher time=" + stopwatch.elapsed()); InformationPointStore store = InformationPointStoreFactory.create(configuration.getInformationPointStoreConfiguration()); LOG.trace("store time=" + stopwatch.elapsed()); ToolkitManager toolkitManager = new ToolkitManager(pluginManager, configuration.getToolkitsConfigurations()); LOG.trace("toolkitManager time=" + stopwatch.elapsed()); ScriptEngine engine = ScriptEngineFactory.create(publisher, configuration, toolkitManager); LOG.trace("engine time=" + stopwatch.elapsed()); ControllersManager controllersManager = new ControllersManager(pluginManager, configuration.getControllersConfigurations()); LOG.trace("controllerManager time=" + stopwatch.elapsed()); InformationPointQueue newInformationPointQueue = new BasicInformationPointQueue(10000); // max 10000 information points in queue InformationPointQueue removeInformationPointQueue = new BasicInformationPointQueue(10000); // max 10000 information points in queue ClassQueue newClassQueue = new BasicClassQueue(200000); // max 200000 new classes in queue // iformation point provider InformationPointService informationPointService = new InformationPointServiceImpl(store, newInformationPointQueue, removeInformationPointQueue); LOG.trace("informationPointService time=" + stopwatch.elapsed()); // ClassService - scans JVM loaded classes and put every new class to the newClassQuery LOG.trace("ClassService init :: ignoredPackages=" + configuration.getClassScannerConfiguration().getIgnoredPackages().stream().collect(Collectors.joining(", "))); ClassService classService = new BasicClassService(newClassQueue, configuration.getClassScannerConfiguration().getIgnoredPackages(), configuration.getClassScannerConfiguration().getInitialDelayInMs(), configuration.getClassScannerConfiguration().getScanPeriodInMs()); LOG.trace("classService time=" + stopwatch.elapsed()); LOG.debug("JVMAgent - ClassService is executed."); // TODO builder jamesHQ = new JamesHQ(informationPointService, classService, newInformationPointQueue, removeInformationPointQueue, newClassQueue, configuration.getJamesHQConfiguration().getInitialDelayInMs(), configuration.getJamesHQConfiguration().getScanPeriodInMs(), configuration.getJamesHQConfiguration().getJamesIntervalInMs()); jamesHQ.start(); LOG.trace("James HQ time=" + stopwatch.elapsed()); LOG.debug("JVMAgent - JamesHQ is executed."); controllersManager.initializeControllers( informationPointService, classService.getClassScanner(), engine, publisher, jamesHQ.getJamesObjectivesQueue(), newClassQueue, newInformationPointQueue, removeInformationPointQueue ); LOG.trace("initialize controllers time=" + stopwatch.elapsed()); ShutdownHook shutdownHook = new ShutdownHook(controllersManager, engine, publisher, configuration, () -> MethodExecutionContextHelper.shutdown()); Runtime.getRuntime().addShutdownHook(shutdownHook); LOG.trace("shutdownHook time=" + stopwatch.elapsed()); stopwatch.stop(); LOG.info("JVMAgent - initialization complete - time=" + stopwatch.elapsed()); } catch (ConfigurationInitializationException e) { e.printStackTrace(); } }