Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ This file provides comprehensive guidance to AI coding agents when working with

While working on Fory, please remember:

- **Do not reserve any legacy code/docs unless requested clearly**.
- **Do Not Keep Dead Weight**: Do not keep legacy, dead, or useless code, tests, or docs unless the user explicitly requests it.
- **Performance First**: Performance is the top priority. Never introduce code that reduces performance without explicit justification.
- **English Only**: Always use English in code, comments, and documentation.
- **Meaningful Comments**: Only add comments when the code's behavior is difficult to understand or when documenting complex algorithms.
- **Focused Testing**: Only add tests that verify internal behaviors or fix specific bugs; don't create unnecessary tests unless requested.
- **No Cleanup-Sentinel Tests**: Do not add standalone tests that only assert deleted APIs, removed fields, or cleanup-only surface constraints; prefer behavior tests in existing focused suites.
- **Git-Tracked Files**: When reading code, skip all files not tracked by git by default unless generated by yourself.
- **Cross-Language Consistency**: Maintain consistency across language implementations while respecting language-specific idioms.
- **No Checked Exceptions in New Code**: Do not introduce checked exceptions in new APIs or newly added code paths; prefer unchecked propagation or explicit result/state handling.
- **Explicit Runtime Context Ownership**: Do not use `ThreadLocal`/ambient runtime context patterns in Java runtime code. `WriteContext`/`ReadContext`/`CopyContext` state must stay explicit, generated serializers must not retain context fields, and `Fory` should stay a root-operation facade rather than accumulating serializer/runtime convenience state.
- **Avoid Reflection on Fixed Bootstrap Paths**: When a serializer class and constructor shape are known at the call site, prefer direct constructor lambdas or direct instantiation over reflective `Serializers.newSerializer(...)`; keep reflection for dynamic/general construction paths only.
- **GraalVM support using fory codegen**: For GraalVM, use `fory codegen` to generate the serializer when building a native image. Do not use GraalVM reflect-related configuration unless for JDK `proxy`.
- **Xlang Type System**: Java `native mode(xlang=false)` shares same type systems between type id from `Types.BOOL~Types.STRING` with `xlang mode(xlang=true)`, but for other types, java `native mode` has different type ids.
- **Remote git repository**: `git@github.com:apache/fory.git` is remote repository, do not use other remote repository when you want to check code under `main` branch, **`apache/main`** is the only target main branch instead of `origin/main`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class NewJava11StringSuite {
private static String stubStr = new String(new char[] {Character.MAX_VALUE, Character.MIN_VALUE});
private static Fory fory =
Fory.builder().withStringCompressed(true).requireClassRegistration(false).build();
private static StringSerializer stringSerializer = new StringSerializer(fory);
private static StringSerializer stringSerializer = new StringSerializer(fory.getConfig());
private static MemoryBuffer buffer = MemoryBuffer.newHeapBuffer(512);

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.apache.fory.ThreadSafeFory;
import org.apache.fory.config.CompatibleMode;
import org.apache.fory.config.Language;
import org.apache.fory.logging.Logger;
import org.apache.fory.logging.LoggerFactory;
import org.openjdk.jmh.Main;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
Expand All @@ -42,9 +40,7 @@
@CompilerControl(value = CompilerControl.Mode.INLINE)
@State(Scope.Benchmark)
@OutputTimeUnit(java.util.concurrent.TimeUnit.MILLISECONDS)
public class ThreadPoolForySuite {

private static final Logger LOG = LoggerFactory.getLogger(ThreadPoolForySuite.class);
public class ThreadSafeForyPoolSuite {

private ThreadSafeFory fory =
Fory.builder()
Expand Down Expand Up @@ -83,7 +79,7 @@ public void tearDown() {}
public static void main(String[] args) throws IOException {
if (args.length == 0) {
String commandLine =
"org.apache.fory.*ObjectPoolBenchmark.* -f 1 -wi 0 -i 5 -w 2s -r 2s -rf csv";
"org.apache.fory.*ThreadSafeForyPoolSuite.* -f 1 -wi 0 -i 5 -w 2s -r 2s -rf csv";
System.out.println(commandLine);
args = commandLine.split(" ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Object fory_deserialize_compatible(ForyState.ForyCompatibleState state) {
@Benchmark
public Object forymetashared_deserialize_compatible(ForyState.ForyMetaSharedState state) {
state.buffer.readerIndex(0);
state.fory.getSerializationContext().setMetaContext(state.readerMetaContext);
state.fory.setMetaContext(state.readerMetaContext);
return state.fory.deserialize(state.buffer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Object fory_serialize_compatible(ForyState.ForyCompatibleState state) {
@Benchmark
public Object forymetashared_serialize_compatible(ForyState.ForyMetaSharedState state) {
state.buffer.writerIndex(0);
state.fory.getSerializationContext().setMetaContext(state.writerMetaContext);
state.fory.setMetaContext(state.writerMetaContext);
state.fory.serialize(state.buffer, state.object);
return state.buffer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
import org.apache.fory.config.CompatibleMode;
import org.apache.fory.config.ForyBuilder;
import org.apache.fory.config.Language;
import org.apache.fory.context.MetaContext;
import org.apache.fory.logging.Logger;
import org.apache.fory.logging.LoggerFactory;
import org.apache.fory.memory.MemoryBuffer;
import org.apache.fory.memory.MemoryUtils;
import org.apache.fory.resolver.MetaContext;
import org.apache.fory.util.Preconditions;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.CompilerControl;
Expand Down
2 changes: 1 addition & 1 deletion compiler/fory_compiler/generators/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ def generate_union_registration(
class_ref = f"{parent_path}.{union.name}" if parent_path else union.name
type_name = union.name
serializer_ref = (
f"new org.apache.fory.serializer.UnionSerializer(fory, {class_ref}.class)"
f"new org.apache.fory.serializer.UnionSerializer(resolver, {class_ref}.class)"
)

if self.should_register_by_id(union):
Expand Down
Loading
Loading