creating workflow for mirror::String compression
All-ASCII String characters are stored in 8-bit blocks
instead of 16-bit. The compression has not taken place, but all
workflow are in the code already (changing kUseStringCompression in
string.h file to TRUE will enable the feature)
Notes: Feature works on interpreter only without optimizing
Test art: m ART_TEST_INTERPRETER=true ART_TEST_OPTIMIZING=false
test-art-host
Also tested with String tests from libcore/:
1. libcore.java.lang.StringTest
2. libcore.java.lang.StringBufferTest
3. libcore.java.lang.StringBuilderTest
4. libcore.java.lang.OldStringTest
5. libcore.java.lang.OldStringBufferTest
Memory improvement is 33% (from 6.03% to 4.03%, total String memory
from all apps per total memory of all apps) measured on Angler
with Hprof tools
Bug: 31040547
Change-Id: I9cc92c265ebf1305fc06b5fc33efd83797660cce
diff --git a/runtime/jni_internal_test.cc b/runtime/jni_internal_test.cc
index 04ba8df..6495474 100644
--- a/runtime/jni_internal_test.cc
+++ b/runtime/jni_internal_test.cc
@@ -880,8 +880,15 @@
ASSERT_NE(fid2, nullptr);
// Make sure we can actually use it.
jstring s = env_->NewStringUTF("poop");
- ASSERT_EQ(4, env_->GetIntField(s, fid2));
-
+ if (mirror::kUseStringCompression) {
+ // Negative because s is compressed (first bit is 1)
+ ASSERT_EQ(-2147483644, env_->GetIntField(s, fid2));
+ // Create incompressible string
+ jstring s_16 = env_->NewStringUTF("\u0444\u0444");
+ ASSERT_EQ(2, env_->GetIntField(s_16, fid2));
+ } else {
+ ASSERT_EQ(4, env_->GetIntField(s, fid2));
+ }
// Bad arguments.
GetFromReflectedField_ToReflectedFieldBadArgumentTest(false);
GetFromReflectedField_ToReflectedFieldBadArgumentTest(true);
@@ -1632,13 +1639,28 @@
jboolean is_copy = JNI_TRUE;
chars = env_->GetStringCritical(s, &is_copy);
- EXPECT_EQ(JNI_FALSE, is_copy);
+ if (mirror::kUseStringCompression) {
+ // is_copy has to be JNI_TRUE because "hello" is all-ASCII
+ EXPECT_EQ(JNI_TRUE, is_copy);
+ } else {
+ EXPECT_EQ(JNI_FALSE, is_copy);
+ }
EXPECT_EQ(expected[0], chars[0]);
EXPECT_EQ(expected[1], chars[1]);
EXPECT_EQ(expected[2], chars[2]);
EXPECT_EQ(expected[3], chars[3]);
EXPECT_EQ(expected[4], chars[4]);
env_->ReleaseStringCritical(s, chars);
+
+ if (mirror::kUseStringCompression) {
+ // is_copy has to be JNI_FALSE because "\xed\xa0\x81\xed\xb0\x80" is incompressible
+ jboolean is_copy_16 = JNI_TRUE;
+ jstring s_16 = env_->NewStringUTF("\xed\xa0\x81\xed\xb0\x80");
+ chars = env_->GetStringCritical(s_16, &is_copy_16);
+ EXPECT_EQ(2, env_->GetStringLength(s_16));
+ EXPECT_EQ(4, env_->GetStringUTFLength(s_16));
+ env_->ReleaseStringCritical(s_16, chars);
+ }
}
TEST_F(JniInternalTest, GetObjectArrayElement_SetObjectArrayElement) {