From a15a7fcda5ccf55d7c0017e03b00bda1525d1dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=96=E6=9E=97?= <55180407+LSL-cloud@users.noreply.github.com> Date: Wed, 22 Jan 2025 13:44:50 +0800 Subject: [PATCH 1/4] =?UTF-8?q?metaspace=E5=86=85=E5=AD=98=E6=8C=81?= =?UTF-8?q?=E7=BB=AD=E4=B8=8A=E6=B6=A8=20(#3299)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * metaspace内存持续上涨 * 重复加载testcase * Update ObjectWriterProviderTest.java --- .../writer/ObjectWriterProvider.java | 5 ++++ .../write/ObjectWriterProviderTest.java | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterProvider.java b/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterProvider.java index d991fad09d..6e8b783ca7 100644 --- a/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterProvider.java +++ b/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterProvider.java @@ -397,6 +397,11 @@ private ObjectWriter getObjectWriterInternal(Type objectType, Class objectClass, if (objectWriter != null) { return objectWriter; } + } else { + objectWriter = cache.get(objectType); + if (objectWriter != null) { + return objectWriter; + } } } diff --git a/core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java b/core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java index c1507626ca..82eb3a6acd 100644 --- a/core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java +++ b/core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java @@ -6,8 +6,13 @@ import com.alibaba.fastjson2.writer.ObjectWriter; import com.alibaba.fastjson2.writer.ObjectWriterProvider; import org.junit.jupiter.api.Test; +import org.springframework.cglib.proxy.Enhancer; +import org.springframework.cglib.proxy.MethodInterceptor; +import org.springframework.cglib.proxy.MethodProxy; +import java.lang.reflect.Method; import java.lang.reflect.Type; +import java.util.concurrent.TimeUnit; import static org.junit.jupiter.api.Assertions.*; @@ -131,9 +136,28 @@ public void testWriter2() { assertSame(writer1, JSON.registerIfAbsent(Bean.class, writer, false)); } + @Test + public void testWriterProxy() throws InterruptedException { + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(Bean.class); + enhancer.setCallback(new BeanMethodInterceptor()); + Object proxy1 = enhancer.create(); + JSON.toJSONString(proxy1); + JSON.toJSONString(proxy1); + TimeUnit.MINUTES.sleep(60); + } + public static class Bean { } + public static class BeanMethodInterceptor implements MethodInterceptor { + + @Override + public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { + return methodProxy.invokeSuper(o, objects); + } + } + public static class BeanWriter implements ObjectWriter { @Override From 9381547af19f45dfbc838d16de7613e222b0c1d3 Mon Sep 17 00:00:00 2001 From: wenshao Date: Wed, 22 Jan 2025 20:08:40 +0800 Subject: [PATCH 2/4] fix code style --- .../com/alibaba/fastjson2/write/ObjectWriterProviderTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java b/core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java index 82eb3a6acd..3303d622b0 100644 --- a/core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java +++ b/core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java @@ -150,8 +150,8 @@ public void testWriterProxy() throws InterruptedException { public static class Bean { } - public static class BeanMethodInterceptor implements MethodInterceptor { - + public static class BeanMethodInterceptor + implements MethodInterceptor { @Override public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { return methodProxy.invokeSuper(o, objects); From 831bb9152b1e3d46afbdb38d85dedf3687546417 Mon Sep 17 00:00:00 2001 From: wenshao Date: Wed, 22 Jan 2025 20:21:33 +0800 Subject: [PATCH 3/4] Revert "fix code style" This reverts commit 9381547af19f45dfbc838d16de7613e222b0c1d3. --- .../com/alibaba/fastjson2/write/ObjectWriterProviderTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java b/core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java index 3303d622b0..82eb3a6acd 100644 --- a/core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java +++ b/core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java @@ -150,8 +150,8 @@ public void testWriterProxy() throws InterruptedException { public static class Bean { } - public static class BeanMethodInterceptor - implements MethodInterceptor { + public static class BeanMethodInterceptor implements MethodInterceptor { + @Override public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { return methodProxy.invokeSuper(o, objects); From 402d21df7804e281e0baa4d42ebfc722c57fb78f Mon Sep 17 00:00:00 2001 From: wenshao Date: Wed, 22 Jan 2025 20:21:37 +0800 Subject: [PATCH 4/4] =?UTF-8?q?Revert=20"metaspace=E5=86=85=E5=AD=98?= =?UTF-8?q?=E6=8C=81=E7=BB=AD=E4=B8=8A=E6=B6=A8=20(#3299)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit a15a7fcda5ccf55d7c0017e03b00bda1525d1dc1. --- .../writer/ObjectWriterProvider.java | 5 ---- .../write/ObjectWriterProviderTest.java | 24 ------------------- 2 files changed, 29 deletions(-) diff --git a/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterProvider.java b/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterProvider.java index 6e8b783ca7..d991fad09d 100644 --- a/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterProvider.java +++ b/core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterProvider.java @@ -397,11 +397,6 @@ private ObjectWriter getObjectWriterInternal(Type objectType, Class objectClass, if (objectWriter != null) { return objectWriter; } - } else { - objectWriter = cache.get(objectType); - if (objectWriter != null) { - return objectWriter; - } } } diff --git a/core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java b/core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java index 82eb3a6acd..c1507626ca 100644 --- a/core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java +++ b/core/src/test/java/com/alibaba/fastjson2/write/ObjectWriterProviderTest.java @@ -6,13 +6,8 @@ import com.alibaba.fastjson2.writer.ObjectWriter; import com.alibaba.fastjson2.writer.ObjectWriterProvider; import org.junit.jupiter.api.Test; -import org.springframework.cglib.proxy.Enhancer; -import org.springframework.cglib.proxy.MethodInterceptor; -import org.springframework.cglib.proxy.MethodProxy; -import java.lang.reflect.Method; import java.lang.reflect.Type; -import java.util.concurrent.TimeUnit; import static org.junit.jupiter.api.Assertions.*; @@ -136,28 +131,9 @@ public void testWriter2() { assertSame(writer1, JSON.registerIfAbsent(Bean.class, writer, false)); } - @Test - public void testWriterProxy() throws InterruptedException { - Enhancer enhancer = new Enhancer(); - enhancer.setSuperclass(Bean.class); - enhancer.setCallback(new BeanMethodInterceptor()); - Object proxy1 = enhancer.create(); - JSON.toJSONString(proxy1); - JSON.toJSONString(proxy1); - TimeUnit.MINUTES.sleep(60); - } - public static class Bean { } - public static class BeanMethodInterceptor implements MethodInterceptor { - - @Override - public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { - return methodProxy.invokeSuper(o, objects); - } - } - public static class BeanWriter implements ObjectWriter { @Override