Skip to content

android: Replace env->NewGlobalRef with NoDestructor wrapper#10783

Open
kjyoun wants to merge 5 commits into
youtube:mainfrom
kjyoun:handle-g_j_video_surface
Open

android: Replace env->NewGlobalRef with NoDestructor wrapper#10783
kjyoun wants to merge 5 commits into
youtube:mainfrom
kjyoun:handle-g_j_video_surface

Conversation

@kjyoun
Copy link
Copy Markdown
Contributor

@kjyoun kjyoun commented Jun 5, 2026

  • Refactor starboard/android/shared/video_window.cc to replace direct env->NewGlobalRef call with starboard::NoDestructor<jni_zero::ScopedJavaGlobalRef>.
  • This ensures safe lifecycle management of the global video surface JNI reference and avoids potential shutdown crashes.
  • Add starboard::NoDestructor utility to starboard/common, mirroring base::NoDestructor.
  • Add unit tests for starboard::NoDestructor in no_destructor_test.cc.

Issue: 520007952
Issue: 509619283

- Refactor starboard/android/shared/video_window.cc to replace direct env->NewGlobalRef call with starboard::NoDestructor<jni_zero::ScopedJavaGlobalRef<jobject>>.
- This ensures safe lifecycle management of the global video surface JNI reference and avoids potential shutdown crashes.
- Add starboard::NoDestructor utility to starboard/common, mirroring base::NoDestructor.
- Add unit tests for starboard::NoDestructor in no_destructor_test.cc.

BUG=b/520007952
TAG=agy
CONV=5d7aa66e-ca8b-4eab-bf9f-38fb21320b8c
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

🤖 Gemini Suggested Commit Message


android: Use NoDestructor for JNI video surface

Refactor the Android video window implementation to use a NoDestructor
wrapper around ScopedJavaGlobalRef for the video surface. This ensures
safe lifecycle management of the JNI reference and prevents potential
shutdown crashes associated with static destructors.

This change also introduces the starboard::NoDestructor utility to
starboard/common, mirroring base::NoDestructor, along with unit tests.

Issue: 520007952
Issue: 509619283

💡 Pro Tips for a Better Commit Message:

  1. Influence the Result: Want to change the output? You can write custom prompts or instructions directly in the Pull Request description. The model uses that text to generate the message.
  2. Re-run the Generator: Post a comment with: /generate-commit-message

@kjyoun kjyoun force-pushed the handle-g_j_video_surface branch from 13dd015 to c159a30 Compare June 5, 2026 17:27
@kjyoun
Copy link
Copy Markdown
Contributor Author

kjyoun commented Jun 5, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a NoDestructor<T> utility class to prevent the execution of non-trivial destructors for static and global variables, accompanied by comprehensive unit tests. Additionally, it refactors the global video surface management in video_window.cc to utilize jni_zero::ScopedJavaGlobalRef wrapped in NoDestructor. The review feedback recommends using std::launder in NoDestructor::get() to comply with C++17 strict aliasing rules and prevent undefined behavior. It also suggests simplifying the JNI reference resetting logic in video_window.cc since ScopedJavaGlobalRef::Reset automatically handles releasing the previous reference.

Comment thread starboard/common/no_destructor.h
Comment thread starboard/android/shared/video_window.cc Outdated
@kjyoun kjyoun marked this pull request as ready for review June 5, 2026 17:37
@kjyoun kjyoun requested a review from a team as a code owner June 5, 2026 17:37
@kjyoun kjyoun requested a review from andrewsavage1 June 5, 2026 17:37
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a NoDestructor helper class to starboard/common along with its unit tests, and utilizes it in video_window.cc to manage a global Java reference safely using jni_zero::ScopedJavaGlobalRef. The feedback suggests simplifying the video surface reset logic by removing a redundant null check, as Reset() is safe to call on empty references.

Comment thread starboard/android/shared/video_window.cc Outdated
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.

1 participant