You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/12/16 08:13:26 UTC

[shardingsphere] branch master updated: Refactor AdviceFactory (#22908)

This is an automated email from the ASF dual-hosted git repository.

panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 6b4df57f26f Refactor AdviceFactory (#22908)
6b4df57f26f is described below

commit 6b4df57f26ff63fec0b1cb668508a3f399ec3d7a
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Dec 16 16:13:13 2022 +0800

    Refactor AdviceFactory (#22908)
    
    * Refactor AdviceFactory
    
    * Refactor AdviceFactory
    
    * Refactor AdviceFactory
---
 .../core/plugin/loader/AdviceInstanceLoader.java   | 120 ---------------------
 .../core/transformer/builder/AdviceFactory.java    |  95 ++++++++++++++++
 .../builder/ConstructorAdvisorBuilder.java         |  24 ++---
 .../builder/InstanceMethodAdvisorBuilder.java      |  24 ++---
 .../builder/StaticMethodAdvisorBuilder.java        |  24 ++---
 .../core/transformer/AgentTransformerTest.java     |   4 +-
 6 files changed, 127 insertions(+), 164 deletions(-)

diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/loader/AdviceInstanceLoader.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/loader/AdviceInstanceLoader.java
deleted file mode 100644
index c61904e2857..00000000000
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/loader/AdviceInstanceLoader.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.core.plugin.loader;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import lombok.SneakyThrows;
-import org.apache.shardingsphere.agent.config.plugin.PluginConfiguration;
-import org.apache.shardingsphere.agent.core.classloader.AgentClassLoader;
-import org.apache.shardingsphere.agent.core.plugin.PluginBootServiceManager;
-import org.apache.shardingsphere.agent.core.plugin.PluginJarHolder;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.locks.ReentrantLock;
-
-/**
- * Advice instance loader.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class AdviceInstanceLoader {
-    
-    private static final Map<String, Object> ADVICE_INSTANCE_CACHE = new ConcurrentHashMap<>();
-    
-    private static final Map<ClassLoader, ClassLoader> PLUGIN_CLASSLOADERS = new HashMap<>();
-    
-    private static final ReentrantLock INIT_INSTANCE_LOCK = new ReentrantLock();
-    
-    private static boolean isStarted;
-    
-    /**
-     * Load instance of advice class.
-     *
-     * @param <T> expected type
-     * @param className class name
-     * @param classLoader class loader
-     * @param pluginConfigs plugin configurations
-     * @param isEnhancedForProxy is enhanced for proxy
-     * @return the type reference
-     */
-    public static <T> T loadAdviceInstance(final String className, final ClassLoader classLoader, final Map<String, PluginConfiguration> pluginConfigs, final boolean isEnhancedForProxy) {
-        return isEnhancedForProxy ? loadAdviceInstanceForProxy(className) : loadAdviceInstanceForJdbc(className, classLoader, pluginConfigs);
-    }
-    
-    @SneakyThrows(ReflectiveOperationException.class)
-    @SuppressWarnings("unchecked")
-    private static <T> T loadAdviceInstanceForProxy(final String className) {
-        Object adviceInstance = ADVICE_INSTANCE_CACHE.get(className);
-        if (Objects.nonNull(adviceInstance)) {
-            return (T) adviceInstance;
-        }
-        try {
-            INIT_INSTANCE_LOCK.lock();
-            adviceInstance = ADVICE_INSTANCE_CACHE.get(className);
-            if (Objects.isNull(adviceInstance)) {
-                adviceInstance = Class.forName(className, true, AgentClassLoader.getClassLoader()).getDeclaredConstructor().newInstance();
-                ADVICE_INSTANCE_CACHE.put(className, adviceInstance);
-            }
-            return (T) adviceInstance;
-        } finally {
-            INIT_INSTANCE_LOCK.unlock();
-        }
-    }
-    
-    @SneakyThrows(ReflectiveOperationException.class)
-    @SuppressWarnings("unchecked")
-    private static <T> T loadAdviceInstanceForJdbc(final String className, final ClassLoader classLoader, final Map<String, PluginConfiguration> pluginConfigs) {
-        String adviceInstanceCacheKey = String.format("%s_%s@%s", className, classLoader.getClass().getName(), Integer.toHexString(classLoader.hashCode()));
-        Object adviceInstance = ADVICE_INSTANCE_CACHE.get(adviceInstanceCacheKey);
-        if (Objects.nonNull(adviceInstance)) {
-            return (T) adviceInstance;
-        }
-        INIT_INSTANCE_LOCK.lock();
-        try {
-            adviceInstance = ADVICE_INSTANCE_CACHE.get(adviceInstanceCacheKey);
-            ClassLoader pluginClassLoader = PLUGIN_CLASSLOADERS.get(classLoader);
-            if (Objects.isNull(adviceInstance)) {
-                if (Objects.isNull(pluginClassLoader)) {
-                    pluginClassLoader = new AgentClassLoader(classLoader, PluginJarHolder.getPluginJars());
-                    PLUGIN_CLASSLOADERS.put(classLoader, pluginClassLoader);
-                }
-                adviceInstance = Class.forName(className, true, pluginClassLoader).getDeclaredConstructor().newInstance();
-                ADVICE_INSTANCE_CACHE.put(adviceInstanceCacheKey, adviceInstance);
-            }
-            setupPluginBootService(pluginClassLoader, pluginConfigs);
-            return (T) adviceInstance;
-        } finally {
-            INIT_INSTANCE_LOCK.unlock();
-        }
-    }
-    
-    private static void setupPluginBootService(final ClassLoader classLoader, final Map<String, PluginConfiguration> pluginConfigs) {
-        if (isStarted) {
-            return;
-        }
-        try {
-            PluginBootServiceManager.startAllServices(pluginConfigs, classLoader, false);
-            Runtime.getRuntime().addShutdownHook(new Thread(PluginBootServiceManager::closeAllServices));
-        } finally {
-            isStarted = true;
-        }
-    }
-}
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/builder/AdviceFactory.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/builder/AdviceFactory.java
new file mode 100644
index 00000000000..15dac5d78cf
--- /dev/null
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/builder/AdviceFactory.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.agent.core.transformer.builder;
+
+import lombok.RequiredArgsConstructor;
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.agent.config.plugin.PluginConfiguration;
+import org.apache.shardingsphere.agent.core.classloader.AgentClassLoader;
+import org.apache.shardingsphere.agent.core.plugin.PluginBootServiceManager;
+import org.apache.shardingsphere.agent.core.plugin.PluginJarHolder;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Advice factory.
+ */
+@RequiredArgsConstructor
+public final class AdviceFactory {
+    
+    private static final Map<String, Object> CACHED_ADVICES = new ConcurrentHashMap<>();
+    
+    private static final Map<ClassLoader, ClassLoader> PLUGIN_CLASS_LOADERS = new HashMap<>();
+    
+    private static boolean isStarted;
+    
+    private final ClassLoader classLoader;
+    
+    private final Map<String, PluginConfiguration> pluginConfigs;
+    
+    private final boolean isEnhancedForProxy;
+    
+    /**
+     * Get advice.
+     *
+     * @param adviceClassName advice class name
+     * @param <T> type of advice
+     * @return got advance
+     */
+    public <T> T getAdvice(final String adviceClassName) {
+        return isEnhancedForProxy ? getAdviceForProxy(adviceClassName) : getAdviceForJDBC(adviceClassName);
+    }
+    
+    @SuppressWarnings("unchecked")
+    private <T> T getAdviceForProxy(final String adviceClassName) {
+        return (T) CACHED_ADVICES.computeIfAbsent(adviceClassName, this::createAdviceForProxy);
+    }
+    
+    @SneakyThrows(ReflectiveOperationException.class)
+    private Object createAdviceForProxy(final String adviceClassName) {
+        return Class.forName(adviceClassName, true, AgentClassLoader.getClassLoader()).getDeclaredConstructor().newInstance();
+    }
+    
+    @SuppressWarnings("unchecked")
+    private <T> T getAdviceForJDBC(final String adviceClassName) {
+        String adviceInstanceCacheKey = String.format("%s_%s@%s", adviceClassName, classLoader.getClass().getName(), Integer.toHexString(classLoader.hashCode()));
+        return (T) CACHED_ADVICES.computeIfAbsent(adviceInstanceCacheKey, key -> createAdviceForJDBC(adviceClassName));
+    }
+    
+    @SneakyThrows(ReflectiveOperationException.class)
+    private Object createAdviceForJDBC(final String adviceClassName) {
+        ClassLoader pluginClassLoader = PLUGIN_CLASS_LOADERS.computeIfAbsent(classLoader, key -> new AgentClassLoader(key, PluginJarHolder.getPluginJars()));
+        Object result = Class.forName(adviceClassName, true, pluginClassLoader).getDeclaredConstructor().newInstance();
+        setupPluginBootService(pluginClassLoader);
+        return result;
+    }
+    
+    private void setupPluginBootService(final ClassLoader pluginClassLoader) {
+        if (isStarted) {
+            return;
+        }
+        try {
+            PluginBootServiceManager.startAllServices(pluginConfigs, pluginClassLoader, false);
+            Runtime.getRuntime().addShutdownHook(new Thread(PluginBootServiceManager::closeAllServices));
+        } finally {
+            isStarted = true;
+        }
+    }
+}
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/builder/ConstructorAdvisorBuilder.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/builder/ConstructorAdvisorBuilder.java
index ab2bf1c0b7a..1e079dea3c3 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/builder/ConstructorAdvisorBuilder.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/builder/ConstructorAdvisorBuilder.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.agent.core.transformer.builder;
 
-import lombok.RequiredArgsConstructor;
 import net.bytebuddy.description.method.MethodDescription;
 import net.bytebuddy.description.method.MethodDescription.InDefinedShape;
 import net.bytebuddy.description.type.TypeDescription;
@@ -31,7 +30,6 @@ import org.apache.shardingsphere.agent.core.logging.LoggerFactory;
 import org.apache.shardingsphere.agent.core.plugin.advice.ConstructorAdvice;
 import org.apache.shardingsphere.agent.core.plugin.interceptor.ConstructorInterceptor;
 import org.apache.shardingsphere.agent.core.plugin.interceptor.composed.ComposedConstructorInterceptor;
-import org.apache.shardingsphere.agent.core.plugin.loader.AdviceInstanceLoader;
 import org.apache.shardingsphere.agent.core.transformer.MethodAdvisor;
 
 import java.util.Collection;
@@ -43,20 +41,22 @@ import java.util.stream.Collectors;
 /**
  * Constructor advisor builder.
  */
-@RequiredArgsConstructor
 public final class ConstructorAdvisorBuilder {
     
     private static final LoggerFactory.Logger LOGGER = LoggerFactory.getLogger(ConstructorAdvisorBuilder.class);
     
-    private final Map<String, PluginConfiguration> pluginConfigs;
-    
     private final Collection<ConstructorAdvisorConfiguration> constructorAdvisorConfigs;
     
-    private final boolean isEnhancedForProxy;
-    
     private final TypeDescription typePointcut;
     
-    private final ClassLoader classLoader;
+    private final AdviceFactory adviceFactory;
+    
+    public ConstructorAdvisorBuilder(final Map<String, PluginConfiguration> pluginConfigs, final Collection<ConstructorAdvisorConfiguration> constructorAdvisorConfigs,
+                                     final boolean isEnhancedForProxy, final TypeDescription typePointcut, final ClassLoader classLoader) {
+        this.constructorAdvisorConfigs = constructorAdvisorConfigs;
+        this.typePointcut = typePointcut;
+        adviceFactory = new AdviceFactory(classLoader, pluginConfigs, isEnhancedForProxy);
+    }
     
     /**
      * Create constructor advisor builder.
@@ -92,16 +92,12 @@ public final class ConstructorAdvisorBuilder {
         }
         if (1 == matchedConstructorAdvisorConfigs.size()) {
             return new MethodAdvisor<>(
-                    methodPointcut, new ConstructorInterceptor(loadAdviceInstance(matchedConstructorAdvisorConfigs.get(0).getAdviceClassName())));
+                    methodPointcut, new ConstructorInterceptor(adviceFactory.getAdvice(matchedConstructorAdvisorConfigs.get(0).getAdviceClassName())));
         }
         Collection<ConstructorAdvice> constructorAdvices = matchedConstructorAdvisorConfigs.stream()
                 .map(ConstructorAdvisorConfiguration::getAdviceClassName)
-                .map(each -> (ConstructorAdvice) loadAdviceInstance(each))
+                .map(each -> (ConstructorAdvice) adviceFactory.getAdvice(each))
                 .collect(Collectors.toList());
         return new MethodAdvisor<>(methodPointcut, new ComposedConstructorInterceptor(constructorAdvices));
     }
-    
-    private <T> T loadAdviceInstance(final String adviceClassName) {
-        return AdviceInstanceLoader.loadAdviceInstance(adviceClassName, classLoader, pluginConfigs, isEnhancedForProxy);
-    }
 }
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/builder/InstanceMethodAdvisorBuilder.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/builder/InstanceMethodAdvisorBuilder.java
index 9f753b71507..f788d40beb6 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/builder/InstanceMethodAdvisorBuilder.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/builder/InstanceMethodAdvisorBuilder.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.agent.core.transformer.builder;
 
-import lombok.RequiredArgsConstructor;
 import net.bytebuddy.description.method.MethodDescription.InDefinedShape;
 import net.bytebuddy.description.type.TypeDescription;
 import net.bytebuddy.dynamic.DynamicType.Builder;
@@ -33,7 +32,6 @@ import org.apache.shardingsphere.agent.core.plugin.interceptor.InstanceMethodAro
 import org.apache.shardingsphere.agent.core.plugin.interceptor.InstanceMethodInterceptorArgsOverride;
 import org.apache.shardingsphere.agent.core.plugin.interceptor.composed.ComposedInstanceMethodAroundInterceptor;
 import org.apache.shardingsphere.agent.core.plugin.interceptor.composed.ComposedInstanceMethodInterceptorArgsOverride;
-import org.apache.shardingsphere.agent.core.plugin.loader.AdviceInstanceLoader;
 import org.apache.shardingsphere.agent.core.transformer.MethodAdvisor;
 
 import java.util.Collection;
@@ -46,20 +44,22 @@ import java.util.stream.Collectors;
 /**
  * Instance method advisor builder.
  */
-@RequiredArgsConstructor
 public final class InstanceMethodAdvisorBuilder {
     
     private static final LoggerFactory.Logger LOGGER = LoggerFactory.getLogger(InstanceMethodAdvisorBuilder.class);
     
-    private final Map<String, PluginConfiguration> pluginConfigs;
-    
     private final Collection<InstanceMethodAdvisorConfiguration> instanceMethodAdvisorConfigs;
     
-    private final boolean isEnhancedForProxy;
-    
     private final TypeDescription typePointcut;
     
-    private final ClassLoader classLoader;
+    private final AdviceFactory adviceFactory;
+    
+    public InstanceMethodAdvisorBuilder(final Map<String, PluginConfiguration> pluginConfigs, final Collection<InstanceMethodAdvisorConfiguration> instanceMethodAdvisorConfigs,
+                                        final boolean isEnhancedForProxy, final TypeDescription typePointcut, final ClassLoader classLoader) {
+        this.instanceMethodAdvisorConfigs = instanceMethodAdvisorConfigs;
+        this.typePointcut = typePointcut;
+        adviceFactory = new AdviceFactory(classLoader, pluginConfigs, isEnhancedForProxy);
+    }
     
     /**
      * Create instance method advisor builder.
@@ -104,7 +104,7 @@ public final class InstanceMethodAdvisorBuilder {
     }
     
     private MethodAdvisor<?> getSingleInstanceMethodPoint(final InDefinedShape methodPointcut, final InstanceMethodAdvisorConfiguration instanceMethodAdvisorConfig) {
-        InstanceMethodAroundAdvice instanceMethodAroundAdvice = loadAdviceInstance(instanceMethodAdvisorConfig.getAdviceClassName());
+        InstanceMethodAroundAdvice instanceMethodAroundAdvice = adviceFactory.getAdvice(instanceMethodAdvisorConfig.getAdviceClassName());
         return instanceMethodAdvisorConfig.isOverrideArgs()
                 ? new MethodAdvisor<>(methodPointcut, new InstanceMethodInterceptorArgsOverride(instanceMethodAroundAdvice))
                 : new MethodAdvisor<>(methodPointcut, new InstanceMethodAroundInterceptor(instanceMethodAroundAdvice));
@@ -118,15 +118,11 @@ public final class InstanceMethodAdvisorBuilder {
                 isArgsOverride = true;
             }
             if (null != each.getAdviceClassName()) {
-                instanceMethodAroundAdvices.add(loadAdviceInstance(each.getAdviceClassName()));
+                instanceMethodAroundAdvices.add(adviceFactory.getAdvice(each.getAdviceClassName()));
             }
         }
         return isArgsOverride
                 ? new MethodAdvisor<>(methodPointcut, new ComposedInstanceMethodInterceptorArgsOverride(instanceMethodAroundAdvices))
                 : new MethodAdvisor<>(methodPointcut, new ComposedInstanceMethodAroundInterceptor(instanceMethodAroundAdvices));
     }
-    
-    private <T> T loadAdviceInstance(final String adviceClassName) {
-        return AdviceInstanceLoader.loadAdviceInstance(adviceClassName, classLoader, pluginConfigs, isEnhancedForProxy);
-    }
 }
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/builder/StaticMethodAdvisorBuilder.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/builder/StaticMethodAdvisorBuilder.java
index 7e5e495dd60..cbb637b6569 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/builder/StaticMethodAdvisorBuilder.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/transformer/builder/StaticMethodAdvisorBuilder.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.agent.core.transformer.builder;
 
-import lombok.RequiredArgsConstructor;
 import net.bytebuddy.description.method.MethodDescription.InDefinedShape;
 import net.bytebuddy.description.type.TypeDescription;
 import net.bytebuddy.dynamic.DynamicType.Builder;
@@ -33,7 +32,6 @@ import org.apache.shardingsphere.agent.core.plugin.interceptor.StaticMethodAroun
 import org.apache.shardingsphere.agent.core.plugin.interceptor.StaticMethodInterceptorArgsOverride;
 import org.apache.shardingsphere.agent.core.plugin.interceptor.composed.ComposedStaticMethodAroundInterceptor;
 import org.apache.shardingsphere.agent.core.plugin.interceptor.composed.ComposedStaticMethodInterceptorArgsOverride;
-import org.apache.shardingsphere.agent.core.plugin.loader.AdviceInstanceLoader;
 import org.apache.shardingsphere.agent.core.transformer.MethodAdvisor;
 
 import java.util.Collection;
@@ -46,20 +44,22 @@ import java.util.stream.Collectors;
 /**
  * Static method advisor builder.
  */
-@RequiredArgsConstructor
 public final class StaticMethodAdvisorBuilder {
     
     private static final LoggerFactory.Logger LOGGER = LoggerFactory.getLogger(StaticMethodAdvisorBuilder.class);
     
-    private final Map<String, PluginConfiguration> pluginConfigs;
-    
     private final Collection<StaticMethodAdvisorConfiguration> staticMethodAdvisorConfigs;
     
-    private final boolean isEnhancedForProxy;
-    
     private final TypeDescription typePointcut;
     
-    private final ClassLoader classLoader;
+    private final AdviceFactory adviceFactory;
+    
+    public StaticMethodAdvisorBuilder(final Map<String, PluginConfiguration> pluginConfigs, final Collection<StaticMethodAdvisorConfiguration> staticMethodAdvisorConfigs,
+                                      final boolean isEnhancedForProxy, final TypeDescription typePointcut, final ClassLoader classLoader) {
+        this.staticMethodAdvisorConfigs = staticMethodAdvisorConfigs;
+        this.typePointcut = typePointcut;
+        adviceFactory = new AdviceFactory(classLoader, pluginConfigs, isEnhancedForProxy);
+    }
     
     /**
      * Create static method advisor builder.
@@ -103,7 +103,7 @@ public final class StaticMethodAdvisorBuilder {
     }
     
     private MethodAdvisor<?> getSingleStaticMethodPoint(final InDefinedShape methodPointcut, final StaticMethodAdvisorConfiguration staticMethodAdvisorConfig) {
-        StaticMethodAroundAdvice staticMethodAroundAdvice = loadAdviceInstance(staticMethodAdvisorConfig.getAdviceClassName());
+        StaticMethodAroundAdvice staticMethodAroundAdvice = adviceFactory.getAdvice(staticMethodAdvisorConfig.getAdviceClassName());
         return staticMethodAdvisorConfig.isOverrideArgs()
                 ? new MethodAdvisor<>(methodPointcut, new StaticMethodInterceptorArgsOverride(staticMethodAroundAdvice))
                 : new MethodAdvisor<>(methodPointcut, new StaticMethodAroundInterceptor(staticMethodAroundAdvice));
@@ -117,14 +117,10 @@ public final class StaticMethodAdvisorBuilder {
                 isArgsOverride = true;
             }
             if (null != each.getAdviceClassName()) {
-                staticMethodAroundAdvices.add(loadAdviceInstance(each.getAdviceClassName()));
+                staticMethodAroundAdvices.add(adviceFactory.getAdvice(each.getAdviceClassName()));
             }
         }
         return isArgsOverride ? new MethodAdvisor<>(methodPointcut, new ComposedStaticMethodInterceptorArgsOverride(staticMethodAroundAdvices))
                 : new MethodAdvisor<>(methodPointcut, new ComposedStaticMethodAroundInterceptor(staticMethodAroundAdvices));
     }
-    
-    private <T> T loadAdviceInstance(final String adviceClassName) {
-        return AdviceInstanceLoader.loadAdviceInstance(adviceClassName, classLoader, pluginConfigs, isEnhancedForProxy);
-    }
 }
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/AgentTransformerTest.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/AgentTransformerTest.java
index 25858dc7532..01bb54416d3 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/AgentTransformerTest.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/AgentTransformerTest.java
@@ -35,7 +35,7 @@ import org.apache.shardingsphere.agent.core.mock.advice.MockInstanceMethodAround
 import org.apache.shardingsphere.agent.core.mock.advice.MockStaticMethodAroundAdvice;
 import org.apache.shardingsphere.agent.core.mock.material.Material;
 import org.apache.shardingsphere.agent.core.mock.material.RepeatedAdviceMaterial;
-import org.apache.shardingsphere.agent.core.plugin.loader.AdviceInstanceLoader;
+import org.apache.shardingsphere.agent.core.transformer.builder.AdviceFactory;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -63,7 +63,7 @@ public final class AgentTransformerTest {
     public static void setup() throws ReflectiveOperationException {
         ByteBuddyAgent.install();
         AgentClassLoader.init(Collections.emptyList());
-        FieldReader objectPoolReader = new FieldReader(AdviceInstanceLoader.class, AdviceInstanceLoader.class.getDeclaredField("ADVICE_INSTANCE_CACHE"));
+        FieldReader objectPoolReader = new FieldReader(AdviceFactory.class, AdviceFactory.class.getDeclaredField("CACHED_ADVICES"));
         Map<String, Object> objectPool = (Map<String, Object>) objectPoolReader.read();
         objectPool.put(MockConstructorAdvice.class.getTypeName(), new MockConstructorAdvice());
         objectPool.put(MockInstanceMethodAroundAdvice.class.getTypeName(), new MockInstanceMethodAroundAdvice());