Rename OatCompilationUnit to Dex.. move to compiler.
Some other clean-up to make fields const and private.
Change-Id: Icad66e2969385ab1f4125162bcbf8d5fa92d3ed5
diff --git a/src/compiler/driver/compiler_driver.cc b/src/compiler/driver/compiler_driver.cc
index f22aaa5..a28ba18 100644
--- a/src/compiler/driver/compiler_driver.cc
+++ b/src/compiler/driver/compiler_driver.cc
@@ -24,8 +24,8 @@
#include "base/stl_util.h"
#include "base/timing_logger.h"
#include "class_linker.h"
+#include "dex_compilation_unit.h"
#include "jni_internal.h"
-#include "oat_compilation_unit.h"
#include "oat_file.h"
#include "oat/runtime/stub.h"
#include "object_utils.h"
@@ -671,37 +671,37 @@
}
static mirror::Class* ComputeCompilingMethodsClass(ScopedObjectAccess& soa,
- OatCompilationUnit* mUnit)
+ const DexCompilationUnit* mUnit)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
- mirror::DexCache* dex_cache = mUnit->class_linker_->FindDexCache(*mUnit->dex_file_);
- mirror::ClassLoader* class_loader = soa.Decode<mirror::ClassLoader*>(mUnit->class_loader_);
- const DexFile::MethodId& referrer_method_id = mUnit->dex_file_->GetMethodId(mUnit->method_idx_);
- return mUnit->class_linker_->ResolveType(*mUnit->dex_file_, referrer_method_id.class_idx_,
- dex_cache, class_loader);
+ mirror::DexCache* dex_cache = mUnit->GetClassLinker()->FindDexCache(*mUnit->GetDexFile());
+ mirror::ClassLoader* class_loader = soa.Decode<mirror::ClassLoader*>(mUnit->GetClassLoader());
+ const DexFile::MethodId& referrer_method_id = mUnit->GetDexFile()->GetMethodId(mUnit->GetDexMethodIndex());
+ return mUnit->GetClassLinker()->ResolveType(*mUnit->GetDexFile(), referrer_method_id.class_idx_,
+ dex_cache, class_loader);
}
static mirror::Field* ComputeFieldReferencedFromCompilingMethod(ScopedObjectAccess& soa,
- OatCompilationUnit* mUnit,
+ const DexCompilationUnit* mUnit,
uint32_t field_idx)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
- mirror::DexCache* dex_cache = mUnit->class_linker_->FindDexCache(*mUnit->dex_file_);
- mirror::ClassLoader* class_loader = soa.Decode<mirror::ClassLoader*>(mUnit->class_loader_);
- return mUnit->class_linker_->ResolveField(*mUnit->dex_file_, field_idx, dex_cache,
- class_loader, false);
+ mirror::DexCache* dex_cache = mUnit->GetClassLinker()->FindDexCache(*mUnit->GetDexFile());
+ mirror::ClassLoader* class_loader = soa.Decode<mirror::ClassLoader*>(mUnit->GetClassLoader());
+ return mUnit->GetClassLinker()->ResolveField(*mUnit->GetDexFile(), field_idx, dex_cache,
+ class_loader, false);
}
static mirror::AbstractMethod* ComputeMethodReferencedFromCompilingMethod(ScopedObjectAccess& soa,
- OatCompilationUnit* mUnit,
+ const DexCompilationUnit* mUnit,
uint32_t method_idx,
InvokeType type)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
- mirror::DexCache* dex_cache = mUnit->class_linker_->FindDexCache(*mUnit->dex_file_);
- mirror::ClassLoader* class_loader = soa.Decode<mirror::ClassLoader*>(mUnit->class_loader_);
- return mUnit->class_linker_->ResolveMethod(*mUnit->dex_file_, method_idx, dex_cache,
- class_loader, NULL, type);
+ mirror::DexCache* dex_cache = mUnit->GetClassLinker()->FindDexCache(*mUnit->GetDexFile());
+ mirror::ClassLoader* class_loader = soa.Decode<mirror::ClassLoader*>(mUnit->GetClassLoader());
+ return mUnit->GetClassLinker()->ResolveMethod(*mUnit->GetDexFile(), method_idx, dex_cache,
+ class_loader, NULL, type);
}
-bool CompilerDriver::ComputeInstanceFieldInfo(uint32_t field_idx, OatCompilationUnit* mUnit,
+bool CompilerDriver::ComputeInstanceFieldInfo(uint32_t field_idx, const DexCompilationUnit* mUnit,
int& field_offset, bool& is_volatile, bool is_put) {
ScopedObjectAccess soa(Thread::Current());
// Conservative defaults.
@@ -721,7 +721,7 @@
// protected field being made public by a sub-class. Resort to the dex file to determine
// the correct class for the access check.
const DexFile& dex_file = *referrer_class->GetDexCache()->GetDexFile();
- mirror::Class* dex_fields_class = mUnit->class_linker_->ResolveType(dex_file,
+ mirror::Class* dex_fields_class = mUnit->GetClassLinker()->ResolveType(dex_file,
dex_file.GetFieldId(field_idx).class_idx_,
referrer_class);
access_ok = referrer_class->CanAccess(dex_fields_class) &&
@@ -746,7 +746,7 @@
return false; // Incomplete knowledge needs slow path.
}
-bool CompilerDriver::ComputeStaticFieldInfo(uint32_t field_idx, OatCompilationUnit* mUnit,
+bool CompilerDriver::ComputeStaticFieldInfo(uint32_t field_idx, const DexCompilationUnit* mUnit,
int& field_offset, int& ssb_index,
bool& is_referrers_class, bool& is_volatile,
bool is_put) {
@@ -779,9 +779,9 @@
// used to identify the SSB.
const DexFile& dex_file = *referrer_class->GetDexCache()->GetDexFile();
mirror::Class* dex_fields_class =
- mUnit->class_linker_->ResolveType(dex_file,
- dex_file.GetFieldId(field_idx).class_idx_,
- referrer_class);
+ mUnit->GetClassLinker()->ResolveType(dex_file,
+ dex_file.GetFieldId(field_idx).class_idx_,
+ referrer_class);
access_ok = referrer_class->CanAccess(dex_fields_class) &&
referrer_class->CanAccessMember(dex_fields_class,
resolved_field->GetAccessFlags());
@@ -792,7 +792,7 @@
// in its static storage base (which may fail if it doesn't have a slot for it)
// TODO: for images we can elide the static storage base null check
// if we know there's a non-null entry in the image
- mirror::DexCache* dex_cache = mUnit->class_linker_->FindDexCache(*mUnit->dex_file_);
+ mirror::DexCache* dex_cache = mUnit->GetClassLinker()->FindDexCache(*mUnit->GetDexFile());
if (fields_class->GetDexCache() == dex_cache) {
// common case where the dex cache of both the referrer and the field are the same,
// no need to search the dex file
@@ -806,13 +806,13 @@
// of the class mentioned in the dex file and there is no dex cache entry.
std::string descriptor(FieldHelper(resolved_field).GetDeclaringClassDescriptor());
const DexFile::StringId* string_id =
- mUnit->dex_file_->FindStringId(descriptor);
+ mUnit->GetDexFile()->FindStringId(descriptor);
if (string_id != NULL) {
const DexFile::TypeId* type_id =
- mUnit->dex_file_->FindTypeId(mUnit->dex_file_->GetIndexForStringId(*string_id));
+ mUnit->GetDexFile()->FindTypeId(mUnit->GetDexFile()->GetIndexForStringId(*string_id));
if (type_id != NULL) {
// medium path, needs check of static storage base being initialized
- ssb_index = mUnit->dex_file_->GetIndexForTypeId(*type_id);
+ ssb_index = mUnit->GetDexFile()->GetIndexForTypeId(*type_id);
field_offset = resolved_field->GetOffset().Int32Value();
is_volatile = resolved_field->IsVolatile();
stats_->ResolvedStaticField();
@@ -882,7 +882,7 @@
}
}
-bool CompilerDriver::ComputeInvokeInfo(uint32_t method_idx, OatCompilationUnit* mUnit,
+bool CompilerDriver::ComputeInvokeInfo(uint32_t method_idx, const DexCompilationUnit* mUnit,
InvokeType& type, int& vtable_idx, uintptr_t& direct_code,
uintptr_t& direct_method) {
ScopedObjectAccess soa(Thread::Current());
@@ -907,9 +907,9 @@
// check.
const DexFile& dex_file = *referrer_class->GetDexCache()->GetDexFile();
methods_class =
- mUnit->class_linker_->ResolveType(dex_file,
- dex_file.GetMethodId(method_idx).class_idx_,
- referrer_class);
+ mUnit->GetClassLinker()->ResolveType(dex_file,
+ dex_file.GetMethodId(method_idx).class_idx_,
+ referrer_class);
}
if (referrer_class->CanAccess(methods_class) &&
referrer_class->CanAccessMember(methods_class, resolved_method->GetAccessFlags())) {
diff --git a/src/compiler/driver/compiler_driver.h b/src/compiler/driver/compiler_driver.h
index 7026a60..49bc473 100644
--- a/src/compiler/driver/compiler_driver.h
+++ b/src/compiler/driver/compiler_driver.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef ART_SRC_COMPILER_H_
-#define ART_SRC_COMPILER_H_
+#ifndef ART_SRC_COMPILER_DRIVER_COMPILER_DRIVER_H_
+#define ART_SRC_COMPILER_DRIVER_COMPILER_DRIVER_H_
#include <set>
#include <string>
@@ -36,7 +36,7 @@
class AOTCompilationStats;
class ParallelCompilationManager;
-class OatCompilationUnit;
+class DexCompilationUnit;
class TimingLogger;
enum CompilerBackend {
@@ -151,20 +151,20 @@
LOCKS_EXCLUDED(Locks::mutator_lock_);
// Can we fast path instance field access? Computes field's offset and volatility.
- bool ComputeInstanceFieldInfo(uint32_t field_idx, OatCompilationUnit* mUnit,
+ bool ComputeInstanceFieldInfo(uint32_t field_idx, const DexCompilationUnit* mUnit,
int& field_offset, bool& is_volatile, bool is_put)
LOCKS_EXCLUDED(Locks::mutator_lock_);
// Can we fastpath static field access? Computes field's offset, volatility and whether the
// field is within the referrer (which can avoid checking class initialization).
- bool ComputeStaticFieldInfo(uint32_t field_idx, OatCompilationUnit* mUnit,
+ bool ComputeStaticFieldInfo(uint32_t field_idx, const DexCompilationUnit* mUnit,
int& field_offset, int& ssb_index,
bool& is_referrers_class, bool& is_volatile, bool is_put)
LOCKS_EXCLUDED(Locks::mutator_lock_);
// Can we fastpath a interface, super class or virtual method call? Computes method's vtable
// index.
- bool ComputeInvokeInfo(uint32_t method_idx, OatCompilationUnit* mUnit, InvokeType& type,
+ bool ComputeInvokeInfo(uint32_t method_idx, const DexCompilationUnit* mUnit, InvokeType& type,
int& vtable_idx, uintptr_t& direct_code, uintptr_t& direct_method)
LOCKS_EXCLUDED(Locks::mutator_lock_);
@@ -419,4 +419,4 @@
} // namespace art
-#endif // ART_SRC_COMPILER_H_
+#endif // ART_SRC_COMPILER_DRIVER_COMPILER_DRIVER_H_
diff --git a/src/compiler/driver/dex_compilation_unit.h b/src/compiler/driver/dex_compilation_unit.h
new file mode 100644
index 0000000..6a0218d
--- /dev/null
+++ b/src/compiler/driver/dex_compilation_unit.h
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2012 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_SRC_COMPILER_DEX_DEX_COMPILATION_UNIT_H_
+#define ART_SRC_COMPILER_DEX_DEX_COMPILATION_UNIT_H_
+
+#include "dex_file.h"
+
+#include <stdint.h>
+
+namespace art {
+namespace mirror {
+class ClassLoader;
+class DexCache;
+} // namespace mirror
+class ClassLinker;
+class DexFile;
+
+class DexCompilationUnit {
+ public:
+ DexCompilationUnit(jobject class_loader, ClassLinker* class_linker, const DexFile& dex_file,
+ const DexFile::CodeItem* code_item, uint32_t class_def_idx,
+ uint32_t method_idx, uint32_t access_flags)
+ : class_loader_(class_loader), class_linker_(class_linker), dex_file_(&dex_file),
+ code_item_(code_item), class_def_idx_(class_def_idx), dex_method_idx_(method_idx),
+ access_flags_(access_flags) {
+ }
+
+ jobject GetClassLoader() const {
+ return class_loader_;
+ }
+
+ ClassLinker* GetClassLinker() const {
+ return class_linker_;
+ }
+
+ const DexFile* GetDexFile() const {
+ return dex_file_;
+ }
+
+ uint32_t GetClassDefIndex() const {
+ return class_def_idx_;
+ }
+
+ uint32_t GetDexMethodIndex() const {
+ return dex_method_idx_;
+ }
+
+ const DexFile::CodeItem* GetCodeItem() const {
+ return code_item_;
+ }
+
+ const char* GetShorty() const {
+ const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
+ return dex_file_->GetMethodShorty(method_id);
+ }
+
+ const char* GetShorty(uint32_t* shorty_len) const {
+ const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
+ return dex_file_->GetMethodShorty(method_id, shorty_len);
+ }
+
+ uint32_t GetAccessFlags() const {
+ return access_flags_;
+ }
+
+ bool IsNative() const {
+ return ((access_flags_ & kAccNative) != 0);
+ }
+
+ bool IsStatic() const {
+ return ((access_flags_ & kAccStatic) != 0);
+ }
+
+ bool IsSynchronized() const {
+ return ((access_flags_ & kAccSynchronized) != 0);
+ }
+
+ private:
+ const jobject class_loader_;
+ ClassLinker* const class_linker_;
+
+ const DexFile* const dex_file_;
+
+ const DexFile::CodeItem* const code_item_;
+ const uint32_t class_def_idx_;
+ const uint32_t dex_method_idx_;
+ const uint32_t access_flags_;
+};
+
+} // namespace art
+
+#endif // ART_SRC_COMPILER_DEX_DEX_COMPILATION_UNIT_H_