summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2024-06-17 14:28:40 +0000
committer VladimĂ­r Marko <vmarko@google.com> 2024-06-18 09:09:11 +0000
commitb9485ace615a1ef2476884ee790357dd28c32d4e (patch)
tree59010f8e2765a2f5434011e13fa463c2e37aac9c
parent3004a295d46959b0c4b9fa354175e6c88462a17b (diff)
Move `jni_stub_hash_map_test.cc` to `compiler/`.
The test is using `Compiler`, so it belongs to `compiler/`. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 288983053 Change-Id: Id1d5aef67a694a8b610d390c4e40e74d9d788ca9
-rw-r--r--compiler/Android.bp1
-rw-r--r--compiler/common_compiler_test.cc17
-rw-r--r--compiler/common_compiler_test.h1
-rw-r--r--compiler/oat/jni_stub_hash_map_test.cc (renamed from runtime/oat/jni_stub_hash_map_test.cc)45
-rw-r--r--dex2oat/linker/image_writer.cc1
-rw-r--r--runtime/Android.bp1
-rw-r--r--runtime/class_linker.cc9
-rw-r--r--runtime/class_linker.h8
-rw-r--r--runtime/oat/jni_stub_hash_map-inl.h37
-rw-r--r--runtime/oat/jni_stub_hash_map.cc1
-rw-r--r--runtime/oat/jni_stub_hash_map.h13
11 files changed, 83 insertions, 51 deletions
diff --git a/compiler/Android.bp b/compiler/Android.bp
index 975bbf8335..0bfc8fa7b2 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -458,6 +458,7 @@ art_cc_defaults {
"jni/jni_compiler_test.cc",
"linker/linker_patch_test.cc",
"linker/output_stream_test.cc",
+ "oat/jni_stub_hash_map_test.cc",
"optimizing/bounds_check_elimination_test.cc",
"optimizing/constant_folding_test.cc",
"optimizing/data_type_test.cc",
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc
index d7f6a2274f..392a0d1001 100644
--- a/compiler/common_compiler_test.cc
+++ b/compiler/common_compiler_test.cc
@@ -303,6 +303,23 @@ void CommonCompilerTestImpl::CompileMethod(ArtMethod* method) {
}
}
+std::vector<uint8_t> CommonCompilerTestImpl::JniCompileCode(ArtMethod* method) {
+ CHECK(method->IsNative());
+ Thread* self = Thread::Current();
+ StackHandleScope<1> hs(self);
+ const DexFile& dex_file = *method->GetDexFile();
+ Handle<mirror::DexCache> dex_cache =
+ hs.NewHandle(GetClassLinker()->FindDexCache(self, dex_file));
+ OneCompiledMethodStorage storage;
+ std::unique_ptr<Compiler> compiler(Compiler::Create(*compiler_options_, &storage));
+ compiler->JniCompile(method->GetAccessFlags(),
+ method->GetDexMethodIndex(),
+ dex_file,
+ dex_cache);
+ ArrayRef<const uint8_t> code = storage.GetCode();
+ return std::vector<uint8_t>(code.begin(), code.end());
+}
+
void CommonCompilerTestImpl::ClearBootImageOption() {
compiler_options_->image_type_ = CompilerOptions::ImageType::kNone;
}
diff --git a/compiler/common_compiler_test.h b/compiler/common_compiler_test.h
index 30d5734ba3..32a5234797 100644
--- a/compiler/common_compiler_test.h
+++ b/compiler/common_compiler_test.h
@@ -67,6 +67,7 @@ class EXPORT CommonCompilerTestImpl {
void TearDown();
void CompileMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
+ std::vector<uint8_t> JniCompileCode(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
void ApplyInstructionSet();
void OverrideInstructionSetFeatures(InstructionSet instruction_set, const std::string& variant);
diff --git a/runtime/oat/jni_stub_hash_map_test.cc b/compiler/oat/jni_stub_hash_map_test.cc
index cf6f4e2c0d..2a26bcfae6 100644
--- a/runtime/oat/jni_stub_hash_map_test.cc
+++ b/compiler/oat/jni_stub_hash_map_test.cc
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "jni_stub_hash_map.h"
+#include "oat/jni_stub_hash_map-inl.h"
#include <gtest/gtest.h>
@@ -34,19 +34,18 @@
#include "base/utils.h"
#include "class_linker.h"
#include "common_compiler_test.h"
-#include "common_compiler_test.cc"
#include "compiler.h"
#include "gc/heap.h"
#include "gc/space/image_space.h"
#include "handle.h"
#include "handle_scope.h"
#include "handle_scope-inl.h"
-#include "image.h"
-#include "image-inl.h"
#include "jni.h"
#include "mirror/class.h"
#include "mirror/class_loader.h"
#include "mirror/dex_cache.h"
+#include "oat/image-inl.h"
+#include "oat/oat_quick_method_header.h"
#include "obj_ptr.h"
#include "runtime.h"
#include "scoped_thread_state_change.h"
@@ -97,61 +96,35 @@ class JniStubHashMapTest : public CommonCompilerTest {
void SetBaseMethod(std::string_view base_method_name, std::string_view base_method_sig) {
jni_stub_hash_map_.clear();
- Thread* self = Thread::Current();
- ScopedObjectAccess soa(self);
+ ScopedObjectAccess soa(Thread::Current());
ObjPtr<mirror::Class> klass = soa.Decode<mirror::Class>(jklass_);
base_method_ = klass->FindClassMethod(base_method_name, base_method_sig, pointer_size_);
ASSERT_TRUE(base_method_ != nullptr);
ASSERT_TRUE(base_method_->IsNative());
- OneCompiledMethodStorage base_method_storage;
- StackHandleScope<1> hs(self);
- std::unique_ptr<Compiler> compiler(
- Compiler::Create(*compiler_options_, &base_method_storage));
- const DexFile& dex_file = *base_method_->GetDexFile();
- Handle<mirror::DexCache> dex_cache =
- hs.NewHandle(GetClassLinker()->FindDexCache(self, dex_file));
- compiler->JniCompile(base_method_->GetAccessFlags(),
- base_method_->GetDexMethodIndex(),
- dex_file,
- dex_cache);
- ArrayRef<const uint8_t> code = base_method_storage.GetCode();
- base_method_code_.assign(code.begin(), code.end());
+ base_method_code_ = JniCompileCode(base_method_);
jni_stub_hash_map_.insert(std::make_pair(JniStubKey(base_method_), base_method_));
}
void CompareMethod(std::string_view cmp_method_name, std::string_view cmp_method_sig) {
- Thread* self = Thread::Current();
- ScopedObjectAccess soa(self);
+ ScopedObjectAccess soa(Thread::Current());
ObjPtr<mirror::Class> klass = soa.Decode<mirror::Class>(jklass_);
ArtMethod* cmp_method = klass->FindClassMethod(cmp_method_name, cmp_method_sig, pointer_size_);
ASSERT_TRUE(cmp_method != nullptr);
ASSERT_TRUE(cmp_method->IsNative());
- OneCompiledMethodStorage cmp_method_storage;
- StackHandleScope<1> hs(self);
- std::unique_ptr<Compiler> compiler(
- Compiler::Create(*compiler_options_, &cmp_method_storage));
- const DexFile& dex_file = *cmp_method->GetDexFile();
- Handle<mirror::DexCache> dex_cache =
- hs.NewHandle(GetClassLinker()->FindDexCache(self, dex_file));
- compiler->JniCompile(cmp_method->GetAccessFlags(),
- cmp_method->GetDexMethodIndex(),
- dex_file,
- dex_cache);
+ std::vector<uint8_t> cmp_method_code = JniCompileCode(cmp_method);
- ArrayRef<const uint8_t> method_code = ArrayRef<const uint8_t>(base_method_code_);
- ArrayRef<const uint8_t> cmp_method_code = cmp_method_storage.GetCode();
auto it = jni_stub_hash_map_.find(JniStubKey(cmp_method));
if (it != jni_stub_hash_map_.end()) {
- ASSERT_EQ(method_code, cmp_method_code)
+ ASSERT_EQ(base_method_code_, cmp_method_code)
<< "base method: " << base_method_->PrettyMethod() << ", compared method: "
<< cmp_method->PrettyMethod();
} else if (strict_check_){
// If the compared method maps to a different entry, then its compiled JNI stub should be
// also different from the base one.
- ASSERT_NE(method_code, cmp_method_code)
+ ASSERT_NE(base_method_code_, cmp_method_code)
<< "base method: " << base_method_->PrettyMethod() << ", compared method: "
<< cmp_method->PrettyMethod();
}
diff --git a/dex2oat/linker/image_writer.cc b/dex2oat/linker/image_writer.cc
index b3399fed0c..41cf1edaf8 100644
--- a/dex2oat/linker/image_writer.cc
+++ b/dex2oat/linker/image_writer.cc
@@ -78,6 +78,7 @@
#include "nterp_helpers.h"
#include "oat/elf_file.h"
#include "oat/image-inl.h"
+#include "oat/jni_stub_hash_map-inl.h"
#include "oat/oat.h"
#include "oat/oat_file.h"
#include "oat/oat_file_manager.h"
diff --git a/runtime/Android.bp b/runtime/Android.bp
index fe9fe295f6..276e25c1de 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -1106,7 +1106,6 @@ art_cc_defaults {
"monitor_pool_test.cc",
"monitor_test.cc",
"native_stack_dump_test.cc",
- "oat/jni_stub_hash_map_test.cc",
"oat/oat_file_assistant_test.cc",
"oat/oat_file_test.cc",
"parsed_options_test.cc",
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index c8394b2a5d..4d3eaea37f 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -138,6 +138,7 @@
#include "nterp_helpers-inl.h"
#include "nterp_helpers.h"
#include "oat/image-inl.h"
+#include "oat/jni_stub_hash_map-inl.h"
#include "oat/oat.h"
#include "oat/oat_file-inl.h"
#include "oat/oat_file.h"
@@ -409,6 +410,14 @@ void ClassLinker::ForceClassInitialized(Thread* self, Handle<mirror::Class> klas
MakeInitializedClassesVisiblyInitialized(self, /*wait=*/true);
}
+const void* ClassLinker::FindBootJniStub(ArtMethod* method) {
+ return FindBootJniStub(JniStubKey(method));
+}
+
+const void* ClassLinker::FindBootJniStub(uint32_t flags, std::string_view shorty) {
+ return FindBootJniStub(JniStubKey(flags, shorty));
+}
+
const void* ClassLinker::FindBootJniStub(JniStubKey key) {
auto it = boot_image_jni_stubs_.find(key);
if (it == boot_image_jni_stubs_.end()) {
diff --git a/runtime/class_linker.h b/runtime/class_linker.h
index daf9534c3a..660e4be20e 100644
--- a/runtime/class_linker.h
+++ b/runtime/class_linker.h
@@ -964,13 +964,9 @@ class EXPORT ClassLinker {
}
// Find a matching JNI stub from boot images that we could reuse as entrypoint.
const void* FindBootJniStub(ArtMethod* method)
- REQUIRES_SHARED(Locks::mutator_lock_) {
- return FindBootJniStub(JniStubKey(method));
- }
+ REQUIRES_SHARED(Locks::mutator_lock_);
- const void* FindBootJniStub(uint32_t flags, std::string_view shorty) {
- return FindBootJniStub(JniStubKey(flags, shorty));
- }
+ const void* FindBootJniStub(uint32_t flags, std::string_view shorty);
const void* FindBootJniStub(JniStubKey key);
diff --git a/runtime/oat/jni_stub_hash_map-inl.h b/runtime/oat/jni_stub_hash_map-inl.h
new file mode 100644
index 0000000000..5ac0308a5b
--- /dev/null
+++ b/runtime/oat/jni_stub_hash_map-inl.h
@@ -0,0 +1,37 @@
+/*
+ * 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_RUNTIME_OAT_JNI_STUB_HASH_MAP_INL_H_
+#define ART_RUNTIME_OAT_JNI_STUB_HASH_MAP_INL_H_
+
+#include "jni_stub_hash_map.h"
+
+#include "art_method-inl.h"
+
+namespace art {
+
+inline JniStubKey::JniStubKey(uint32_t flags, std::string_view shorty)
+ : flags_(flags & (kAccStatic | kAccSynchronized | kAccFastNative | kAccCriticalNative)),
+ shorty_(shorty) {
+ DCHECK(ArtMethod::IsNative(flags));
+}
+
+inline JniStubKey::JniStubKey(ArtMethod* method)
+ : JniStubKey(method->GetAccessFlags(), method->GetShortyView()) {}
+
+} // namespace art
+
+#endif // ART_RUNTIME_OAT_JNI_STUB_HASH_MAP_INL_H_
diff --git a/runtime/oat/jni_stub_hash_map.cc b/runtime/oat/jni_stub_hash_map.cc
index fccf697b7d..add1005291 100644
--- a/runtime/oat/jni_stub_hash_map.cc
+++ b/runtime/oat/jni_stub_hash_map.cc
@@ -21,6 +21,7 @@
#include "arch/riscv64/jni_frame_riscv64.h"
#include "arch/x86_64/jni_frame_x86_64.h"
#include "base/macros.h"
+#include "dex/modifiers.h"
namespace art HIDDEN {
diff --git a/runtime/oat/jni_stub_hash_map.h b/runtime/oat/jni_stub_hash_map.h
index 6e4603d3fb..83528843e0 100644
--- a/runtime/oat/jni_stub_hash_map.h
+++ b/runtime/oat/jni_stub_hash_map.h
@@ -21,25 +21,22 @@
#include <string_view>
#include "arch/instruction_set.h"
-#include "art_method.h"
#include "base/hash_map.h"
+#include "base/locks.h"
namespace art HIDDEN {
+class ArtMethod;
+
class JniStubKey {
public:
JniStubKey() = default;
JniStubKey(const JniStubKey& other) = default;
JniStubKey& operator=(const JniStubKey& other) = default;
- JniStubKey(uint32_t flags, std::string_view shorty)
- : flags_(flags & (kAccStatic | kAccSynchronized | kAccFastNative | kAccCriticalNative)),
- shorty_(shorty) {
- DCHECK(ArtMethod::IsNative(flags));
- }
+ JniStubKey(uint32_t flags, std::string_view shorty);
- explicit JniStubKey(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_)
- : JniStubKey(method->GetAccessFlags(), method->GetShortyView()) {}
+ explicit JniStubKey(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
uint32_t Flags() const {
return flags_;