summaryrefslogtreecommitdiff
path: root/compiler/compiled_method_test.cc
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2015-09-11 11:59:18 +0100
committer Vladimir Marko <vmarko@google.com> 2015-10-27 15:13:37 +0000
commit35831e8bfa1c0944d4c978d99c4c5b9577945170 (patch)
treea347ecaf4265a1713c86d528392e162d5edfaebc /compiler/compiled_method_test.cc
parent171b12e8060f63cf900ffc43d6db35125f6b8c83 (diff)
Reduce memory used by CompiledMethods.
Use LengthPrefixedArray<>s instead of SwapVector<>s to store CompiledMethod data and get rid of the unnecessary members of CompiledMethod to reduce dex2oat memory usage. Refactor the deduplication from CompilerDriver to a new class. Use HashSet<> instead of std::set<> for the DedupeSet<> to further decrease the memory usage and improve performance. This reduces the dex2oat memory usage when compiling boot image on Nexus 5 (with Optimizing, -j1) by ~6.75MiB (5%). This also reduces the compile time by ~2.2% (~1.6% dex2oat time; with Optimizing, without -j). Change-Id: I974f1f5e58350de2bf487a2bca3907fa05fb80ea
Diffstat (limited to 'compiler/compiled_method_test.cc')
-rw-r--r--compiler/compiled_method_test.cc120
1 files changed, 120 insertions, 0 deletions
diff --git a/compiler/compiled_method_test.cc b/compiler/compiled_method_test.cc
new file mode 100644
index 0000000000..99ee875da2
--- /dev/null
+++ b/compiler/compiled_method_test.cc
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include "compiled_method.h"
+
+namespace art {
+
+TEST(CompiledMethod, SrcMapElemOperators) {
+ SrcMapElem elems[] = {
+ { 1u, -1 },
+ { 1u, 0 },
+ { 1u, 1 },
+ { 2u, -1 },
+ { 2u, 0 }, // Index 4.
+ { 2u, 1 },
+ { 2u, 0u }, // Index 6: Arbitrarily add identical SrcMapElem with index 4.
+ };
+
+ for (size_t i = 0; i != arraysize(elems); ++i) {
+ for (size_t j = 0; j != arraysize(elems); ++j) {
+ bool expected = (i != 6u ? i : 4u) == (j != 6u ? j : 4u);
+ EXPECT_EQ(expected, elems[i] == elems[j]) << i << " " << j;
+ }
+ }
+
+ for (size_t i = 0; i != arraysize(elems); ++i) {
+ for (size_t j = 0; j != arraysize(elems); ++j) {
+ bool expected = (i != 6u ? i : 4u) < (j != 6u ? j : 4u);
+ EXPECT_EQ(expected, elems[i] < elems[j]) << i << " " << j;
+ }
+ }
+}
+
+TEST(CompiledMethod, LinkerPatchOperators) {
+ const DexFile* dex_file1 = reinterpret_cast<const DexFile*>(1);
+ const DexFile* dex_file2 = reinterpret_cast<const DexFile*>(2);
+ LinkerPatch patches[] = {
+ LinkerPatch::MethodPatch(16u, dex_file1, 1000u),
+ LinkerPatch::MethodPatch(16u, dex_file1, 1001u),
+ LinkerPatch::MethodPatch(16u, dex_file2, 1000u),
+ LinkerPatch::MethodPatch(16u, dex_file2, 1001u), // Index 3.
+ LinkerPatch::CodePatch(16u, dex_file1, 1000u),
+ LinkerPatch::CodePatch(16u, dex_file1, 1001u),
+ LinkerPatch::CodePatch(16u, dex_file2, 1000u),
+ LinkerPatch::CodePatch(16u, dex_file2, 1001u),
+ LinkerPatch::RelativeCodePatch(16u, dex_file1, 1000u),
+ LinkerPatch::RelativeCodePatch(16u, dex_file1, 1001u),
+ LinkerPatch::RelativeCodePatch(16u, dex_file2, 1000u),
+ LinkerPatch::RelativeCodePatch(16u, dex_file2, 1001u),
+ LinkerPatch::TypePatch(16u, dex_file1, 1000u),
+ LinkerPatch::TypePatch(16u, dex_file1, 1001u),
+ LinkerPatch::TypePatch(16u, dex_file2, 1000u),
+ LinkerPatch::TypePatch(16u, dex_file2, 1001u),
+ LinkerPatch::DexCacheArrayPatch(16u, dex_file1, 3000u, 2000u),
+ LinkerPatch::DexCacheArrayPatch(16u, dex_file1, 3001u, 2000u),
+ LinkerPatch::DexCacheArrayPatch(16u, dex_file1, 3000u, 2001u),
+ LinkerPatch::DexCacheArrayPatch(16u, dex_file1, 3001u, 2001u),
+ LinkerPatch::DexCacheArrayPatch(16u, dex_file2, 3000u, 2000u),
+ LinkerPatch::DexCacheArrayPatch(16u, dex_file2, 3001u, 2000u),
+ LinkerPatch::DexCacheArrayPatch(16u, dex_file2, 3000u, 2001u),
+ LinkerPatch::DexCacheArrayPatch(16u, dex_file2, 3001u, 2001u),
+ LinkerPatch::MethodPatch(32u, dex_file1, 1000u),
+ LinkerPatch::MethodPatch(32u, dex_file1, 1001u),
+ LinkerPatch::MethodPatch(32u, dex_file2, 1000u),
+ LinkerPatch::MethodPatch(32u, dex_file2, 1001u),
+ LinkerPatch::CodePatch(32u, dex_file1, 1000u),
+ LinkerPatch::CodePatch(32u, dex_file1, 1001u),
+ LinkerPatch::CodePatch(32u, dex_file2, 1000u),
+ LinkerPatch::CodePatch(32u, dex_file2, 1001u),
+ LinkerPatch::RelativeCodePatch(32u, dex_file1, 1000u),
+ LinkerPatch::RelativeCodePatch(32u, dex_file1, 1001u),
+ LinkerPatch::RelativeCodePatch(32u, dex_file2, 1000u),
+ LinkerPatch::RelativeCodePatch(32u, dex_file2, 1001u),
+ LinkerPatch::TypePatch(32u, dex_file1, 1000u),
+ LinkerPatch::TypePatch(32u, dex_file1, 1001u),
+ LinkerPatch::TypePatch(32u, dex_file2, 1000u),
+ LinkerPatch::TypePatch(32u, dex_file2, 1001u),
+ LinkerPatch::DexCacheArrayPatch(32u, dex_file1, 3000u, 2000u),
+ LinkerPatch::DexCacheArrayPatch(32u, dex_file1, 3001u, 2000u),
+ LinkerPatch::DexCacheArrayPatch(32u, dex_file1, 3000u, 2001u),
+ LinkerPatch::DexCacheArrayPatch(32u, dex_file1, 3001u, 2001u),
+ LinkerPatch::DexCacheArrayPatch(32u, dex_file2, 3000u, 2000u),
+ LinkerPatch::DexCacheArrayPatch(32u, dex_file2, 3001u, 2000u),
+ LinkerPatch::DexCacheArrayPatch(32u, dex_file2, 3000u, 2001u),
+ LinkerPatch::DexCacheArrayPatch(32u, dex_file2, 3001u, 2001u),
+ LinkerPatch::MethodPatch(16u, dex_file2, 1001u), // identical with patch as index 3.
+ };
+ constexpr size_t last_index = arraysize(patches) - 1u;
+
+ for (size_t i = 0; i != arraysize(patches); ++i) {
+ for (size_t j = 0; j != arraysize(patches); ++j) {
+ bool expected = (i != last_index ? i : 3u) == (j != last_index ? j : 3u);
+ EXPECT_EQ(expected, patches[i] == patches[j]) << i << " " << j;
+ }
+ }
+
+ for (size_t i = 0; i != arraysize(patches); ++i) {
+ for (size_t j = 0; j != arraysize(patches); ++j) {
+ bool expected = (i != last_index ? i : 3u) < (j != last_index ? j : 3u);
+ EXPECT_EQ(expected, patches[i] < patches[j]) << i << " " << j;
+ }
+ }
+}
+
+} // namespace art