diff --git a/java/fury-core/src/main/java/org/apache/fury/Fury.java b/java/fury-core/src/main/java/org/apache/fury/Fury.java index 9f3e84e1bd..bb2aa87e92 100644 --- a/java/fury-core/src/main/java/org/apache/fury/Fury.java +++ b/java/fury-core/src/main/java/org/apache/fury/Fury.java @@ -134,7 +134,7 @@ public Fury(FuryBuilder builder, ClassLoader classLoader) { config = new Config(builder); this.language = config.getLanguage(); this.refTracking = config.trackingRef(); - this.copyRefTracking = config.copyTrackingRef(); + this.copyRefTracking = config.copyRef(); this.shareMeta = config.isMetaShareEnabled(); compressInt = config.compressInt(); longEncoding = config.longEncoding(); diff --git a/java/fury-core/src/main/java/org/apache/fury/config/Config.java b/java/fury-core/src/main/java/org/apache/fury/config/Config.java index e783044f4f..fad9d3957d 100644 --- a/java/fury-core/src/main/java/org/apache/fury/config/Config.java +++ b/java/fury-core/src/main/java/org/apache/fury/config/Config.java @@ -38,7 +38,7 @@ public class Config implements Serializable { private final boolean basicTypesRefIgnored; private final boolean stringRefIgnored; private final boolean timeRefIgnored; - private final boolean copyTrackingRef; + private final boolean copyRef; private final boolean codeGenEnabled; private final boolean checkClassVersion; private final CompatibleMode compatibleMode; @@ -66,7 +66,7 @@ public Config(FuryBuilder builder) { basicTypesRefIgnored = !trackingRef || builder.basicTypesRefIgnored; stringRefIgnored = !trackingRef || builder.stringRefIgnored; timeRefIgnored = !trackingRef || builder.timeRefIgnored; - copyTrackingRef = builder.copyTrackingRef; + copyRef = builder.copyRef; compressString = builder.compressString; compressInt = builder.compressInt; longEncoding = builder.longEncoding; @@ -101,8 +101,16 @@ public boolean trackingRef() { return trackingRef; } - public boolean copyTrackingRef() { - return copyTrackingRef; + /** + * Returns true if copy value by ref, and false copy by value. + * + *

If this option is false, shared reference will be copied into different object, and circular + * reference copy will raise stack overflow exception. + * + *

If this option is enabled, the copy performance will be slower. + */ + public boolean copyRef() { + return copyRef; } public boolean isBasicTypesRefIgnored() { @@ -253,7 +261,7 @@ public boolean equals(Object o) { && basicTypesRefIgnored == config.basicTypesRefIgnored && stringRefIgnored == config.stringRefIgnored && timeRefIgnored == config.timeRefIgnored - && copyTrackingRef == config.copyTrackingRef + && copyRef == config.copyRef && codeGenEnabled == config.codeGenEnabled && checkClassVersion == config.checkClassVersion && checkJdkClassSerializable == config.checkJdkClassSerializable @@ -283,7 +291,7 @@ public int hashCode() { basicTypesRefIgnored, stringRefIgnored, timeRefIgnored, - copyTrackingRef, + copyRef, codeGenEnabled, checkClassVersion, compatibleMode, diff --git a/java/fury-core/src/main/java/org/apache/fury/config/FuryBuilder.java b/java/fury-core/src/main/java/org/apache/fury/config/FuryBuilder.java index 2080dca6cd..4d5c9686ea 100644 --- a/java/fury-core/src/main/java/org/apache/fury/config/FuryBuilder.java +++ b/java/fury-core/src/main/java/org/apache/fury/config/FuryBuilder.java @@ -59,7 +59,7 @@ public final class FuryBuilder { boolean checkClassVersion = false; Language language = Language.JAVA; boolean trackingRef = false; - boolean copyTrackingRef = false; + boolean copyRef = false; boolean basicTypesRefIgnored = true; boolean stringRefIgnored = true; boolean timeRefIgnored = true; @@ -99,9 +99,16 @@ public FuryBuilder withRefTracking(boolean trackingRef) { return this; } - /** Whether track {@link Fury#copy(Object)} circular references. */ - public FuryBuilder withCopyRefTracking(boolean copyTrackingRef) { - this.copyTrackingRef = copyTrackingRef; + /** + * Whether track {@link Fury#copy(Object)} shared or circular references. + * + *

If this option is false, shared reference will be copied into different object, and circular + * reference copy will raise stack overflow exception. + * + *

If this option is enabled, the copy performance will be slower. + */ + public FuryBuilder withRefCopy(boolean copyRef) { + this.copyRef = copyRef; return this; } diff --git a/java/fury-core/src/test/java/org/apache/fury/FuryCopyTest.java b/java/fury-core/src/test/java/org/apache/fury/FuryCopyTest.java index b86fe07ae4..213e82e962 100644 --- a/java/fury-core/src/test/java/org/apache/fury/FuryCopyTest.java +++ b/java/fury-core/src/test/java/org/apache/fury/FuryCopyTest.java @@ -86,7 +86,7 @@ public class FuryCopyTest extends FuryTestBase { - private final Fury fury = builder().withCopyRefTracking(true).withCodegen(false).build(); + private final Fury fury = builder().withRefCopy(true).withCodegen(false).build(); @Test public void immutableObjectCopyTest() { @@ -131,7 +131,7 @@ public void threadLocalCopyTest() { ExecutorService executor = Executors.newSingleThreadExecutor(); AtomicReference ex = new AtomicReference<>(); ThreadLocalFury threadLocalFury = - builder().withCodegen(false).withCopyRefTracking(true).buildThreadLocalFury(); + builder().withCodegen(false).withRefCopy(true).buildThreadLocalFury(); threadLocalFury.register(BeanA.class); assetEqualsButNotSame(threadLocalFury.copy(beanA)); executor.execute( @@ -151,7 +151,7 @@ public void threadpoolCopyTest() throws InterruptedException { AtomicBoolean flag = new AtomicBoolean(false); ThreadSafeFury threadSafeFury = builder() - .withCopyRefTracking(true) + .withRefCopy(true) .withCodegen(false) .withAsyncCompilation(true) .buildThreadSafeFuryPool(5, 10);