-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Java] Optimize collection serialization protocol by homogenization #923
[Java] Optimize collection serialization protocol by homogenization #923
Conversation
* Optimize StringBuilder/StringBuffer serialization * try to optimize StringBuilder * first to Check code Style * hidden * hidden * bug fix and check code style * delete excess code and add buffers to try testing * fix * try to fix problem * fix function * code fix * code fix again * Update java/fury-core/src/main/java/io/fury/serializer/Serializers.java commit Co-authored-by: Shawn <shawn.ck.yang@gmail.com> * Update java/fury-core/src/main/java/io/fury/serializer/Serializers.java commit Co-authored-by: Shawn <shawn.ck.yang@gmail.com> --------- Co-authored-by: pankoli <pankoli@tencent.com> Co-authored-by: Shawn <shawn.ck.yang@gmail.com>
add basic type java format doc
* speed test codegen speed by avoid duplicate codegen * fix cache * fix cllass gc * use a standalone lock for every key * refine gc trigger * skip cache for furyGC tests * fix gc tests * lint code
With some minor change on Crash java stack: "main" #1 prio=5 tid=0x00007f3ce8027000 nid=0x149e runnable [0x00007f3cef7fa000]
java.lang.Thread.State: RUNNABLE
JavaThread state: _thread_blocked
- java.lang.reflect.Method.copy() @bci=17, line=160 (Compiled frame)
- java.lang.reflect.ReflectAccess.copyMethod(java.lang.reflect.Method) @bci=1, line=144 (Compiled frame)
- jdk.internal.reflect.ReflectionFactory.copyMethod(java.lang.reflect.Method) @bci=4, line=366 (Compiled frame)
- java.lang.Class.copyMethods(java.lang.reflect.Method[]) @bci=24, line=3391 (Compiled frame)
- java.lang.Class.getDeclaredMethods() @bci=23, line=2309 (Compiled frame)
- io.fury.util.ReflectionUtils.findMethods(java.lang.Class, java.lang.String) @bci=103, line=162 (Compiled frame)
- io.fury.util.ReflectionUtils.hasException(java.lang.Class, java.lang.String) @bci=2, line=212 (Compiled frame)
- io.fury.codegen.Expression$Invoke.<init>(io.fury.codegen.Expression, java.lang.String, java.lang.String, com.google.common.reflect.TypeToken, boolean, io.fury.codegen.Expression[]) @bci=18, line=841 (Compiled frame)
- io.fury.codegen.Expression$Invoke.<init>(io.fury.codegen.Expression, java.lang.String, com.google.common.reflect.TypeToken, boolean, io.fury.codegen.Expression[]) @bci=10, line=825 (Compiled frame)
- io.fury.codegen.Expression$Invoke.inlineInvoke(io.fury.codegen.Expression, java.lang.String, com.google.common.reflect.TypeToken, io.fury.codegen.Expression[]) @bci=9, line=864 (Compiled frame)
- io.fury.builder.BaseObjectCodecBuilder.addClassInfoField(java.lang.Class) @bci=224, line=563 (Compiled frame)
- io.fury.builder.BaseObjectCodecBuilder.writeForNotNullNonFinalObject(io.fury.codegen.Expression, io.fury.codegen.Expression, com.google.common.reflect.TypeToken) @bci=39, line=439 (Interpreted frame)
- io.fury.builder.BaseObjectCodecBuilder.serializeForNotNullObject(io.fury.codegen.Expression, io.fury.codegen.Expression, com.google.common.reflect.TypeToken, io.fury.codegen.Expression) @bci=80, line=429 (Compiled frame)
- io.fury.builder.BaseObjectCodecBuilder.serializeForNotNull(io.fury.codegen.Expression, io.fury.codegen.Expression, com.google.common.reflect.TypeToken, io.fury.codegen.Expression, boolean) @bci=420, line=398 (Compiled frame)
- io.fury.builder.BaseObjectCodecBuilder.serializeFor(io.fury.codegen.Expression, io.fury.codegen.Expression, com.google.common.reflect.TypeToken, io.fury.codegen.Expression, boolean) @bci=47, line=314 (Compiled frame)
- io.fury.builder.BaseObjectCodecBuilder.serializeFor(io.fury.codegen.Expression, io.fury.codegen.Expression, com.google.common.reflect.TypeToken, boolean) @bci=7, line=300 (Compiled frame)
- io.fury.builder.BaseObjectCodecBuilder.serializeFor(io.fury.codegen.Expression, io.fury.codegen.Expression, com.google.common.reflect.TypeToken) @bci=5, line=288 (Compiled frame)
- io.fury.builder.ObjectCodecBuilder.lambda$serializeGroup$9f8a61a4$1(java.util.List, io.fury.codegen.Expression, io.fury.codegen.Expression) @bci=95, line=187 (Compiled frame)
- io.fury.builder.ObjectCodecBuilder$$Lambda$285.get() @bci=16 (Compiled frame)
- io.fury.codegen.ExpressionOptimizer.invokeGenerated(io.fury.codegen.CodegenContext, io.fury.util.function.SerializableSupplier, java.lang.String) @bci=15, line=48 (Compiled frame)
- io.fury.builder.ObjectCodecOptimizer.invokeGenerated(io.fury.util.function.SerializableSupplier, java.lang.String) @bci=6, line=134 (Compiled frame)
- io.fury.builder.ObjectCodecBuilder.serializeGroup(java.util.List, io.fury.codegen.Expression, io.fury.codegen.Expression, boolean) @bci=35, line=196 (Compiled frame)
- io.fury.builder.ObjectCodecBuilder.buildEncodeExpression() @bci=234, line=158 (Interpreted frame)
- io.fury.builder.BaseObjectCodecBuilder.genCode() @bci=84, line=202 (Interpreted frame)
- io.fury.builder.CodecUtils$$Lambda$279.get() @bci=4 (Interpreted frame)
- io.fury.codegen.CompileUnit.getCode() @bci=24, line=54 (Compiled frame)
- io.fury.codegen.JaninoUtils.toBytecode(java.lang.ClassLoader, java.lang.String, io.fury.codegen.CompileUnit[]) @bci=83, line=73 (Interpreted frame)
- io.fury.codegen.JaninoUtils.toBytecode(java.lang.ClassLoader, io.fury.codegen.CompileUnit[]) @bci=5, line=65 (Compiled frame)
- io.fury.codegen.CodeGenerator.compile(java.util.List, io.fury.codegen.CompileCallback) @bci=169, line=141 (Compiled frame)
- io.fury.builder.CodecUtils.loadOrGenCodecClass(java.lang.Class, io.fury.Fury, io.fury.builder.BaseObjectCodecBuilder) @bci=108, line=89 (Interpreted frame)
- io.fury.builder.CodecUtils.loadOrGenObjectCodecClass(java.lang.Class, io.fury.Fury) @bci=18, line=40 (Interpreted frame)
- io.fury.serializer.CodegenSerializer.loadCodegenSerializer(io.fury.Fury, java.lang.Class) @bci=2, line=43 (Interpreted frame)
- io.fury.resolver.ClassResolver.lambda$getObjectSerializerClass$4(boolean, java.lang.Class) @bci=9, line=906 (Interpreted frame)
- io.fury.resolver.ClassResolver$$Lambda$275.call() @bci=12 (Interpreted frame)
- io.fury.builder.JITContext.registerSerializerJITCallback(java.util.concurrent.Callable, java.util.concurrent.Callable, io.fury.builder.JITContext$SerializerJITCallback) @bci=117, line=132 (Compiled frame)
- io.fury.resolver.ClassResolver.getObjectSerializerClass(java.lang.Class, boolean, boolean, io.fury.builder.JITContext$SerializerJITCallback) @bci=149, line=902 (Interpreted frame)
- io.fury.resolver.ClassResolver.getSerializerClass(java.lang.Class, boolean) @bci=496, line=846 (Compiled frame)
- io.fury.resolver.ClassResolver.getSerializerClass(java.lang.Class) @bci=29, line=754 (Compiled frame)
- io.fury.resolver.ClassResolver.createSerializer(java.lang.Class) @bci=129, line=1103 (Compiled frame)
- io.fury.resolver.ClassResolver.getOrUpdateClassInfo(java.lang.Class) @bci=40, line=1045 (Compiled frame)
- io.fury.Fury.writeRef(io.fury.memory.MemoryBuffer, java.lang.Object) @bci=22, line=284 (Compiled frame)
- io.fury.Fury.serialize(io.fury.memory.MemoryBuffer, java.lang.Object, io.fury.serializer.BufferCallback) @bci=171, line=232 (Compiled frame)
- io.fury.Fury.serialize(java.lang.Object) @bci=15, line=184 (Compiled frame)
- io.fury.serializer.UnexistedClassSerializersTest.testDeserializeUnexisted(boolean, boolean, boolean, boolean, boolean) @bci=202, line=203 (Interpreted frame) Jvm still crash at same place: #2 __GI___pthread_kill (threadid=139899661448768, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3 0x00007f3cef442476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4 0x00007f3cef4287f3 in __GI_abort () at ./stdlib/abort.c:79
#5 0x00007f3ceea71f35 in os::abort(bool, void*, void const*) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#6 0x00007f3ceed4d747 in VMError::report_and_die(int, char const*, char const*, __va_list_tag*, Thread*, unsigned char*, void*, void*, char const*, int, unsigned long) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#7 0x00007f3ceed4e36b in VMError::report_and_die(Thread*, unsigned int, unsigned char*, void*, void*, char const*, ...) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#8 0x00007f3ceed4e39e in VMError::report_and_die(Thread*, unsigned int, unsigned char*, void*, void*) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#9 0x00007f3ceea7e038 in JVM_handle_linux_signal () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#10 0x00007f3ceea6f968 in signalHandler(int, siginfo*, void*) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#11 <signal handler called>
#12 0x00007f3cee5fb844 in G1ParScanThreadState::copy_to_survivor_space(InCSetState, oopDesc*, markOopDesc*) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#13 0x00007f3cee5fc668 in G1ParScanThreadState::trim_queue() () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#14 0x00007f3cee5bd096 in G1ParEvacuateFollowersClosure::do_void() () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#15 0x00007f3cee5c270e in G1ParTask::work(unsigned int) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#16 0x00007f3ceed79e5d in GangWorker::loop() () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#17 0x00007f3ceecdc6bf in Thread::call_run() () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#18 0x00007f3ceea7ad06 in thread_native_entry(Thread*) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#19 0x00007f3cef494b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#20 0x00007f3cef526a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81 Duplicate run java stack can crash at different place: "main" #1 prio=5 tid=0x00007f8e40027000 nid=0x23fc waiting on condition [0x00007f8e467f9000]
java.lang.Thread.State: RUNNABLE
JavaThread state: _thread_blocked
- org.codehaus.janino.Parser.parseQualifiedIdentifier() @bci=0, line=325 (Compiled frame)
- org.codehaus.janino.Parser.parsePrimary() @bci=281, line=2893 (Compiled frame)
- org.codehaus.janino.Parser.parseUnaryExpression() @bci=113, line=2794 (Compiled frame)
- org.codehaus.janino.Parser.parseMultiplicativeExpression() @bci=1, line=2753 (Compiled frame)
- org.codehaus.janino.Parser.parseAdditiveExpression() @bci=1, line=2732 (Compiled frame)
- org.codehaus.janino.Parser.parseShiftExpression() @bci=1, line=2711 (Compiled frame)
- org.codehaus.janino.Parser.parseRelationalExpression() @bci=1, line=2635 (Compiled frame)
- org.codehaus.janino.Parser.parseEqualityExpression() @bci=1, line=2609 (Compiled frame)
- org.codehaus.janino.Parser.parseAndExpression() @bci=1, line=2588 (Compiled frame)
- org.codehaus.janino.Parser.parseExclusiveOrExpression() @bci=1, line=2567 (Compiled frame)
- org.codehaus.janino.Parser.parseInclusiveOrExpression() @bci=1, line=2546 (Compiled frame)
- org.codehaus.janino.Parser.parseConditionalAndExpression() @bci=1, line=2525 (Compiled frame)
- org.codehaus.janino.Parser.parseConditionalOrExpression() @bci=1, line=2504 (Compiled frame)
- org.codehaus.janino.Parser.parseConditionalExpression() @bci=1, line=2485 (Compiled frame)
- org.codehaus.janino.Parser.parseAssignmentExpression() @bci=1, line=2464 (Compiled frame)
- org.codehaus.janino.Parser.parseAssignmentExpression() @bci=115, line=2471 (Compiled frame)
- org.codehaus.janino.Parser.parseExpression() @bci=1, line=2449 (Compiled frame)
- org.codehaus.janino.Parser.parseBlockStatement() @bci=254, line=1647 (Compiled frame)
- org.codehaus.janino.Parser.parseBlockStatements() @bci=38, line=1580 (Interpreted frame)
- org.codehaus.janino.Parser.parseBlock() @bci=20, line=1567 (Interpreted frame)
- org.codehaus.janino.Parser.parseStatement() @bci=35, line=1763 (Interpreted frame)
- org.codehaus.janino.Parser.parseIfStatement() @bci=33, line=1812 (Interpreted frame)
- org.codehaus.janino.Parser.parseStatement() @bci=52, line=1764 (Interpreted frame)
- org.codehaus.janino.Parser.parseBlockStatement() @bci=134, line=1615 (Compiled frame)
- org.codehaus.janino.Parser.parseBlockStatements() @bci=38, line=1580 (Interpreted frame)
- org.codehaus.janino.Parser.parseMethodDeclarationRest(java.lang.String, org.codehaus.janino.Java$Modifiers, org.codehaus.janino.Java$TypeParameter[], org.codehaus.janino.Java$Type, java.lang.String, boolean) @bci=146, line=1417 (Interpreted frame)
- org.codehaus.janino.Parser.parseClassBodyDeclaration(org.codehaus.janino.Java$AbstractClassDeclaration) @bci=149, line=838 (Interpreted frame)
- org.codehaus.janino.Parser.parseClassBody(org.codehaus.janino.Java$AbstractClassDeclaration) @bci=18, line=736 (Interpreted frame)
- org.codehaus.janino.Parser.parseClassDeclarationRest(java.lang.String, org.codehaus.janino.Java$Modifiers, org.codehaus.janino.Parser$ClassDeclarationContext) @bci=191, line=642 (Interpreted frame)
- org.codehaus.janino.Parser.parsePackageMemberTypeDeclarationRest(java.lang.String, org.codehaus.janino.Java$Modifiers) @bci=98, line=370 (Interpreted frame)
- org.codehaus.janino.Parser.parseCompilationUnit() @bci=210, line=241 (Interpreted frame)
- org.codehaus.janino.Compiler.parseCompilationUnit(java.lang.String, java.io.InputStream, java.lang.String) @bci=65, line=580 (Interpreted frame)
- org.codehaus.janino.Compiler.compile(org.codehaus.janino.util.resource.Resource[]) @bci=79, line=501 (Interpreted frame)
- io.fury.codegen.JaninoUtils.toBytecode(java.lang.ClassLoader, java.lang.String, io.fury.codegen.CompileUnit[]) @bci=312, line=107 (Interpreted frame)
- io.fury.codegen.JaninoUtils.toBytecode(java.lang.ClassLoader, io.fury.codegen.CompileUnit[]) @bci=5, line=65 (Interpreted frame)
- io.fury.codegen.CodeGenerator.compile(java.util.List, io.fury.codegen.CompileCallback) @bci=169, line=141 (Interpreted frame)
- io.fury.builder.CodecUtils.loadOrGenCodecClass(java.lang.Class, io.fury.Fury, io.fury.builder.BaseObjectCodecBuilder) @bci=108, line=89 (Interpreted frame)
- io.fury.builder.CodecUtils.loadOrGenMetaSharedCodecClass(io.fury.Fury, java.lang.Class, io.fury.type.ClassDef) @bci=22, line=48 (Interpreted frame)
- io.fury.resolver.ClassResolver.lambda$getMetaSharedClassInfo$9(java.lang.Class, io.fury.type.ClassDef) @bci=6, line=1305 (Interpreted frame)
- io.fury.resolver.ClassResolver$$Lambda$451.call() @bci=12 (Interpreted frame)
- io.fury.builder.JITContext.registerSerializerJITCallback(java.util.concurrent.Callable, java.util.concurrent.Callable, io.fury.builder.JITContext$SerializerJITCallback) @bci=117, line=132 (Interpreted frame)
- io.fury.resolver.ClassResolver.getMetaSharedClassInfo(io.fury.type.ClassDef, java.lang.Class) @bci=115, line=1303 (Interpreted frame)
- io.fury.resolver.ClassResolver.readClassInfoWithMetaShare(io.fury.memory.MemoryBuffer, io.fury.resolver.MetaContext) @bci=172, line=1271 (Interpreted frame)
- io.fury.resolver.ClassResolver.readAndUpdateClassInfoCache(io.fury.memory.MemoryBuffer) @bci=26, line=1471 (Interpreted frame)
- io.fury.Fury.readRef(io.fury.memory.MemoryBuffer) @bci=25, line=743 (Interpreted frame)
- io.fury.Fury.deserialize(io.fury.memory.MemoryBuffer, java.lang.Iterable) @bci=196, line=687 (Interpreted frame)
- io.fury.Fury.deserialize(byte[]) @bci=6, line=619 (Interpreted frame)
- io.fury.serializer.UnexistedClassSerializersTest.testDeserializeUnexisted(boolean, boolean, boolean, boolean, boolean) @bci=269, line=212 (Interpreted frame) This can be workaround by the same change as |
95cb69b
to
da80783
Compare
da80783
to
1ceb201
Compare
The crash isn't a bug in jvm, but out-of-band writing using Unsafe in fury, fixed in #937 |
It's a long tough way to locate this bug. It took me a whole night. |
Aha, thanks a lot, unfortunately, we don't have a way to reproduce the bug stably... which makes this bug more tough... |
What do these changes do?
Optimize collection serialization protocol by homogenous information in elements:
Benchmark
Test data
Speed Optimization:
Before this pr:
After this PR:
1.5X speed up!
Space Optimization
Before this pr:
8199
bytesAfter this PR:
4107
bytes2X space saving!
Related issue number
Closes #927
Check code requirements