Skip to content

Commit 8747e60

Browse files
authored
feat: optimize dynamic (#346)
1 parent 274f9a5 commit 8747e60

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

arex-agent-core/src/main/java/io/arex/agent/instrumentation/InstrumentationInstaller.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import io.arex.inst.runtime.model.DynamicClassStatusEnum;
1414
import io.arex.agent.bootstrap.util.ServiceLoader;
1515
import java.util.stream.Collectors;
16+
17+
import io.arex.inst.runtime.util.IgnoreUtils;
1618
import net.bytebuddy.ByteBuddy;
1719
import net.bytebuddy.agent.builder.AgentBuilder;
1820
import net.bytebuddy.agent.builder.ResettableClassFileTransformer;
@@ -61,7 +63,7 @@ private ResettableClassFileTransformer retransform() {
6163
LOGGER.info("[AREX] No Change in dynamic class config, no need to retransform.");
6264
return resettableClassFileTransformer;
6365
}
64-
66+
IgnoreUtils.clearInvalidOperation();
6567
instrumentation.removeTransformer(resettableClassFileTransformer);
6668
resettableClassFileTransformer = install(getAgentBuilder(), true);
6769
LOGGER.info("[AREX] Agent retransform successfully.");
@@ -73,7 +75,7 @@ private void resetClass() {
7375
if (CollectionUtil.isEmpty(resetClassSet)) {
7476
return;
7577
}
76-
78+
IgnoreUtils.clearInvalidOperation();
7779
instrumentation.removeTransformer(resettableClassFileTransformer);
7880
// TODO: optimize reset abstract class
7981
for (Class<?> clazz : this.instrumentation.getAllLoadedClasses()) {

arex-instrumentation-api/src/main/java/io/arex/inst/runtime/util/IgnoreUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,8 @@ public static void addInvalidOperation(String operationSignature) {
125125
INVALID_OPERATION_HASH_CACHE.add(operationSignature.hashCode());
126126
}
127127

128+
public static void clearInvalidOperation() {
129+
INVALID_OPERATION_HASH_CACHE.clear();
130+
}
131+
128132
}

arex-instrumentation-api/src/test/java/io/arex/inst/runtime/util/IgnoreUtilsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,7 @@ void ignoreOperation_excludePathList() {
110110
void invalidOperation() {
111111
IgnoreUtils.addInvalidOperation("testClass.testMethod");
112112
assertTrue(IgnoreUtils.invalidOperation("testClass.testMethod"));
113+
IgnoreUtils.clearInvalidOperation();
114+
assertFalse(IgnoreUtils.invalidOperation("testClass.testMethod"));
113115
}
114116
}

arex-instrumentation/dynamic/arex-dynamic-common/src/main/java/io/arex/inst/dynamic/common/DynamicClassExtractor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.util.Objects;
3232
import java.util.concurrent.CompletableFuture;
3333
import java.util.concurrent.Future;
34-
import java.util.function.Consumer;
3534
import reactor.core.publisher.Mono;
3635

3736
public class DynamicClassExtractor {
@@ -185,7 +184,7 @@ String buildMethodKey(Method method, Object[] args, String keyExpression) {
185184
}
186185

187186
String key = ExpressionParseUtil.generateKey(method, args, keyExpression);
188-
if (key != null) {
187+
if (key != null || StringUtil.isNotEmpty(keyExpression)) {
189188
return key;
190189
}
191190

arex-instrumentation/dynamic/arex-dynamic-common/src/test/java/io/arex/inst/dynamic/common/DynamicClassExtractorTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,25 @@ void testBuildMethodKey() throws Throwable {
350350
ConfigBuilder.create("mock-service").dynamicClassList(list).build();
351351
actualResult = extractor.buildMethodKey(testWithArexMock, new Object[]{"mock-method-key"});
352352
assertEquals("mock-method-key", actualResult);
353+
354+
// express is null
355+
Method testWithArexMockList = DynamicClassExtractorTest.class.getDeclaredMethod("testWithArexMock", List.class);
356+
extractor = new DynamicClassExtractor(testWithArexMockList, new Object[]{new ArrayList<>()}, null, String.class);
357+
list.clear();
358+
list.add(new DynamicClassEntity("io.arex.inst.dynamic.common.DynamicClassExtractorTest", "testWithArexMock", "mock", "$1.get(0)"));
359+
ConfigBuilder.create("mock-service").dynamicClassList(list).build();
360+
actualResult = extractor.buildMethodKey(testWithArexMockList, new Object[]{new ArrayList<>()});
361+
assertNull(actualResult);
353362
}
354363

355364
public String testWithArexMock(String val) {
356365
return val + "testWithArexMock";
357366
}
358367

368+
public String testWithArexMock(List list) {
369+
return "testWithArexMock";
370+
}
371+
359372
public ListenableFuture<String> testReturnListenableFuture(String val, Throwable t) {
360373
if (t != null) {
361374
return Futures.immediateFailedFuture(t);

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
<properties>
5656
<!-- Maven CI Friendly Versions https://maven.apache.org/maven-ci-friendly.html -->
57-
<revision>0.3.14</revision>
57+
<revision>0.3.16</revision>
5858
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5959
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
6060

0 commit comments

Comments
 (0)