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

nullpointerexception in GC #3753

Open
ddyer0 opened this issue Oct 26, 2023 · 3 comments
Open

nullpointerexception in GC #3753

ddyer0 opened this issue Oct 26, 2023 · 3 comments
Assignees

Comments

@ddyer0
Copy link
Contributor

ddyer0 commented Oct 26, 2023

I was debugging under xcode, and got a nullpointer exception in the GC thread at the indicated point.

JAVA_BOOLEAN com_codename1_impl_ios_IOSNative_isSocketConnected___long(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject, JAVA_LONG socket) {
POOL_BEGIN();
SocketImpl* impl = (BRIDGE_CAST SocketImpl*)((void *)socket);
JAVA_BOOLEAN b = [impl isConnected]; // HERE
POOL_END();
return b;
}

stack trace
Thread 3

#0 0x00000001136091a2 in virtual_java_lang_Long_longValue___R_long at /Users/admin/Desktop/boardspace-7.2/dist/Develop-src/java_lang_Long.m:506
#1 0x00000001114307d6 in com_codename1_impl_ios_IOSImplementation_isSocketConnected___java_lang_Object_R_boolean at /Users/admin/Desktop/boardspace-7.2/dist/Develop-src/com_codename1_impl_ios_IOSImplementation.m:14456
#2 0x0000000110f75a02 in virtual_com_codename1_impl_CodenameOneImplementation_isSocketConnected___java_lang_Object_R_boolean at /Users/admin/Desktop/boardspace-7.2/dist/Develop-src/com_codename1_impl_CodenameOneImplementation.m:16156
#3 0x0000000113d554fe in com_codename1_io_Socket_SocketInputStream_close__ at /Users/admin/Desktop/boardspace-7.2/dist/Develop-src/com_codename1_io_Socket_SocketInputStream.m:116
#4 0x0000000113d578c7 in virtual_com_codename1_io_Socket_SocketInputStream_close__ at /Users/admin/Desktop/boardspace-7.2/dist/Develop-src/com_codename1_io_Socket_SocketInputStream.m:462
#5 0x0000000113d54ea3 in com_codename1_io_Socket_SocketInputStream_finalize__ at /Users/admin/Desktop/boardspace-7.2/dist/Develop-src/com_codename1_io_Socket_SocketInputStream.m:398
#6 0x0000000113d54a5d in FINALIZER_com_codename1_io_Socket_SocketInputStream at /Users/admin/Desktop/boardspace-7.2/dist/Develop-src/com_codename1_io_Socket_SocketInputStream.m:59
#7 0x000000010f699258 in freeAndFinalize at /Users/admin/Desktop/boardspace-7.2/dist/Develop-src/cn1_globals.m:430
#8 0x000000010f699d38 in codenameOneGCSweep at /Users/admin/Desktop/boardspace-7.2/dist/Develop-src/cn1_globals.m:830
#9 0x00000001100fc817 in java_lang_System_gcMarkSweep
at /Users/admin/Desktop/boardspace-7.2/dist/Develop-src/nativeMethods.m:1116
#10 0x0000000111449d67 in java_lang_System_access$200__ at /Users/admin/Desktop/boardspace-7.2/dist/Develop-src/java_lang_System.m:342
#11 0x000000010f794556 in java_lang_System_1_run__ at /Users/admin/Desktop/boardspace-7.2/dist/Develop-src/java_lang_System_1.m:120
#12 0x0000000110add2dc in virtual_java_lang_Runnable_run__ at /Users/admin/Desktop/boardspace-7.2/dist/Develop-src/java_lang_Runnable.m:60
#13 0x000000011030528d in java_lang_Thread_runImpl___long at /Users/admin/Desktop/boardspace-7.2/dist/Develop-src/java_lang_Thread.m:248
#14 0x00000001100fcde0 in threadRunner at /Users/admin/Desktop/boardspace-7.2/dist/Develop-src/nativeMethods.m:1337

All of the implementation seems to assume that "socket" has been allocated, but that is clearly
not the case.

@shai-almog shai-almog self-assigned this Oct 27, 2023
@shai-almog
Copy link
Collaborator

Might be related to my work on #3726

@ddyer0
Copy link
Contributor Author

ddyer0 commented Oct 27, 2023

i agree. if the finalizer is new that would explain how it was unnoticed. I'm still tracking the issue, but I haven't seen
any directly bad behavior that corresponds to this other than in the debugger.

@ddyer0
Copy link
Contributor Author

ddyer0 commented Oct 27, 2023

The issue I’m tracking is compatible with the hypotheses that this npe leaves the gc disabled, and subsequently any process that becomes blocked for gc is effectively dead.

Additional evidence: The error I'm tracking first occurred in my logs in a build I made on Sep 15

I hacked my use of sockets to prevent my SocketInputStream and SocketOutputStream instances from being
garbage collected, and that seems to have fixed it.

I don't have a good model how this could have wedged the garbage collector without causing a more
immediate problem - do you ? - It seem to me that there should have been some immediate effect rather
than leave it to victimize some random process sometime in the future in this mysterious way.

shai-almog added a commit that referenced this issue Oct 28, 2023
Ideally should fix both #3726 and the regression in #3753
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

No branches or pull requests

2 participants