apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java
public static void premain(String agentArgs, Instrumentation instrumentation) throws PluginException {
        final PluginFinder pluginFinder;
        try {
            SnifferConfigInitializer.initializeCoreConfig(agentArgs);

            pluginFinder = new PluginFinder(new PluginBootstrap().loadPlugins());
        } catch (AgentPackageNotFoundException ape) {
            LOGGER.error(ape, "Locate agent.jar failure. Shutting down.");
            return;
        } catch (Exception e) {
            LOGGER.error(e, "SkyWalking agent initialized failure. Shutting down.");
            return;
        }

        final ByteBuddy byteBuddy = new ByteBuddy().with(TypeValidation.of(Config.Agent.IS_OPEN_DEBUGGING_CLASS));

        AgentBuilder agentBuilder = new AgentBuilder.Default(byteBuddy).ignore(
            nameStartsWith("net.bytebuddy.").or(nameStartsWith("org.slf4j."))
                                            .or(nameStartsWith("org.groovy."))
                                            .or(nameContains("javassist"))
                                            .or(nameContains(".asm."))
                                            .or(nameContains(".reflectasm."))
                                            .or(nameStartsWith("sun.reflect"))
                                            .or(allSkyWalkingAgentExcludeToolkit())
                                            .or(ElementMatchers.isSynthetic()));

        JDK9ModuleExporter.EdgeClasses edgeClasses = new JDK9ModuleExporter.EdgeClasses();
        try {
            agentBuilder = BootstrapInstrumentBoost.inject(pluginFinder, instrumentation, agentBuilder, edgeClasses);
        } catch (Exception e) {
            LOGGER.error(e, "SkyWalking agent inject bootstrap instrumentation failure. Shutting down.");
            return;
        }

        try {
            agentBuilder = JDK9ModuleExporter.openReadEdge(instrumentation, agentBuilder, edgeClasses);
        } catch (Exception e) {
            LOGGER.error(e, "SkyWalking agent open read edge in JDK 9+ failure. Shutting down.");
            return;
        }

        if (Config.Agent.IS_CACHE_ENHANCED_CLASS) {
            try {
                agentBuilder = agentBuilder.with(new CacheableTransformerDecorator(Config.Agent.CLASS_CACHE_MODE));
                LOGGER.info("SkyWalking agent class cache [{}] activated.", Config.Agent.CLASS_CACHE_MODE);
            } catch (Exception e) {
                LOGGER.error(e, "SkyWalking agent can't active class cache.");
            }
        }

        agentBuilder.type(pluginFinder.buildMatch())
                    .transform(new Transformer(pluginFinder))
                    .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
                    .with(new Listener())
                    .installOn(instrumentation);

        try {
            ServiceManager.INSTANCE.boot();
        } catch (Exception e) {
            LOGGER.error(e, "Skywalking agent boot failure.");
        }

        Runtime.getRuntime()
               .addShutdownHook(new Thread(ServiceManager.INSTANCE::shutdown, "skywalking service shutdown thread"));
    }
/**
     * Main entrance. Use byte-buddy transform to enhance all classes, which define in plugins.
     */
Main entrance. Use byte-buddy transform to enhance all classes, which define in plugins.
Main entrance . Use byte - buddy transform to enhance all classes which define in plugins .
public static void premain(String agentArgs, Instrumentation instrumentation) throws PluginException {
        final PluginFinder pluginFinder;
        try {
            SnifferConfigInitializer.initializeCoreConfig(agentArgs);
            pluginFinder = new PluginFinder(new PluginBootstrap().loadPlugins());
        } catch (AgentPackageNotFoundException ape) {
            LOGGER.error(ape, "Locate agent.jar failure. Shutting down.");
            return;
        } catch (Exception e) {
            LOGGER.error(e, "SkyWalking agent initialized failure. Shutting down.");
            return;
        }
        final ByteBuddy byteBuddy = new ByteBuddy().with(TypeValidation.of(Config.Agent.IS_OPEN_DEBUGGING_CLASS));
        AgentBuilder agentBuilder = new AgentBuilder.Default(byteBuddy).ignore(
            nameStartsWith("net.bytebuddy.").or(nameStartsWith("org.slf4j."))
                                            .or(nameStartsWith("org.groovy."))
                                            .or(nameContains("javassist"))
                                            .or(nameContains(".asm."))
                                            .or(nameContains(".reflectasm."))
                                            .or(nameStartsWith("sun.reflect"))
                                            .or(allSkyWalkingAgentExcludeToolkit())
                                            .or(ElementMatchers.isSynthetic()));
        JDK9ModuleExporter.EdgeClasses edgeClasses = new JDK9ModuleExporter.EdgeClasses();
        try {
            agentBuilder = BootstrapInstrumentBoost.inject(pluginFinder, instrumentation, agentBuilder, edgeClasses);
        } catch (Exception e) {
            LOGGER.error(e, "SkyWalking agent inject bootstrap instrumentation failure. Shutting down.");
            return;
        }
        try {
            agentBuilder = JDK9ModuleExporter.openReadEdge(instrumentation, agentBuilder, edgeClasses);
        } catch (Exception e) {
            LOGGER.error(e, "SkyWalking agent open read edge in JDK 9+ failure. Shutting down.");
            return;
        }
        if (Config.Agent.IS_CACHE_ENHANCED_CLASS) {
            try {
                agentBuilder = agentBuilder.with(new CacheableTransformerDecorator(Config.Agent.CLASS_CACHE_MODE));
                LOGGER.info("SkyWalking agent class cache [{}] activated.", Config.Agent.CLASS_CACHE_MODE);
            } catch (Exception e) {
                LOGGER.error(e, "SkyWalking agent can't active class cache.");
            }
        }
        agentBuilder.type(pluginFinder.buildMatch())
                    .transform(new Transformer(pluginFinder))
                    .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
                    .with(new Listener())
                    .installOn(instrumentation);
        try {
            ServiceManager.INSTANCE.boot();
        } catch (Exception e) {
            LOGGER.error(e, "Skywalking agent boot failure.");
        }
        Runtime.getRuntime()
               .addShutdownHook(new Thread(ServiceManager.INSTANCE::shutdown, "skywalking service shutdown thread"));
    }
