diff options
| author | 2016-06-21 15:14:20 -0700 | |
|---|---|---|
| committer | 2016-07-13 13:20:55 -0700 | |
| commit | 8e2c56252aa9527bd9a82bdd147fdc46cf5deb9c (patch) | |
| tree | 4b300a176d73caae6c63768e951976a4fde993ef /runtime/string_reference.h | |
| parent | 633c22de95fe6f80c0dd3176e15de4de3ee4bc79 (diff) | |
Dump more dex file data in oatdump
Dump some statistics for each dex file along side with strings loaded
from code and dex code bytes.
Sample output:
Cumulative dex file data
Num string ids: 202809
Num method ids: 320464
Num field ids: 162822
Num type ids: 68151
Num class defs: 48061
Unique strings loaded from dex code: 51049
Total strings loaded from dex code: 106651
Number of unique dex code items: 247929
Total number of dex code bytes: 11090574
Added content testing to oat dump test. No significant slowdown.
TEST: test-art-host
Bug: 29462018
Change-Id: I60effd3087d8c427eda4ee26431d5d77165b3939
Diffstat (limited to 'runtime/string_reference.h')
| -rw-r--r-- | runtime/string_reference.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/runtime/string_reference.h b/runtime/string_reference.h new file mode 100644 index 0000000000..c75c218cd5 --- /dev/null +++ b/runtime/string_reference.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2016 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. + */ + +#ifndef ART_RUNTIME_STRING_REFERENCE_H_ +#define ART_RUNTIME_STRING_REFERENCE_H_ + +#include <stdint.h> + +#include "base/logging.h" +#include "dex_file-inl.h" +#include "utf-inl.h" + +namespace art { + +// A string is located by its DexFile and the string_ids_ table index into that DexFile. +struct StringReference { + StringReference(const DexFile* file, uint32_t index) : dex_file(file), string_index(index) { } + + const char* GetStringData() const { + return dex_file->GetStringData(dex_file->GetStringId(string_index)); + } + + const DexFile* dex_file; + uint32_t string_index; +}; + +// Compare only the reference and not the string contents. +struct StringReferenceComparator { + bool operator()(const StringReference& a, const StringReference& b) { + if (a.dex_file != b.dex_file) { + return a.dex_file < b.dex_file; + } + return a.string_index < b.string_index; + } +}; + +// Compare the actual referenced string values. Used for string reference deduplication. +struct StringReferenceValueComparator { + bool operator()(StringReference sr1, StringReference sr2) const { + // Note that we want to deduplicate identical strings even if they are referenced + // by different dex files, so we need some (any) total ordering of strings, rather + // than references. However, the references should usually be from the same dex file, + // so we choose the dex file string ordering so that we can simply compare indexes + // and avoid the costly string comparison in the most common case. + if (sr1.dex_file == sr2.dex_file) { + // Use the string order enforced by the dex file verifier. + DCHECK_EQ( + sr1.string_index < sr2.string_index, + CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(sr1.GetStringData(), + sr2.GetStringData()) < 0); + return sr1.string_index < sr2.string_index; + } else { + // Cannot compare indexes, so do the string comparison. + return CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(sr1.GetStringData(), + sr2.GetStringData()) < 0; + } + } +}; + +} // namespace art + +#endif // ART_RUNTIME_STRING_REFERENCE_H_ |