Skip to content

Commit a15a7fc

Browse files
authored
metaspace内存持续上涨 (#3299)
* metaspace内存持续上涨 * 重复加载testcase * Update ObjectWriterProviderTest.java
1 parent 2978489 commit a15a7fc

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterProvider.java

+5
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,11 @@ private ObjectWriter getObjectWriterInternal(Type objectType, Class objectClass,
397397
if (objectWriter != null) {
398398
return objectWriter;
399399
}
400+
} else {
401+
objectWriter = cache.get(objectType);
402+
if (objectWriter != null) {
403+
return objectWriter;
404+
}
400405
}
401406
}
402407

core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java

+24
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
import com.alibaba.fastjson2.writer.ObjectWriter;
77
import com.alibaba.fastjson2.writer.ObjectWriterProvider;
88
import org.junit.jupiter.api.Test;
9+
import org.springframework.cglib.proxy.Enhancer;
10+
import org.springframework.cglib.proxy.MethodInterceptor;
11+
import org.springframework.cglib.proxy.MethodProxy;
912

13+
import java.lang.reflect.Method;
1014
import java.lang.reflect.Type;
15+
import java.util.concurrent.TimeUnit;
1116

1217
import static org.junit.jupiter.api.Assertions.*;
1318

@@ -131,9 +136,28 @@ public void testWriter2() {
131136
assertSame(writer1, JSON.registerIfAbsent(Bean.class, writer, false));
132137
}
133138

139+
@Test
140+
public void testWriterProxy() throws InterruptedException {
141+
Enhancer enhancer = new Enhancer();
142+
enhancer.setSuperclass(Bean.class);
143+
enhancer.setCallback(new BeanMethodInterceptor());
144+
Object proxy1 = enhancer.create();
145+
JSON.toJSONString(proxy1);
146+
JSON.toJSONString(proxy1);
147+
TimeUnit.MINUTES.sleep(60);
148+
}
149+
134150
public static class Bean {
135151
}
136152

153+
public static class BeanMethodInterceptor implements MethodInterceptor {
154+
155+
@Override
156+
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
157+
return methodProxy.invokeSuper(o, objects);
158+
}
159+
}
160+
137161
public static class BeanWriter
138162
implements ObjectWriter {
139163
@Override

0 commit comments

Comments
 (0)