Skip to content
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

Merged

Conversation

chaokunyang
Copy link
Collaborator

@chaokunyang chaokunyang commented Sep 24, 2023

What do these changes do?

Optimize collection serialization protocol by homogenous information in elements:

  • All elements are not null in most cases
  • All elements are same type in most cases

Benchmark

Test data

List<Integer> list1 = new ArrayList<>(1024);
for (int i = 0; i < 1024; i++) {
  list1.add(i % 255);
}

Speed Optimization:

Before this pr:

Benchmark                              Mode  Cnt      Score       Error  Units
CollectionSuite.deserializeArrayList  thrpt   15  94166.362 ± 12655.140  ops/s
CollectionSuite.serializeArrayList    thrpt   15  85634.398 ±  5241.531  ops/s

After this PR:

Benchmark                              Mode  Cnt       Score       Error  Units
CollectionSuite.deserializeArrayList  thrpt   15  146915.959 ± 10036.130  ops/s
CollectionSuite.serializeArrayList    thrpt   15  132363.925 ± 10012.966  ops/s

1.5X speed up!

Space Optimization

Before this pr: 8199 bytes
After this PR: 4107 bytes

2X space saving!

Related issue number

Closes #927

Check code requirements

  • tests added / passed (if needed)
  • Ensure all linting tests pass, see here for how to run them

@chaokunyang chaokunyang changed the title [Java] Optimize collection serialization protocol [Java] Optimize collection serialization protocol by homogenization Oct 2, 2023
chaokunyang and others added 20 commits October 2, 2023 22:42
* 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>
* 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
@chaokunyang
Copy link
Collaborator Author

chaokunyang commented Oct 3, 2023

With some minor change on io.fury.serializer.UnexistedClassSerializersTest#testDeserializeUnexistedNewFury, the jvm crash still persists, now crash test is UnexistedClassSerializersTest#testDeserializeUnexisted:

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 disable generated test class cache on io.fury.serializer.UnexistedClassSerializersTest#testDeserializeUnexistedNewFury. testDeserializeUnexisted and testDeserializeUnexistedNewFury are similar.

@chaokunyang chaokunyang force-pushed the optimize_collection_serialization branch 8 times, most recently from 95cb69b to da80783 Compare October 3, 2023 15:49
@chaokunyang
Copy link
Collaborator Author

JDK11/17 strange crash:

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `/usr/lib/jvm/temurin-11-jdk-amd64/bin/java -jar /home/runner/work/fury/fury/jav'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=139805163779648) at ./nptl/pthread_kill.c:44
44      ./nptl/pthread_kill.c: No such file or directory.
[Current thread is 1 (Thread 0x7f26ed1ff640 (LWP 7256))]
(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=139805163779648) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=139805163779648) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=139805163779648, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007f271b242476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007f271b2287f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x00007f271a871f35 in os::abort(bool, void*, void const*) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#6  0x00007f271ab4d747 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  0x00007f271ab4e36b 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  0x00007f271ab4e39e 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  0x00007f271ab4f32c in crash_handler(int, siginfo*, void*) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#10 <signal handler called>
#11 0x00007f271a3b2710 in G1CollectedHeap::is_in(void const*) const () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#12 0x00007f271a86b6ee in os::print_location(outputStream*, long, bool) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#13 0x00007f271a87ed3b in os::print_register_info(outputStream*, void const*) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#14 0x00007f271ab4ca80 in VMError::report(outputStream*, bool) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#15 0x00007f271ab4d62a 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
#16 0x00007f271ab4e36b 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
#17 0x00007f271ab4e39e in VMError::report_and_die(Thread*, unsigned int, unsigned char*, void*, void*) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#18 0x00007f271a87e038 in JVM_handle_linux_signal () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#19 0x00007f271a86f968 in signalHandler(int, siginfo*, void*) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#20 <signal handler called>
#21 0x00007f271a3fb844 in G1ParScanThreadState::copy_to_survivor_space(InCSetState, oopDesc*, markOopDesc*) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#22 0x00007f271a3f8c70 in G1ParScanThreadState::trim_queue_partially() () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#23 0x00007f271a588626 in JNIHandleBlock::oops_do(OopClosure*) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#24 0x00007f271aad539e in JavaThread::oops_do(OopClosure*, CodeBlobClosure*) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#25 0x00007f271aada950 in Threads::possibly_parallel_oops_do(bool, OopClosure*, CodeBlobClosure*) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#26 0x00007f271a416e6d in G1RootProcessor::process_java_roots(G1RootClosures*, G1GCPhaseTimes*, unsigned int) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#27 0x00007f271a417518 in G1RootProcessor::evacuate_roots(G1ParScanThreadState*, unsigned int) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#28 0x00007f271a3c268c in G1ParTask::work(unsigned int) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#29 0x00007f271ab79e5d in GangWorker::loop() () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#30 0x00007f271aadc6bf in Thread::call_run() () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#31 0x00007f271a87ad06 in thread_native_entry(Thread*) () from /usr/lib/jvm/temurin-11-jdk-amd64/lib/server/libjvm.so
#32 0x00007f271b294b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#33 0x00007f271b326a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

image

Signal:

eu-readelf --notes  /var/lib/apport/coredump/core._usr_lib_jvm_temurin-8-jdk-amd64_jre_bin_java.1001.1e9da1dc-f566-4641-afe9-d8cdb53fa718.3185.44313  | head

Note segment of 65364 bytes at offset 0x3728:
  Owner          Data size  Type
  CORE                 336  PRSTATUS
    info.si_signo: 6, info.si_code: 0, info.si_errno: 0, cursig: 6
    sigpend: <>
    sighold: ~<6,9,11,19,32-33>
    pid: 3187, ppid: 3183, pgrp: 3142, sid: 2505
    utime: 0.044000, stime: 0.016000, cutime: 0.000000, cstime: 0.000000
    orig_rax: 234, fpvalid: 1

The crash isn't a bug in jvm, but out-of-band writing using Unsafe in fury, fixed in #937

@JackieTien97
Copy link

Hi, I'm curious about how you finaly locate this bug is caused by the reason mentioned in this pr , rather than jdk's own bug?

Recently, in our project, we also encountered the similar problem and have no idea where to find the root cause.

We only have the jvm crash file without any core dump.

@chaokunyang
Copy link
Collaborator Author

It's a long tough way to locate this bug. It took me a whole night.
One of the good thing is that the crash is reproduceable. So I can debug line by line, biselect to narrow the bug scope. Add system.gc to possible lines. And I found the line to crash jvm. The later work will be much easier. I just need to check why it cause crash. Finally I found I write heap memory outofbound.

@JackieTien97
Copy link

Aha, thanks a lot, unfortunately, we don't have a way to reproduce the bug stably... which makes this bug more tough...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Java][Protocol] Collection serialization protocol by homogenization info
3 participants