summaryrefslogtreecommitdiff
path: root/libdexfile/dex/proto_reference.h
diff options
context:
space:
mode:
author Almaz Mingaleev <mingaleev@google.com> 2023-12-15 15:47:22 +0000
committer Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-01-03 15:29:48 +0000
commit3f0981b56a1b9a415383c552c063b890c840b13e (patch)
tree4f5aae6900d024630a90401761905b5ce4847f08 /libdexfile/dex/proto_reference.h
parent41c5dde40d1c75d36a7f984c8d72ec65fbff3111 (diff)
Revert^2 "x86_64: Store resolved MethodType-s in .bss."
This reverts commit d014fd019e84471665ac02f2de285541009892cd. Reason for revert: fix codegen to do runtime call in JIT for now. Bug: 297147201 Test: ./art/test/testrunner/testrunner.py --host --64 --optimizing -b Test: ./art/test/testrunner/testrunner.py --jvm -b Test: ./art/test.py --host -b Test: ./art/test/testrunner/testrunner.py --host --64 --jit -b Change-Id: I0f01c8391b09659bb6195955ecd8f88159141872
Diffstat (limited to 'libdexfile/dex/proto_reference.h')
-rw-r--r--libdexfile/dex/proto_reference.h91
1 files changed, 91 insertions, 0 deletions
diff --git a/libdexfile/dex/proto_reference.h b/libdexfile/dex/proto_reference.h
new file mode 100644
index 0000000000..dc9a447e63
--- /dev/null
+++ b/libdexfile/dex/proto_reference.h
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2023 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_LIBDEXFILE_DEX_PROTO_REFERENCE_H_
+#define ART_LIBDEXFILE_DEX_PROTO_REFERENCE_H_
+
+#include <stdint.h>
+
+#include <android-base/logging.h>
+#include <string_view>
+
+#include "dex/dex_file-inl.h"
+#include "dex/dex_file_reference.h"
+#include "dex/dex_file_types.h"
+
+namespace art {
+
+// A proto is located by its DexFile and the proto_ids_ table index into that DexFile.
+class ProtoReference : public DexFileReference {
+ public:
+ ProtoReference(const DexFile* file, dex::ProtoIndex index)
+ : DexFileReference(file, index.index_) {}
+
+ dex::ProtoIndex ProtoIndex() const {
+ return dex::ProtoIndex(index);
+ }
+
+ const dex::ProtoId& ProtoId() const {
+ return dex_file->GetProtoId(ProtoIndex());
+ }
+
+ std::string_view ReturnType() const {
+ return dex_file->GetTypeDescriptorView(dex_file->GetTypeId(ProtoId().return_type_idx_));
+ }
+};
+
+struct ProtoReferenceValueComparator {
+ bool operator()(const ProtoReference& lhs, const ProtoReference& rhs) const {
+ if (lhs.dex_file == rhs.dex_file) {
+ DCHECK_EQ(lhs.index < rhs.index, SlowCompare(lhs, rhs));
+
+ return lhs.index < rhs.index;
+ } else {
+ return SlowCompare(lhs, rhs);
+ }
+ }
+
+ bool SlowCompare(const ProtoReference& lhs, const ProtoReference& rhs) const {
+ // Compare return type first.
+ const dex::ProtoId& prid1 = lhs.ProtoId();
+ const dex::ProtoId& prid2 = rhs.ProtoId();
+ int return_type_diff = lhs.ReturnType().compare(rhs.ReturnType());
+ if (return_type_diff != 0) {
+ return return_type_diff < 0;
+ }
+ // And then compare parameters lexicographically.
+ const dex::TypeList* params1 = lhs.dex_file->GetProtoParameters(prid1);
+ size_t param1_size = (params1 != nullptr) ? params1->Size() : 0u;
+ const dex::TypeList* params2 = rhs.dex_file->GetProtoParameters(prid2);
+ size_t param2_size = (params2 != nullptr) ? params2->Size() : 0u;
+ for (size_t i = 0, num = std::min(param1_size, param2_size); i != num; ++i) {
+ std::string_view l_param = lhs.dex_file->GetTypeDescriptorView(
+ lhs.dex_file->GetTypeId(params1->GetTypeItem(i).type_idx_));
+ std::string_view r_param = rhs.dex_file->GetTypeDescriptorView(
+ rhs.dex_file->GetTypeId(params2->GetTypeItem(i).type_idx_));
+
+ int param_diff = l_param.compare(r_param);
+ if (param_diff != 0) {
+ return param_diff < 0;
+ }
+ }
+ return param1_size < param2_size;
+ }
+};
+
+} // namespace art
+
+#endif // ART_LIBDEXFILE_DEX_PROTO_REFERENCE_H_