public static void premain ( String agentArgs , Instrumentation instrumentation ) throws PluginException { final PluginFinder pluginFinder ; try { SnifferConfigInitializer . initializeCoreConfig ( agentArgs ) ; pluginFinder = new PluginFinder ( new PluginBootstrap ( ) . loadPlugins ( ) ) ; } catch ( AgentPackageNotFoundException ape ) { LOGGER . error ( ape , "Locate agent.jar failure. Shutting down." ) ; return ; } catch ( Exception e ) { LOGGER . error ( e , "SkyWalking agent initialized failure. Shutting down." ) ; return ; } final ByteBuddy byteBuddy = new ByteBuddy ( ) . with ( TypeValidation . of ( Config . Agent . IS_OPEN_DEBUGGING_CLASS ) ) ; AgentBuilder agentBuilder = new AgentBuilder . Default ( byteBuddy ) . ignore ( nameStartsWith ( "net.bytebuddy." ) . or ( nameStartsWith ( "org.slf4j." ) ) . or ( nameStartsWith ( "org.groovy." ) ) . or ( nameContains ( "javassist" ) ) . or ( nameContains ( ".asm." ) ) . or ( nameContains ( ".reflectasm." ) ) . or ( nameStartsWith ( "sun.reflect" ) ) . or ( allSkyWalkingAgentExcludeToolkit ( ) ) . or ( ElementMatchers . isSynthetic ( ) ) ) ; JDK9ModuleExporter . EdgeClasses edgeClasses = new JDK9ModuleExporter . EdgeClasses ( ) ; try { agentBuilder = BootstrapInstrumentBoost . inject ( pluginFinder , instrumentation , agentBuilder , edgeClasses ) ; } catch ( Exception e ) { LOGGER . error ( e , "SkyWalking agent inject bootstrap instrumentation failure. Shutting down." ) ; return ; } try { agentBuilder = JDK9ModuleExporter . openReadEdge ( instrumentation , agentBuilder , edgeClasses ) ; } catch ( Exception e ) { LOGGER . error ( e , "SkyWalking agent open read edge in JDK 9+ failure. Shutting down." ) ; return ; } if ( Config . Agent . IS_CACHE_ENHANCED_CLASS ) { try { agentBuilder = agentBuilder . with ( new CacheableTransformerDecorator ( Config . Agent . CLASS_CACHE_MODE ) ) ; LOGGER . info ( "SkyWalking agent class cache [{}] activated." , Config . Agent . CLASS_CACHE_MODE ) ; } catch ( Exception e ) { LOGGER . error ( e , "SkyWalking agent can't active class cache." ) ; } } agentBuilder . type ( pluginFinder . buildMatch ( ) ) . transform ( new Transformer ( pluginFinder ) ) . with ( AgentBuilder . RedefinitionStrategy . RETRANSFORMATION ) . with ( new Listener ( ) ) . installOn ( instrumentation ) ; try { ServiceManager . INSTANCE . boot ( ) ; } catch ( Exception e ) { LOGGER . error ( e , "Skywalking agent boot failure." ) ; } Runtime . getRuntime ( ) . addShutdownHook ( new Thread ( ServiceManager . INSTANCE :: shutdown , "skywalking service shutdown thread" ) ) ; }
Main entrance.
Main entrance .