-
Notifications
You must be signed in to change notification settings - Fork 114
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
Implement ObjectArena and ArenaRef to solve JNI Global Reference Issue #1176
Conversation
Integration test with FLAKINESS (succeeded after retry)Requested by @cherylEnkidu on commit 2ce5b8d
Add flaky tests to go/fpl-cpp-flake-tracker |
69db5b3
to
8975580
Compare
✅ Integration test succeeded!Requested by @cherylEnkidu on commit 7889019 |
8d98424
to
b599bfa
Compare
|
||
ArenaRef& ArenaRef::operator=(ArenaRef&& other) { | ||
if (this != &other) { | ||
std::swap(key_, other.key_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do the using std::swap
thing here in the move assignment operator, just like you did for the move constructor (#1176 (comment))
@@ -160,6 +172,21 @@ TEST_F(EnvTest, ToString) { | |||
EXPECT_EQ("Foo", result); | |||
} | |||
|
|||
TEST_F(EnvTest, IsInstanceOfChecksValidArenaRef) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Augment the IsInstanceOfChecksValidArenaRef
test to also call IsInstanceOf
with a different class (e.g. java.lang.Integer
) such that it returns false
.
@@ -367,5 +367,12 @@ TEST_F(FieldValueTest, TestIncrementChoosesTheCorrectType) { | |||
// clang-format on | |||
} | |||
|
|||
TEST_F(FieldValueTest, TestArenaRefMinimunLimit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment to TestArenaRefMinimunLimit
to mention the global refs issue that it's checking and include a link to the issue that it's verifying doesn't regress (i.e. firebase/firebase-unity-sdk#569)
HashMap* gArenaRefHashMap = nullptr; | ||
jclass gLongClass = nullptr; | ||
jmethodID gLongConstructor = nullptr; | ||
std::mutex mutex_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Move std::mutex mutex_
to be defined above the variable that it is protecting (i.e. above the definition of gArenaRefHashMap). Although it's not super relevant in this case, you always want to make sure that the mutex outlives the variable(s) that it is protecting.
HashMap* gArenaRefHashMap = nullptr; | ||
jclass gLongClass = nullptr; | ||
jmethodID gLongConstructor = nullptr; | ||
std::mutex mutex_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename mutex_
to match the naming convention of global variables. Also name it to indicate which variable it is protecting. e.g. gArenaRefHashMapMutex
.
jmethodID ctor = | ||
env().GetMethodId(clazz, "<init>", "(Ljava/lang/String;)V"); | ||
|
||
Local<String> message = env().NewStringUtf("Testing throw"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just get rid of these throwException() and clearExceptionOccurred() helper methods.
throwException() can be replaced by
env.Throw(CreateException(env, "Test Exception"));
and clearExceptionOccurred() can be replaced by
env.ExceptionClear();
Admittedly, this leads to a tiny bit of code duplciation between test cases but that's acceptable because, IMO, it improves readabililty of the test cases.
See go/tott/598 about "DAMP" tests rather than the "DRY" principle that is common in non-testing code.
TEST_F(ArenaRefTestAndroid, MoveConstructsFromValid) { | ||
Local<String> string = env().NewStringUtf("hello world"); | ||
|
||
ArenaRef arena_ref2(env(), string); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Rename arena_ref2
and arena_ref3
back to arena_ref1
and arena_ref2
, respectively.
|
||
TEST_F(ArenaRefTestAndroid, ThrowBeforeConstruct) { | ||
Local<String> string = env().NewStringUtf("hello world"); | ||
EXPECT_EQ(string.ToString(env()).size(), 11U); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these checks for the length of the string returned from NewStringUtf()
. You can just assume that this is true. Applies here and elsewhere in this file.
EXPECT_TRUE(env().IsSameObject(arena_ref1.get(env()), string1)); | ||
} | ||
|
||
TEST_F(ArenaRefTestAndroid, ThrowBeforeConstruct) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can you rename the "ThrowBeforeXXX" test names to "XXXWithPendingException" or something like that? I think using the term "with pending exception" more clearly conveys what scenario the test is testing.
clearExceptionOccurred(); | ||
EXPECT_TRUE(env().IsSameObject(arena_ref2.get(env()), string)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test for calling get() with a pending exception.
Description
Testing
Type of Change
Place an
x
the applicable box:Notes
Release Notes
section ofrelease_build_files/readme.md
.