summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/Android.bp1
-rw-r--r--compiler/optimizing/handle_cache-inl.h38
-rw-r--r--compiler/optimizing/handle_cache.cc33
-rw-r--r--compiler/optimizing/handle_cache.h89
-rw-r--r--compiler/optimizing/inliner.cc1
-rw-r--r--compiler/optimizing/instruction_builder.cc1
-rw-r--r--compiler/optimizing/nodes.cc7
-rw-r--r--compiler/optimizing/nodes.h65
-rw-r--r--compiler/optimizing/reference_type_propagation.cc1
-rw-r--r--compiler/optimizing/reference_type_propagation.h2
10 files changed, 167 insertions, 71 deletions
diff --git a/compiler/Android.bp b/compiler/Android.bp
index 46e90281de..ece67d4290 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -159,6 +159,7 @@ art_cc_defaults {
"optimizing/graph_checker.cc",
"optimizing/graph_visualizer.cc",
"optimizing/gvn.cc",
+ "optimizing/handle_cache.cc",
"optimizing/induction_var_analysis.cc",
"optimizing/induction_var_range.cc",
"optimizing/inliner.cc",
diff --git a/compiler/optimizing/handle_cache-inl.h b/compiler/optimizing/handle_cache-inl.h
new file mode 100644
index 0000000000..81da8f554f
--- /dev/null
+++ b/compiler/optimizing/handle_cache-inl.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2024 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_COMPILER_OPTIMIZING_HANDLE_CACHE_INL_H_
+#define ART_COMPILER_OPTIMIZING_HANDLE_CACHE_INL_H_
+
+#include "handle_cache.h"
+
+#include "handle_scope-inl.h"
+
+namespace art HIDDEN {
+
+template <typename T>
+MutableHandle<T> HandleCache::NewHandle(T* object) {
+ return handles_->NewHandle(object);
+}
+
+template <typename T>
+MutableHandle<T> HandleCache::NewHandle(ObjPtr<T> object) {
+ return handles_->NewHandle(object);
+}
+
+} // namespace art
+
+#endif // ART_COMPILER_OPTIMIZING_HANDLE_CACHE_INL_H_
diff --git a/compiler/optimizing/handle_cache.cc b/compiler/optimizing/handle_cache.cc
new file mode 100644
index 0000000000..fbdc8bbf32
--- /dev/null
+++ b/compiler/optimizing/handle_cache.cc
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2024 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 "handle_cache.h"
+
+#include "class_root-inl.h"
+#include "handle_scope-inl.h"
+#include "scoped_thread_state_change-inl.h"
+#include "thread-current-inl.h"
+
+namespace art HIDDEN {
+
+ReferenceTypeInfo::TypeHandle HandleCache::CreateRootHandle(VariableSizedHandleScope* handles,
+ ClassRoot class_root) {
+ // Mutator lock is required for NewHandle and GetClassRoot().
+ ScopedObjectAccess soa(Thread::Current());
+ return handles->NewHandle(GetClassRoot(class_root));
+}
+
+} // namespace art
diff --git a/compiler/optimizing/handle_cache.h b/compiler/optimizing/handle_cache.h
new file mode 100644
index 0000000000..56c3331aa9
--- /dev/null
+++ b/compiler/optimizing/handle_cache.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2024 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_COMPILER_OPTIMIZING_HANDLE_CACHE_H_
+#define ART_COMPILER_OPTIMIZING_HANDLE_CACHE_H_
+
+#include "base/macros.h"
+#include "class_root.h"
+#include "reference_type_info.h"
+
+namespace art HIDDEN {
+
+class VariableSizedHandleScope;
+
+class HandleCache {
+ public:
+ explicit HandleCache(VariableSizedHandleScope* handles) : handles_(handles) { }
+
+ VariableSizedHandleScope* GetHandles() { return handles_; }
+
+ template <typename T>
+ MutableHandle<T> NewHandle(T* object) REQUIRES_SHARED(Locks::mutator_lock_);
+
+ template <typename T>
+ MutableHandle<T> NewHandle(ObjPtr<T> object) REQUIRES_SHARED(Locks::mutator_lock_);
+
+ ReferenceTypeInfo::TypeHandle GetObjectClassHandle() {
+ return GetRootHandle(ClassRoot::kJavaLangObject, &object_class_handle_);
+ }
+
+ ReferenceTypeInfo::TypeHandle GetClassClassHandle() {
+ return GetRootHandle(ClassRoot::kJavaLangClass, &class_class_handle_);
+ }
+
+ ReferenceTypeInfo::TypeHandle GetMethodHandleClassHandle() {
+ return GetRootHandle(ClassRoot::kJavaLangInvokeMethodHandleImpl, &method_handle_class_handle_);
+ }
+
+ ReferenceTypeInfo::TypeHandle GetMethodTypeClassHandle() {
+ return GetRootHandle(ClassRoot::kJavaLangInvokeMethodType, &method_type_class_handle_);
+ }
+
+ ReferenceTypeInfo::TypeHandle GetStringClassHandle() {
+ return GetRootHandle(ClassRoot::kJavaLangString, &string_class_handle_);
+ }
+
+ ReferenceTypeInfo::TypeHandle GetThrowableClassHandle() {
+ return GetRootHandle(ClassRoot::kJavaLangThrowable, &throwable_class_handle_);
+ }
+
+ private:
+ inline ReferenceTypeInfo::TypeHandle GetRootHandle(ClassRoot class_root,
+ ReferenceTypeInfo::TypeHandle* cache) {
+ if (UNLIKELY(!ReferenceTypeInfo::IsValidHandle(*cache))) {
+ *cache = CreateRootHandle(handles_, class_root);
+ }
+ return *cache;
+ }
+
+ static ReferenceTypeInfo::TypeHandle CreateRootHandle(VariableSizedHandleScope* handles,
+ ClassRoot class_root);
+
+ VariableSizedHandleScope* handles_;
+
+ ReferenceTypeInfo::TypeHandle object_class_handle_;
+ ReferenceTypeInfo::TypeHandle class_class_handle_;
+ ReferenceTypeInfo::TypeHandle method_handle_class_handle_;
+ ReferenceTypeInfo::TypeHandle method_type_class_handle_;
+ ReferenceTypeInfo::TypeHandle string_class_handle_;
+ ReferenceTypeInfo::TypeHandle throwable_class_handle_;
+};
+
+} // namespace art
+
+#endif // ART_COMPILER_OPTIMIZING_HANDLE_CACHE_H_
+
diff --git a/compiler/optimizing/inliner.cc b/compiler/optimizing/inliner.cc
index f457ec6636..396aa95692 100644
--- a/compiler/optimizing/inliner.cc
+++ b/compiler/optimizing/inliner.cc
@@ -28,6 +28,7 @@
#include "dex/inline_method_analyser.h"
#include "driver/compiler_options.h"
#include "driver/dex_compilation_unit.h"
+#include "handle_cache-inl.h"
#include "instruction_simplifier.h"
#include "intrinsics.h"
#include "jit/jit.h"
diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc
index 6decd9b3c4..b2179e69bb 100644
--- a/compiler/optimizing/instruction_builder.cc
+++ b/compiler/optimizing/instruction_builder.cc
@@ -29,6 +29,7 @@
#include "driver/compiler_options.h"
#include "driver/dex_compilation_unit.h"
#include "entrypoints/entrypoint_utils-inl.h"
+#include "handle_cache-inl.h"
#include "imtable-inl.h"
#include "intrinsics.h"
#include "intrinsics_utils.h"
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc
index 7724c7eb34..9c41aef8b6 100644
--- a/compiler/optimizing/nodes.cc
+++ b/compiler/optimizing/nodes.cc
@@ -51,13 +51,6 @@ namespace art HIDDEN {
// double).
static constexpr bool kEnableFloatingPointStaticEvaluation = (FLT_EVAL_METHOD == 0);
-ReferenceTypeInfo::TypeHandle HandleCache::CreateRootHandle(VariableSizedHandleScope* handles,
- ClassRoot class_root) {
- // Mutator lock is required for NewHandle and GetClassRoot().
- ScopedObjectAccess soa(Thread::Current());
- return handles->NewHandle(GetClassRoot(class_root));
-}
-
void HGraph::AddBlock(HBasicBlock* block) {
block->SetBlockId(blocks_.size());
blocks_.push_back(block);
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index cfbb5c8010..5a23c8b2a8 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -45,7 +45,7 @@
#include "dex/method_reference.h"
#include "entrypoints/quick/quick_entrypoints_enum.h"
#include "handle.h"
-#include "handle_scope.h"
+#include "handle_cache.h"
#include "intrinsics_enum.h"
#include "locations.h"
#include "mirror/class.h"
@@ -199,69 +199,6 @@ class HInstructionList : public ValueObject {
DISALLOW_COPY_AND_ASSIGN(HInstructionList);
};
-class HandleCache {
- public:
- explicit HandleCache(VariableSizedHandleScope* handles) : handles_(handles) { }
-
- VariableSizedHandleScope* GetHandles() { return handles_; }
-
- template <typename T>
- MutableHandle<T> NewHandle(T* object) REQUIRES_SHARED(Locks::mutator_lock_) {
- return handles_->NewHandle(object);
- }
-
- template <typename T>
- MutableHandle<T> NewHandle(ObjPtr<T> object) REQUIRES_SHARED(Locks::mutator_lock_) {
- return handles_->NewHandle(object);
- }
-
- ReferenceTypeInfo::TypeHandle GetObjectClassHandle() {
- return GetRootHandle(ClassRoot::kJavaLangObject, &object_class_handle_);
- }
-
- ReferenceTypeInfo::TypeHandle GetClassClassHandle() {
- return GetRootHandle(ClassRoot::kJavaLangClass, &class_class_handle_);
- }
-
- ReferenceTypeInfo::TypeHandle GetMethodHandleClassHandle() {
- return GetRootHandle(ClassRoot::kJavaLangInvokeMethodHandleImpl, &method_handle_class_handle_);
- }
-
- ReferenceTypeInfo::TypeHandle GetMethodTypeClassHandle() {
- return GetRootHandle(ClassRoot::kJavaLangInvokeMethodType, &method_type_class_handle_);
- }
-
- ReferenceTypeInfo::TypeHandle GetStringClassHandle() {
- return GetRootHandle(ClassRoot::kJavaLangString, &string_class_handle_);
- }
-
- ReferenceTypeInfo::TypeHandle GetThrowableClassHandle() {
- return GetRootHandle(ClassRoot::kJavaLangThrowable, &throwable_class_handle_);
- }
-
-
- private:
- inline ReferenceTypeInfo::TypeHandle GetRootHandle(ClassRoot class_root,
- ReferenceTypeInfo::TypeHandle* cache) {
- if (UNLIKELY(!ReferenceTypeInfo::IsValidHandle(*cache))) {
- *cache = CreateRootHandle(handles_, class_root);
- }
- return *cache;
- }
-
- static ReferenceTypeInfo::TypeHandle CreateRootHandle(VariableSizedHandleScope* handles,
- ClassRoot class_root);
-
- VariableSizedHandleScope* handles_;
-
- ReferenceTypeInfo::TypeHandle object_class_handle_;
- ReferenceTypeInfo::TypeHandle class_class_handle_;
- ReferenceTypeInfo::TypeHandle method_handle_class_handle_;
- ReferenceTypeInfo::TypeHandle method_type_class_handle_;
- ReferenceTypeInfo::TypeHandle string_class_handle_;
- ReferenceTypeInfo::TypeHandle throwable_class_handle_;
-};
-
// Control-flow graph of a method. Contains a list of basic blocks.
class HGraph : public ArenaObject<kArenaAllocGraph> {
public:
diff --git a/compiler/optimizing/reference_type_propagation.cc b/compiler/optimizing/reference_type_propagation.cc
index 14017088c2..43079f9eee 100644
--- a/compiler/optimizing/reference_type_propagation.cc
+++ b/compiler/optimizing/reference_type_propagation.cc
@@ -24,6 +24,7 @@
#include "base/scoped_arena_containers.h"
#include "class_linker-inl.h"
#include "class_root-inl.h"
+#include "handle_cache-inl.h"
#include "handle_scope-inl.h"
#include "mirror/class-inl.h"
#include "mirror/dex_cache.h"
diff --git a/compiler/optimizing/reference_type_propagation.h b/compiler/optimizing/reference_type_propagation.h
index 655f62b3da..56c4af8fa5 100644
--- a/compiler/optimizing/reference_type_propagation.h
+++ b/compiler/optimizing/reference_type_propagation.h
@@ -26,6 +26,8 @@
namespace art HIDDEN {
+class HandleCache;
+
/**
* Propagates reference types to instructions.
*/