Merge "Revert "Revert "Re-apply "Cleanup run-test and Makefile around boot image and PIC.""""
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index 3e9f619..12b50b8 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -214,6 +214,8 @@
runtime/base/stringprintf_test.cc \
runtime/base/time_utils_test.cc \
runtime/base/timing_logger_test.cc \
+ runtime/base/transform_array_ref_test.cc \
+ runtime/base/transform_iterator_test.cc \
runtime/base/variant_map_test.cc \
runtime/base/unix_file/fd_file_test.cc \
runtime/class_linker_test.cc \
@@ -308,9 +310,7 @@
compiler/utils/intrusive_forward_list_test.cc \
compiler/utils/string_reference_test.cc \
compiler/utils/swap_space_test.cc \
- compiler/utils/test_dex_file_builder_test.cc \
- compiler/utils/transform_array_ref_test.cc \
- compiler/utils/transform_iterator_test.cc \
+ compiler/utils/test_dex_file_builder_test.cc
COMPILER_GTEST_COMMON_SRC_FILES_all := \
compiler/jni/jni_cfi_test.cc \
diff --git a/build/art.go b/build/art.go
index f694505..ffa9273 100644
--- a/build/art.go
+++ b/build/art.go
@@ -122,7 +122,7 @@
return cflags
}
-func (a *artGlobalDefaults) CustomizeProperties(ctx android.CustomizePropertiesContext) {
+func globalDefaults(ctx android.LoadHookContext) {
type props struct {
Target struct {
Android struct {
@@ -143,9 +143,7 @@
ctx.AppendProperties(p)
}
-type artGlobalDefaults struct{}
-
-func (a *artCustomLinkerCustomizer) CustomizeProperties(ctx android.CustomizePropertiesContext) {
+func customLinker(ctx android.LoadHookContext) {
linker := envDefault(ctx, "CUSTOM_TARGET_LINKER", "")
if linker != "" {
type props struct {
@@ -158,9 +156,7 @@
}
}
-type artCustomLinkerCustomizer struct{}
-
-func (a *artPrefer32BitCustomizer) CustomizeProperties(ctx android.CustomizePropertiesContext) {
+func prefer32Bit(ctx android.LoadHookContext) {
if envTrue(ctx, "HOST_PREFER_32_BIT") {
type props struct {
Target struct {
@@ -176,8 +172,6 @@
}
}
-type artPrefer32BitCustomizer struct{}
-
func init() {
soong.RegisterModuleType("art_cc_library", artLibrary)
soong.RegisterModuleType("art_cc_binary", artBinary)
@@ -187,17 +181,16 @@
}
func artGlobalDefaultsFactory() (blueprint.Module, []interface{}) {
- c := &artGlobalDefaults{}
module, props := artDefaultsFactory()
- android.AddCustomizer(module.(android.Module), c)
+ android.AddLoadHook(module, globalDefaults)
return module, props
}
func artDefaultsFactory() (blueprint.Module, []interface{}) {
- c := &codegenCustomizer{}
- module, props := cc.DefaultsFactory(&c.codegenProperties)
- android.AddCustomizer(module.(android.Module), c)
+ c := &codegenProperties{}
+ module, props := cc.DefaultsFactory(c)
+ android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c) })
return module, props
}
@@ -206,9 +199,9 @@
library, _ := cc.NewLibrary(android.HostAndDeviceSupported, true, true)
module, props := library.Init()
- c := &codegenCustomizer{}
- android.AddCustomizer(library, c)
- props = append(props, &c.codegenProperties)
+ c := &codegenProperties{}
+ android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c) })
+ props = append(props, c)
return module, props
}
@@ -217,8 +210,8 @@
binary, _ := cc.NewBinary(android.HostAndDeviceSupported)
module, props := binary.Init()
- android.AddCustomizer(binary, &artCustomLinkerCustomizer{})
- android.AddCustomizer(binary, &artPrefer32BitCustomizer{})
+ android.AddLoadHook(module, customLinker)
+ android.AddLoadHook(module, prefer32Bit)
return module, props
}
@@ -226,8 +219,8 @@
test := cc.NewTest(android.HostAndDeviceSupported)
module, props := test.Init()
- android.AddCustomizer(test, &artCustomLinkerCustomizer{})
- android.AddCustomizer(test, &artPrefer32BitCustomizer{})
+ android.AddLoadHook(module, customLinker)
+ android.AddLoadHook(module, prefer32Bit)
return module, props
}
diff --git a/build/codegen.go b/build/codegen.go
index fde9420..d98ca4f 100644
--- a/build/codegen.go
+++ b/build/codegen.go
@@ -24,9 +24,7 @@
"strings"
)
-func (a *codegenCustomizer) CustomizeProperties(ctx android.CustomizePropertiesContext) {
- c := &a.codegenProperties.Codegen
-
+func codegen(ctx android.LoadHookContext, c *codegenProperties) {
var hostArches, deviceArches []string
e := envDefault(ctx, "ART_HOST_CODEGEN_ARCHS", "")
@@ -53,17 +51,17 @@
addCodegenArchProperties := func(p *props, hod **codegenArchProperties, arch string) {
switch arch {
case "arm":
- *hod = &c.Arm
+ *hod = &c.Codegen.Arm
case "arm64":
- *hod = &c.Arm64
+ *hod = &c.Codegen.Arm64
case "mips":
- *hod = &c.Mips
+ *hod = &c.Codegen.Mips
case "mips64":
- *hod = &c.Mips64
+ *hod = &c.Codegen.Mips64
case "x86":
- *hod = &c.X86
+ *hod = &c.Codegen.X86
case "x86_64":
- *hod = &c.X86_64
+ *hod = &c.Codegen.X86_64
default:
ctx.ModuleErrorf("Unknown codegen architecture %q", arch)
return
@@ -109,7 +107,7 @@
codegenProperties codegenProperties
}
-func defaultDeviceCodegenArches(ctx android.CustomizePropertiesContext) []string {
+func defaultDeviceCodegenArches(ctx android.LoadHookContext) []string {
arches := make(map[string]bool)
for _, a := range ctx.DeviceConfig().Arches() {
s := a.ArchType.String()
diff --git a/compiler/compiled_method.h b/compiler/compiled_method.h
index 2a81804..1a87448 100644
--- a/compiler/compiled_method.h
+++ b/compiler/compiled_method.h
@@ -23,10 +23,10 @@
#include <vector>
#include "arch/instruction_set.h"
+#include "base/array_ref.h"
#include "base/bit_utils.h"
#include "base/length_prefixed_array.h"
#include "method_reference.h"
-#include "utils/array_ref.h"
namespace art {
diff --git a/compiler/compiler.h b/compiler/compiler.h
index ed42958..9a69456 100644
--- a/compiler/compiler.h
+++ b/compiler/compiler.h
@@ -25,10 +25,14 @@
namespace jit {
class JitCodeCache;
}
+namespace mirror {
+ class DexCache;
+}
class ArtMethod;
class CompilerDriver;
class CompiledMethod;
+template<class T> class Handle;
class OatWriter;
class Compiler {
diff --git a/compiler/debug/dwarf/headers.h b/compiler/debug/dwarf/headers.h
index 146d9fd..28f1084 100644
--- a/compiler/debug/dwarf/headers.h
+++ b/compiler/debug/dwarf/headers.h
@@ -19,13 +19,13 @@
#include <cstdint>
+#include "base/array_ref.h"
#include "debug/dwarf/debug_frame_opcode_writer.h"
#include "debug/dwarf/debug_info_entry_writer.h"
#include "debug/dwarf/debug_line_opcode_writer.h"
#include "debug/dwarf/dwarf_constants.h"
#include "debug/dwarf/register.h"
#include "debug/dwarf/writer.h"
-#include "utils/array_ref.h"
namespace art {
namespace dwarf {
diff --git a/compiler/debug/elf_debug_writer.cc b/compiler/debug/elf_debug_writer.cc
index 5bfdd16..d1c10a9 100644
--- a/compiler/debug/elf_debug_writer.cc
+++ b/compiler/debug/elf_debug_writer.cc
@@ -18,6 +18,7 @@
#include <vector>
+#include "base/array_ref.h"
#include "debug/dwarf/dwarf_constants.h"
#include "debug/elf_compilation_unit.h"
#include "debug/elf_debug_frame_writer.h"
@@ -29,7 +30,6 @@
#include "debug/method_debug_info.h"
#include "elf_builder.h"
#include "linker/vector_output_stream.h"
-#include "utils/array_ref.h"
namespace art {
namespace debug {
diff --git a/compiler/debug/elf_debug_writer.h b/compiler/debug/elf_debug_writer.h
index b0542c7..07f7229 100644
--- a/compiler/debug/elf_debug_writer.h
+++ b/compiler/debug/elf_debug_writer.h
@@ -19,11 +19,11 @@
#include <vector>
+#include "base/array_ref.h"
#include "base/macros.h"
#include "base/mutex.h"
#include "debug/dwarf/dwarf_constants.h"
#include "elf_builder.h"
-#include "utils/array_ref.h"
namespace art {
class OatHeader;
diff --git a/compiler/driver/compiled_method_storage.h b/compiler/driver/compiled_method_storage.h
index 8674abf..124b5a6 100644
--- a/compiler/driver/compiled_method_storage.h
+++ b/compiler/driver/compiled_method_storage.h
@@ -20,9 +20,9 @@
#include <iosfwd>
#include <memory>
+#include "base/array_ref.h"
#include "base/length_prefixed_array.h"
#include "base/macros.h"
-#include "utils/array_ref.h"
#include "utils/dedupe_set.h"
#include "utils/swap_space.h"
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index 53e068e..a149c07 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -26,6 +26,7 @@
#include "art_field-inl.h"
#include "art_method-inl.h"
+#include "base/array_ref.h"
#include "base/bit_vector.h"
#include "base/enums.h"
#include "base/stl_util.h"
@@ -67,7 +68,6 @@
#include "thread_pool.h"
#include "trampolines/trampoline_compiler.h"
#include "transaction.h"
-#include "utils/array_ref.h"
#include "utils/dex_cache_arrays_layout-inl.h"
#include "utils/swap_space.h"
#include "verifier/method_verifier.h"
@@ -2474,7 +2474,7 @@
// mode which prevents the GC from visiting objects modified during the transaction.
// Ensure GC is not run so don't access freed objects when aborting transaction.
- ScopedAssertNoThreadSuspension ants(soa.Self(), "Transaction end");
+ ScopedAssertNoThreadSuspension ants("Transaction end");
runtime->ExitTransactionMode();
if (!success) {
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index fbc1edd..ee21efa 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -24,6 +24,7 @@
#include "arch/instruction_set.h"
#include "base/arena_allocator.h"
+#include "base/array_ref.h"
#include "base/bit_utils.h"
#include "base/mutex.h"
#include "base/timing_logger.h"
@@ -39,7 +40,6 @@
#include "runtime.h"
#include "safe_map.h"
#include "thread_pool.h"
-#include "utils/array_ref.h"
#include "utils/dex_cache_arrays_layout.h"
namespace art {
diff --git a/compiler/elf_builder.h b/compiler/elf_builder.h
index 7f2e193..02831c9 100644
--- a/compiler/elf_builder.h
+++ b/compiler/elf_builder.h
@@ -21,13 +21,13 @@
#include "arch/instruction_set.h"
#include "arch/mips/instruction_set_features_mips.h"
+#include "base/array_ref.h"
#include "base/bit_utils.h"
#include "base/casts.h"
#include "base/unix_file/fd_file.h"
#include "elf_utils.h"
#include "leb128.h"
#include "linker/error_delaying_output_stream.h"
-#include "utils/array_ref.h"
namespace art {
diff --git a/compiler/elf_writer.h b/compiler/elf_writer.h
index c9ea0083..f8f9102 100644
--- a/compiler/elf_writer.h
+++ b/compiler/elf_writer.h
@@ -22,10 +22,10 @@
#include <string>
#include <vector>
+#include "base/array_ref.h"
#include "base/macros.h"
#include "base/mutex.h"
#include "os.h"
-#include "utils/array_ref.h"
namespace art {
diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc
index 7634510..6d86f7d 100644
--- a/compiler/image_writer.cc
+++ b/compiler/image_writer.cc
@@ -868,7 +868,7 @@
// Clear references to removed classes from the DexCaches.
ArtMethod* resolution_method = runtime->GetResolutionMethod();
- ScopedAssertNoThreadSuspension sa(self, __FUNCTION__);
+ ScopedAssertNoThreadSuspension sa(__FUNCTION__);
ReaderMutexLock mu(self, *Locks::classlinker_classes_lock_); // For ClassInClassTable
ReaderMutexLock mu2(self, *class_linker->DexLock());
for (const ClassLinker::DexCacheData& data : class_linker->GetDexCachesData()) {
diff --git a/compiler/jni/quick/calling_convention.h b/compiler/jni/quick/calling_convention.h
index 3d89146..f541d8f 100644
--- a/compiler/jni/quick/calling_convention.h
+++ b/compiler/jni/quick/calling_convention.h
@@ -18,11 +18,11 @@
#define ART_COMPILER_JNI_QUICK_CALLING_CONVENTION_H_
#include "base/arena_object.h"
+#include "base/array_ref.h"
#include "base/enums.h"
#include "handle_scope.h"
#include "primitive.h"
#include "thread.h"
-#include "utils/array_ref.h"
#include "utils/managed_register.h"
namespace art {
diff --git a/compiler/linker/arm64/relative_patcher_arm64.h b/compiler/linker/arm64/relative_patcher_arm64.h
index 48ad105..a4a8018 100644
--- a/compiler/linker/arm64/relative_patcher_arm64.h
+++ b/compiler/linker/arm64/relative_patcher_arm64.h
@@ -17,8 +17,8 @@
#ifndef ART_COMPILER_LINKER_ARM64_RELATIVE_PATCHER_ARM64_H_
#define ART_COMPILER_LINKER_ARM64_RELATIVE_PATCHER_ARM64_H_
+#include "base/array_ref.h"
#include "linker/arm/relative_patcher_arm_base.h"
-#include "utils/array_ref.h"
namespace art {
namespace linker {
diff --git a/compiler/linker/relative_patcher.h b/compiler/linker/relative_patcher.h
index a22b9f2..15e955b 100644
--- a/compiler/linker/relative_patcher.h
+++ b/compiler/linker/relative_patcher.h
@@ -21,9 +21,9 @@
#include "arch/instruction_set.h"
#include "arch/instruction_set_features.h"
+#include "base/array_ref.h"
#include "base/macros.h"
#include "method_reference.h"
-#include "utils/array_ref.h"
namespace art {
diff --git a/compiler/linker/relative_patcher_test.h b/compiler/linker/relative_patcher_test.h
index d21f33e..304b31c 100644
--- a/compiler/linker/relative_patcher_test.h
+++ b/compiler/linker/relative_patcher_test.h
@@ -19,6 +19,7 @@
#include "arch/instruction_set.h"
#include "arch/instruction_set_features.h"
+#include "base/array_ref.h"
#include "base/macros.h"
#include "compiled_method.h"
#include "dex/quick/dex_file_to_method_inliner_map.h"
@@ -31,7 +32,6 @@
#include "method_reference.h"
#include "oat.h"
#include "oat_quick_method_header.h"
-#include "utils/array_ref.h"
#include "vector_output_stream.h"
namespace art {
diff --git a/compiler/oat_test.cc b/compiler/oat_test.cc
index 78e9ca9..24d102d 100644
--- a/compiler/oat_test.cc
+++ b/compiler/oat_test.cc
@@ -453,7 +453,7 @@
EXPECT_EQ(72U, sizeof(OatHeader));
EXPECT_EQ(4U, sizeof(OatMethodOffsets));
EXPECT_EQ(20U, sizeof(OatQuickMethodHeader));
- EXPECT_EQ(164 * static_cast<size_t>(GetInstructionSetPointerSize(kRuntimeISA)),
+ EXPECT_EQ(163 * static_cast<size_t>(GetInstructionSetPointerSize(kRuntimeISA)),
sizeof(QuickEntryPoints));
}
diff --git a/compiler/oat_writer.cc b/compiler/oat_writer.cc
index 43e01d5..5e0c64b 100644
--- a/compiler/oat_writer.cc
+++ b/compiler/oat_writer.cc
@@ -994,7 +994,7 @@
out_(out),
file_offset_(file_offset),
soa_(Thread::Current()),
- no_thread_suspension_(soa_.Self(), "OatWriter patching"),
+ no_thread_suspension_("OatWriter patching"),
class_linker_(Runtime::Current()->GetClassLinker()),
dex_cache_(nullptr) {
patched_code_.reserve(16 * KB);
@@ -1036,7 +1036,7 @@
const CompiledMethod* compiled_method = oat_class->GetCompiledMethod(class_def_method_index);
// No thread suspension since dex_cache_ that may get invalidated if that occurs.
- ScopedAssertNoThreadSuspension tsc(Thread::Current(), __FUNCTION__);
+ ScopedAssertNoThreadSuspension tsc(__FUNCTION__);
if (compiled_method != nullptr) { // ie. not an abstract method
size_t file_offset = file_offset_;
OutputStream* out = out_;
diff --git a/compiler/oat_writer.h b/compiler/oat_writer.h
index 77525f1..dd7d699 100644
--- a/compiler/oat_writer.h
+++ b/compiler/oat_writer.h
@@ -21,6 +21,7 @@
#include <cstddef>
#include <memory>
+#include "base/array_ref.h"
#include "base/dchecked_vector.h"
#include "linker/relative_patcher.h" // For linker::RelativePatcherTargetProvider.
#include "mem_map.h"
@@ -29,7 +30,6 @@
#include "oat.h"
#include "os.h"
#include "safe_map.h"
-#include "utils/array_ref.h"
namespace art {
diff --git a/compiler/optimizing/code_generator_arm.h b/compiler/optimizing/code_generator_arm.h
index ce9d7e6..38a2410 100644
--- a/compiler/optimizing/code_generator_arm.h
+++ b/compiler/optimizing/code_generator_arm.h
@@ -556,10 +556,10 @@
// artReadBarrierForRootSlow.
void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root);
- void GenerateNop();
+ void GenerateNop() OVERRIDE;
- void GenerateImplicitNullCheck(HNullCheck* instruction);
- void GenerateExplicitNullCheck(HNullCheck* instruction);
+ void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE;
+ void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE;
private:
Register GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, Register temp);
diff --git a/compiler/optimizing/code_generator_arm64.cc b/compiler/optimizing/code_generator_arm64.cc
index c00ab56..599185a 100644
--- a/compiler/optimizing/code_generator_arm64.cc
+++ b/compiler/optimizing/code_generator_arm64.cc
@@ -448,7 +448,7 @@
}
const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; }
- bool IsFatal() const { return is_fatal_; }
+ bool IsFatal() const OVERRIDE { return is_fatal_; }
private:
const bool is_fatal_;
diff --git a/compiler/optimizing/code_generator_arm64.h b/compiler/optimizing/code_generator_arm64.h
index f0d7910..f1dc7ee 100644
--- a/compiler/optimizing/code_generator_arm64.h
+++ b/compiler/optimizing/code_generator_arm64.h
@@ -644,10 +644,10 @@
// artReadBarrierForRootSlow.
void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root);
- void GenerateNop();
+ void GenerateNop() OVERRIDE;
- void GenerateImplicitNullCheck(HNullCheck* instruction);
- void GenerateExplicitNullCheck(HNullCheck* instruction);
+ void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE;
+ void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE;
private:
using Uint64ToLiteralMap = ArenaSafeMap<uint64_t, vixl::aarch64::Literal<uint64_t>*>;
diff --git a/compiler/optimizing/code_generator_mips.cc b/compiler/optimizing/code_generator_mips.cc
index fdfc551..b767aa5 100644
--- a/compiler/optimizing/code_generator_mips.cc
+++ b/compiler/optimizing/code_generator_mips.cc
@@ -5817,13 +5817,11 @@
locations->SetInAt(0, Location::RequiresRegister());
}
-void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
- int32_t lower_bound = switch_instr->GetStartValue();
- int32_t num_entries = switch_instr->GetNumEntries();
- LocationSummary* locations = switch_instr->GetLocations();
- Register value_reg = locations->InAt(0).AsRegister<Register>();
- HBasicBlock* default_block = switch_instr->GetDefaultBlock();
-
+void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg,
+ int32_t lower_bound,
+ uint32_t num_entries,
+ HBasicBlock* switch_block,
+ HBasicBlock* default_block) {
// Create a set of compare/jumps.
Register temp_reg = TMP;
__ Addiu32(temp_reg, value_reg, -lower_bound);
@@ -5832,7 +5830,7 @@
// this case, index >= num_entries must be true. So that we can save one branch instruction.
__ Bltz(temp_reg, codegen_->GetLabelOf(default_block));
- const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
+ const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
// Jump to successors[0] if value == lower_bound.
__ Beqz(temp_reg, codegen_->GetLabelOf(successors[0]));
int32_t last_index = 0;
@@ -5850,11 +5848,107 @@
}
// And the default for any other value.
- if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
+ if (!codegen_->GoesToNextBlock(switch_block, default_block)) {
__ B(codegen_->GetLabelOf(default_block));
}
}
+void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg,
+ Register constant_area,
+ int32_t lower_bound,
+ uint32_t num_entries,
+ HBasicBlock* switch_block,
+ HBasicBlock* default_block) {
+ // Create a jump table.
+ std::vector<MipsLabel*> labels(num_entries);
+ const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
+ for (uint32_t i = 0; i < num_entries; i++) {
+ labels[i] = codegen_->GetLabelOf(successors[i]);
+ }
+ JumpTable* table = __ CreateJumpTable(std::move(labels));
+
+ // Is the value in range?
+ __ Addiu32(TMP, value_reg, -lower_bound);
+ if (IsInt<16>(static_cast<int32_t>(num_entries))) {
+ __ Sltiu(AT, TMP, num_entries);
+ __ Beqz(AT, codegen_->GetLabelOf(default_block));
+ } else {
+ __ LoadConst32(AT, num_entries);
+ __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block));
+ }
+
+ // We are in the range of the table.
+ // Load the target address from the jump table, indexing by the value.
+ __ LoadLabelAddress(AT, constant_area, table->GetLabel());
+ __ Sll(TMP, TMP, 2);
+ __ Addu(TMP, TMP, AT);
+ __ Lw(TMP, TMP, 0);
+ // Compute the absolute target address by adding the table start address
+ // (the table contains offsets to targets relative to its start).
+ __ Addu(TMP, TMP, AT);
+ // And jump.
+ __ Jr(TMP);
+ __ NopIfNoReordering();
+}
+
+void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
+ int32_t lower_bound = switch_instr->GetStartValue();
+ uint32_t num_entries = switch_instr->GetNumEntries();
+ LocationSummary* locations = switch_instr->GetLocations();
+ Register value_reg = locations->InAt(0).AsRegister<Register>();
+ HBasicBlock* switch_block = switch_instr->GetBlock();
+ HBasicBlock* default_block = switch_instr->GetDefaultBlock();
+
+ if (codegen_->GetInstructionSetFeatures().IsR6() &&
+ num_entries > kPackedSwitchJumpTableThreshold) {
+ // R6 uses PC-relative addressing to access the jump table.
+ // R2, OTOH, requires an HMipsComputeBaseMethodAddress input to access
+ // the jump table and it is implemented by changing HPackedSwitch to
+ // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress.
+ // See VisitMipsPackedSwitch() for the table-based implementation on R2.
+ GenTableBasedPackedSwitch(value_reg,
+ ZERO,
+ lower_bound,
+ num_entries,
+ switch_block,
+ default_block);
+ } else {
+ GenPackedSwitchWithCompares(value_reg,
+ lower_bound,
+ num_entries,
+ switch_block,
+ default_block);
+ }
+}
+
+void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) {
+ LocationSummary* locations =
+ new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
+ locations->SetInAt(0, Location::RequiresRegister());
+ // Constant area pointer (HMipsComputeBaseMethodAddress).
+ locations->SetInAt(1, Location::RequiresRegister());
+}
+
+void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) {
+ int32_t lower_bound = switch_instr->GetStartValue();
+ uint32_t num_entries = switch_instr->GetNumEntries();
+ LocationSummary* locations = switch_instr->GetLocations();
+ Register value_reg = locations->InAt(0).AsRegister<Register>();
+ Register constant_area = locations->InAt(1).AsRegister<Register>();
+ HBasicBlock* switch_block = switch_instr->GetBlock();
+ HBasicBlock* default_block = switch_instr->GetDefaultBlock();
+
+ // This is an R2-only path. HPackedSwitch has been changed to
+ // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress
+ // required to address the jump table relative to PC.
+ GenTableBasedPackedSwitch(value_reg,
+ constant_area,
+ lower_bound,
+ num_entries,
+ switch_block,
+ default_block);
+}
+
void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress(
HMipsComputeBaseMethodAddress* insn) {
LocationSummary* locations =
diff --git a/compiler/optimizing/code_generator_mips.h b/compiler/optimizing/code_generator_mips.h
index 0039981..a42374f 100644
--- a/compiler/optimizing/code_generator_mips.h
+++ b/compiler/optimizing/code_generator_mips.h
@@ -218,6 +218,14 @@
MipsAssembler* GetAssembler() const { return assembler_; }
+ // Compare-and-jump packed switch generates approx. 3 + 2.5 * N 32-bit
+ // instructions for N cases.
+ // Table-based packed switch generates approx. 11 32-bit instructions
+ // and N 32-bit data words for N cases.
+ // At N = 6 they come out as 18 and 17 32-bit words respectively.
+ // We switch to the table-based method starting with 7 cases.
+ static constexpr uint32_t kPackedSwitchJumpTableThreshold = 6;
+
private:
void GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, Register class_reg);
void GenerateMemoryBarrier(MemBarrierKind kind);
@@ -262,6 +270,17 @@
void GenerateDivRemIntegral(HBinaryOperation* instruction);
void HandleGoto(HInstruction* got, HBasicBlock* successor);
auto GetImplicitNullChecker(HInstruction* instruction);
+ void GenPackedSwitchWithCompares(Register value_reg,
+ int32_t lower_bound,
+ uint32_t num_entries,
+ HBasicBlock* switch_block,
+ HBasicBlock* default_block);
+ void GenTableBasedPackedSwitch(Register value_reg,
+ Register constant_area,
+ int32_t lower_bound,
+ uint32_t num_entries,
+ HBasicBlock* switch_block,
+ HBasicBlock* default_block);
MipsAssembler* const assembler_;
CodeGeneratorMIPS* const codegen_;
@@ -310,10 +329,10 @@
void SetupBlockedRegisters() const OVERRIDE;
- size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id);
- size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id);
- size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id);
- size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id);
+ size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
+ size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
+ size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
+ size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
void ClobberRA() {
clobbered_ra_ = true;
}
@@ -344,7 +363,7 @@
void MoveLocation(Location dst, Location src, Primitive::Type dst_type) OVERRIDE;
- void MoveConstant(Location destination, int32_t value);
+ void MoveConstant(Location destination, int32_t value) OVERRIDE;
void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE;
@@ -356,7 +375,7 @@
ParallelMoveResolver* GetMoveResolver() OVERRIDE { return &move_resolver_; }
- bool NeedsTwoRegisters(Primitive::Type type) const {
+ bool NeedsTwoRegisters(Primitive::Type type) const OVERRIDE {
return type == Primitive::kPrimLong;
}
@@ -384,9 +403,9 @@
UNIMPLEMENTED(FATAL) << "Not implemented on MIPS";
}
- void GenerateNop();
- void GenerateImplicitNullCheck(HNullCheck* instruction);
- void GenerateExplicitNullCheck(HNullCheck* instruction);
+ void GenerateNop() OVERRIDE;
+ void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE;
+ void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE;
// The PcRelativePatchInfo is used for PC-relative addressing of dex cache arrays
// and boot image strings. The only difference is the interpretation of the offset_or_index.
diff --git a/compiler/optimizing/code_generator_mips64.h b/compiler/optimizing/code_generator_mips64.h
index 3910530..2dd409a 100644
--- a/compiler/optimizing/code_generator_mips64.h
+++ b/compiler/optimizing/code_generator_mips64.h
@@ -285,10 +285,10 @@
void SetupBlockedRegisters() const OVERRIDE;
- size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id);
- size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id);
- size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id);
- size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id);
+ size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
+ size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
+ size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
+ size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE;
void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE;
@@ -327,7 +327,7 @@
ParallelMoveResolver* GetMoveResolver() OVERRIDE { return &move_resolver_; }
- bool NeedsTwoRegisters(Primitive::Type type ATTRIBUTE_UNUSED) const { return false; }
+ bool NeedsTwoRegisters(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { return false; }
// Check if the desired_string_load_kind is supported. If it is, return it,
// otherwise return a fall-back kind that should be used instead.
@@ -353,9 +353,9 @@
UNIMPLEMENTED(FATAL) << "Not implemented on MIPS64";
}
- void GenerateNop();
- void GenerateImplicitNullCheck(HNullCheck* instruction);
- void GenerateExplicitNullCheck(HNullCheck* instruction);
+ void GenerateNop() OVERRIDE;
+ void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE;
+ void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE;
private:
// Labels for each block that will be compiled.
diff --git a/compiler/optimizing/code_generator_x86.h b/compiler/optimizing/code_generator_x86.h
index e225098..04a0a3d 100644
--- a/compiler/optimizing/code_generator_x86.h
+++ b/compiler/optimizing/code_generator_x86.h
@@ -561,9 +561,9 @@
}
}
- void GenerateNop();
- void GenerateImplicitNullCheck(HNullCheck* instruction);
- void GenerateExplicitNullCheck(HNullCheck* instruction);
+ void GenerateNop() OVERRIDE;
+ void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE;
+ void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE;
// When we don't know the proper offset for the value, we use kDummy32BitOffset.
// The correct value will be inserted when processing Assembler fixups.
diff --git a/compiler/optimizing/code_generator_x86_64.h b/compiler/optimizing/code_generator_x86_64.h
index d939083..693d0b8 100644
--- a/compiler/optimizing/code_generator_x86_64.h
+++ b/compiler/optimizing/code_generator_x86_64.h
@@ -533,9 +533,9 @@
}
}
- void GenerateNop();
- void GenerateImplicitNullCheck(HNullCheck* instruction);
- void GenerateExplicitNullCheck(HNullCheck* instruction);
+ void GenerateNop() OVERRIDE;
+ void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE;
+ void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE;
// When we don't know the proper offset for the value, we use kDummy32BitOffset.
// We will fix this up in the linker later to have the right value.
diff --git a/compiler/optimizing/codegen_test.cc b/compiler/optimizing/codegen_test.cc
index d9347f6..070cbb3 100644
--- a/compiler/optimizing/codegen_test.cc
+++ b/compiler/optimizing/codegen_test.cc
@@ -1007,17 +1007,7 @@
}
TEST_F(CodegenTest, ComparisonsLong) {
- // TODO: make MIPS work for long
- if (kRuntimeISA == kMips || kRuntimeISA == kMips64) {
- return;
- }
-
for (CodegenTargetConfig target_config : GetTargetConfigs()) {
- if ((target_config.GetInstructionSet() == kMips) ||
- (target_config.GetInstructionSet() == kMips64)) {
- continue;
- }
-
for (int64_t i = -1; i <= 1; i++) {
for (int64_t j = -1; j <= 1; j++) {
for (int cond = kCondFirst; cond <= kCondLast; cond++) {
diff --git a/compiler/optimizing/dead_code_elimination.cc b/compiler/optimizing/dead_code_elimination.cc
index e1bde7c..aa3f268 100644
--- a/compiler/optimizing/dead_code_elimination.cc
+++ b/compiler/optimizing/dead_code_elimination.cc
@@ -16,7 +16,7 @@
#include "dead_code_elimination.h"
-#include "utils/array_ref.h"
+#include "base/array_ref.h"
#include "base/bit_vector-inl.h"
#include "ssa_phi_elimination.h"
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc
index 8f37236..9cfa89b 100644
--- a/compiler/optimizing/nodes.cc
+++ b/compiler/optimizing/nodes.cc
@@ -460,6 +460,113 @@
return kAnalysisSuccess;
}
+static bool InSameLoop(HLoopInformation* first_loop, HLoopInformation* second_loop) {
+ return first_loop == second_loop;
+}
+
+static bool IsLoop(HLoopInformation* info) {
+ return info != nullptr;
+}
+
+static bool IsInnerLoop(HLoopInformation* outer, HLoopInformation* inner) {
+ return (inner != outer)
+ && (inner != nullptr)
+ && (outer != nullptr)
+ && inner->IsIn(*outer);
+}
+
+// Helper method to update work list for linear order.
+static void AddToListForLinearization(ArenaVector<HBasicBlock*>* worklist, HBasicBlock* block) {
+ HLoopInformation* block_loop = block->GetLoopInformation();
+ auto insert_pos = worklist->rbegin(); // insert_pos.base() will be the actual position.
+ for (auto end = worklist->rend(); insert_pos != end; ++insert_pos) {
+ HBasicBlock* current = *insert_pos;
+ HLoopInformation* current_loop = current->GetLoopInformation();
+ if (InSameLoop(block_loop, current_loop)
+ || !IsLoop(current_loop)
+ || IsInnerLoop(current_loop, block_loop)) {
+ // The block can be processed immediately.
+ break;
+ }
+ }
+ worklist->insert(insert_pos.base(), block);
+}
+
+// Helper method to validate linear order.
+static bool IsLinearOrderWellFormed(const HGraph& graph) {
+ for (HBasicBlock* header : graph.GetBlocks()) {
+ if (header == nullptr || !header->IsLoopHeader()) {
+ continue;
+ }
+ HLoopInformation* loop = header->GetLoopInformation();
+ size_t num_blocks = loop->GetBlocks().NumSetBits();
+ size_t found_blocks = 0u;
+ for (HLinearOrderIterator it(graph); !it.Done(); it.Advance()) {
+ HBasicBlock* current = it.Current();
+ if (loop->Contains(*current)) {
+ found_blocks++;
+ if (found_blocks == 1u && current != header) {
+ // First block is not the header.
+ return false;
+ } else if (found_blocks == num_blocks && !loop->IsBackEdge(*current)) {
+ // Last block is not a back edge.
+ return false;
+ }
+ } else if (found_blocks != 0u && found_blocks != num_blocks) {
+ // Blocks are not adjacent.
+ return false;
+ }
+ }
+ DCHECK_EQ(found_blocks, num_blocks);
+ }
+ return true;
+}
+
+void HGraph::Linearize() {
+ // Create a reverse post ordering with the following properties:
+ // - Blocks in a loop are consecutive,
+ // - Back-edge is the last block before loop exits.
+
+ // (1): Record the number of forward predecessors for each block. This is to
+ // ensure the resulting order is reverse post order. We could use the
+ // current reverse post order in the graph, but it would require making
+ // order queries to a GrowableArray, which is not the best data structure
+ // for it.
+ ArenaVector<uint32_t> forward_predecessors(blocks_.size(),
+ arena_->Adapter(kArenaAllocSsaLiveness));
+ for (HReversePostOrderIterator it(*this); !it.Done(); it.Advance()) {
+ HBasicBlock* block = it.Current();
+ size_t number_of_forward_predecessors = block->GetPredecessors().size();
+ if (block->IsLoopHeader()) {
+ number_of_forward_predecessors -= block->GetLoopInformation()->NumberOfBackEdges();
+ }
+ forward_predecessors[block->GetBlockId()] = number_of_forward_predecessors;
+ }
+
+ // (2): Following a worklist approach, first start with the entry block, and
+ // iterate over the successors. When all non-back edge predecessors of a
+ // successor block are visited, the successor block is added in the worklist
+ // following an order that satisfies the requirements to build our linear graph.
+ linear_order_.reserve(GetReversePostOrder().size());
+ ArenaVector<HBasicBlock*> worklist(arena_->Adapter(kArenaAllocSsaLiveness));
+ worklist.push_back(GetEntryBlock());
+ do {
+ HBasicBlock* current = worklist.back();
+ worklist.pop_back();
+ linear_order_.push_back(current);
+ for (HBasicBlock* successor : current->GetSuccessors()) {
+ int block_id = successor->GetBlockId();
+ size_t number_of_remaining_predecessors = forward_predecessors[block_id];
+ if (number_of_remaining_predecessors == 1) {
+ AddToListForLinearization(&worklist, successor);
+ }
+ forward_predecessors[block_id] = number_of_remaining_predecessors - 1;
+ }
+ } while (!worklist.empty());
+
+ DCHECK(HasIrreducibleLoops() || IsLinearOrderWellFormed(*this));
+}
+
void HLoopInformation::Dump(std::ostream& os) {
os << "header: " << header_->GetBlockId() << std::endl;
os << "pre header: " << GetPreHeader()->GetBlockId() << std::endl;
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index 99d7673..7c3ca5c 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -24,7 +24,9 @@
#include "base/arena_bit_vector.h"
#include "base/arena_containers.h"
#include "base/arena_object.h"
+#include "base/array_ref.h"
#include "base/stl_util.h"
+#include "base/transform_array_ref.h"
#include "dex_file.h"
#include "entrypoints/quick/quick_entrypoints_enum.h"
#include "handle.h"
@@ -35,9 +37,7 @@
#include "mirror/class.h"
#include "offsets.h"
#include "primitive.h"
-#include "utils/array_ref.h"
#include "utils/intrusive_forward_list.h"
-#include "utils/transform_array_ref.h"
namespace art {
@@ -365,6 +365,13 @@
// is a throw-catch loop, i.e. the header is a catch block.
GraphAnalysisResult AnalyzeLoops() const;
+ // Computes the linear order (should be called before using HLinearOrderIterator).
+ // Linearizes the graph such that:
+ // (1): a block is always after its dominator,
+ // (2): blocks of loops are contiguous.
+ // This creates a natural and efficient ordering when visualizing live ranges.
+ void Linearize();
+
// Iterate over blocks to compute try block membership. Needs reverse post
// order and loop information.
void ComputeTryBlockInformation();
@@ -1314,7 +1321,8 @@
#else
#define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \
M(MipsComputeBaseMethodAddress, Instruction) \
- M(MipsDexCacheArraysBase, Instruction)
+ M(MipsDexCacheArraysBase, Instruction) \
+ M(MipsPackedSwitch, Instruction)
#endif
#define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M)
diff --git a/compiler/optimizing/nodes_mips.h b/compiler/optimizing/nodes_mips.h
index de77245..36431c1 100644
--- a/compiler/optimizing/nodes_mips.h
+++ b/compiler/optimizing/nodes_mips.h
@@ -66,6 +66,41 @@
DISALLOW_COPY_AND_ASSIGN(HMipsDexCacheArraysBase);
};
+// Mips version of HPackedSwitch that holds a pointer to the base method address.
+class HMipsPackedSwitch FINAL : public HTemplateInstruction<2> {
+ public:
+ HMipsPackedSwitch(int32_t start_value,
+ int32_t num_entries,
+ HInstruction* input,
+ HMipsComputeBaseMethodAddress* method_base,
+ uint32_t dex_pc)
+ : HTemplateInstruction(SideEffects::None(), dex_pc),
+ start_value_(start_value),
+ num_entries_(num_entries) {
+ SetRawInputAt(0, input);
+ SetRawInputAt(1, method_base);
+ }
+
+ bool IsControlFlow() const OVERRIDE { return true; }
+
+ int32_t GetStartValue() const { return start_value_; }
+
+ int32_t GetNumEntries() const { return num_entries_; }
+
+ HBasicBlock* GetDefaultBlock() const {
+ // Last entry is the default block.
+ return GetBlock()->GetSuccessors()[num_entries_];
+ }
+
+ DECLARE_INSTRUCTION(MipsPackedSwitch);
+
+ private:
+ const int32_t start_value_;
+ const int32_t num_entries_;
+
+ DISALLOW_COPY_AND_ASSIGN(HMipsPackedSwitch);
+};
+
} // namespace art
#endif // ART_COMPILER_OPTIMIZING_NODES_MIPS_H_
diff --git a/compiler/optimizing/pc_relative_fixups_mips.cc b/compiler/optimizing/pc_relative_fixups_mips.cc
index c6d297d..6006e6c 100644
--- a/compiler/optimizing/pc_relative_fixups_mips.cc
+++ b/compiler/optimizing/pc_relative_fixups_mips.cc
@@ -92,6 +92,25 @@
}
}
+ void VisitPackedSwitch(HPackedSwitch* switch_insn) OVERRIDE {
+ if (switch_insn->GetNumEntries() <=
+ InstructionCodeGeneratorMIPS::kPackedSwitchJumpTableThreshold) {
+ return;
+ }
+ // We need to replace the HPackedSwitch with a HMipsPackedSwitch in order to
+ // address the constant area.
+ InitializePCRelativeBasePointer();
+ HGraph* graph = GetGraph();
+ HBasicBlock* block = switch_insn->GetBlock();
+ HMipsPackedSwitch* mips_switch = new (graph->GetArena()) HMipsPackedSwitch(
+ switch_insn->GetStartValue(),
+ switch_insn->GetNumEntries(),
+ switch_insn->InputAt(0),
+ base_,
+ switch_insn->GetDexPc());
+ block->ReplaceAndRemoveInstructionWith(switch_insn, mips_switch);
+ }
+
void HandleInvoke(HInvoke* invoke) {
// If this is an invoke-static/-direct with PC-relative dex cache array
// addressing, we need the PC-relative address base.
diff --git a/compiler/optimizing/register_allocation_resolver.h b/compiler/optimizing/register_allocation_resolver.h
index a70ceae..d48b1a0 100644
--- a/compiler/optimizing/register_allocation_resolver.h
+++ b/compiler/optimizing/register_allocation_resolver.h
@@ -18,9 +18,9 @@
#define ART_COMPILER_OPTIMIZING_REGISTER_ALLOCATION_RESOLVER_H_
#include "base/arena_containers.h"
+#include "base/array_ref.h"
#include "base/value_object.h"
#include "primitive.h"
-#include "utils/array_ref.h"
namespace art {
diff --git a/compiler/optimizing/ssa_liveness_analysis.cc b/compiler/optimizing/ssa_liveness_analysis.cc
index a4d52d7..9ce34aa 100644
--- a/compiler/optimizing/ssa_liveness_analysis.cc
+++ b/compiler/optimizing/ssa_liveness_analysis.cc
@@ -23,119 +23,11 @@
namespace art {
void SsaLivenessAnalysis::Analyze() {
- LinearizeGraph();
+ graph_->Linearize();
NumberInstructions();
ComputeLiveness();
}
-static bool IsLoop(HLoopInformation* info) {
- return info != nullptr;
-}
-
-static bool InSameLoop(HLoopInformation* first_loop, HLoopInformation* second_loop) {
- return first_loop == second_loop;
-}
-
-static bool IsInnerLoop(HLoopInformation* outer, HLoopInformation* inner) {
- return (inner != outer)
- && (inner != nullptr)
- && (outer != nullptr)
- && inner->IsIn(*outer);
-}
-
-static void AddToListForLinearization(ArenaVector<HBasicBlock*>* worklist, HBasicBlock* block) {
- HLoopInformation* block_loop = block->GetLoopInformation();
- auto insert_pos = worklist->rbegin(); // insert_pos.base() will be the actual position.
- for (auto end = worklist->rend(); insert_pos != end; ++insert_pos) {
- HBasicBlock* current = *insert_pos;
- HLoopInformation* current_loop = current->GetLoopInformation();
- if (InSameLoop(block_loop, current_loop)
- || !IsLoop(current_loop)
- || IsInnerLoop(current_loop, block_loop)) {
- // The block can be processed immediately.
- break;
- }
- }
- worklist->insert(insert_pos.base(), block);
-}
-
-static bool IsLinearOrderWellFormed(const HGraph& graph) {
- for (HBasicBlock* header : graph.GetBlocks()) {
- if (header == nullptr || !header->IsLoopHeader()) {
- continue;
- }
-
- HLoopInformation* loop = header->GetLoopInformation();
- size_t num_blocks = loop->GetBlocks().NumSetBits();
- size_t found_blocks = 0u;
-
- for (HLinearOrderIterator it(graph); !it.Done(); it.Advance()) {
- HBasicBlock* current = it.Current();
- if (loop->Contains(*current)) {
- found_blocks++;
- if (found_blocks == 1u && current != header) {
- // First block is not the header.
- return false;
- } else if (found_blocks == num_blocks && !loop->IsBackEdge(*current)) {
- // Last block is not a back edge.
- return false;
- }
- } else if (found_blocks != 0u && found_blocks != num_blocks) {
- // Blocks are not adjacent.
- return false;
- }
- }
- DCHECK_EQ(found_blocks, num_blocks);
- }
-
- return true;
-}
-
-void SsaLivenessAnalysis::LinearizeGraph() {
- // Create a reverse post ordering with the following properties:
- // - Blocks in a loop are consecutive,
- // - Back-edge is the last block before loop exits.
-
- // (1): Record the number of forward predecessors for each block. This is to
- // ensure the resulting order is reverse post order. We could use the
- // current reverse post order in the graph, but it would require making
- // order queries to a GrowableArray, which is not the best data structure
- // for it.
- ArenaVector<uint32_t> forward_predecessors(graph_->GetBlocks().size(),
- graph_->GetArena()->Adapter(kArenaAllocSsaLiveness));
- for (HReversePostOrderIterator it(*graph_); !it.Done(); it.Advance()) {
- HBasicBlock* block = it.Current();
- size_t number_of_forward_predecessors = block->GetPredecessors().size();
- if (block->IsLoopHeader()) {
- number_of_forward_predecessors -= block->GetLoopInformation()->NumberOfBackEdges();
- }
- forward_predecessors[block->GetBlockId()] = number_of_forward_predecessors;
- }
-
- // (2): Following a worklist approach, first start with the entry block, and
- // iterate over the successors. When all non-back edge predecessors of a
- // successor block are visited, the successor block is added in the worklist
- // following an order that satisfies the requirements to build our linear graph.
- graph_->linear_order_.reserve(graph_->GetReversePostOrder().size());
- ArenaVector<HBasicBlock*> worklist(graph_->GetArena()->Adapter(kArenaAllocSsaLiveness));
- worklist.push_back(graph_->GetEntryBlock());
- do {
- HBasicBlock* current = worklist.back();
- worklist.pop_back();
- graph_->linear_order_.push_back(current);
- for (HBasicBlock* successor : current->GetSuccessors()) {
- int block_id = successor->GetBlockId();
- size_t number_of_remaining_predecessors = forward_predecessors[block_id];
- if (number_of_remaining_predecessors == 1) {
- AddToListForLinearization(&worklist, successor);
- }
- forward_predecessors[block_id] = number_of_remaining_predecessors - 1;
- }
- } while (!worklist.empty());
-
- DCHECK(graph_->HasIrreducibleLoops() || IsLinearOrderWellFormed(*graph_));
-}
-
void SsaLivenessAnalysis::NumberInstructions() {
int ssa_index = 0;
size_t lifetime_position = 0;
diff --git a/compiler/optimizing/ssa_liveness_analysis.h b/compiler/optimizing/ssa_liveness_analysis.h
index 0be1611..b62bf4e 100644
--- a/compiler/optimizing/ssa_liveness_analysis.h
+++ b/compiler/optimizing/ssa_liveness_analysis.h
@@ -1186,12 +1186,6 @@
static constexpr const char* kLivenessPassName = "liveness";
private:
- // Linearize the graph so that:
- // (1): a block is always after its dominator,
- // (2): blocks of loops are contiguous.
- // This creates a natural and efficient ordering when visualizing live ranges.
- void LinearizeGraph();
-
// Give an SSA number to each instruction that defines a value used by another instruction,
// and setup the lifetime information of each instruction and block.
void NumberInstructions();
diff --git a/compiler/utils/arm/assembler_thumb2.h b/compiler/utils/arm/assembler_thumb2.h
index 13f3bec..353555d 100644
--- a/compiler/utils/arm/assembler_thumb2.h
+++ b/compiler/utils/arm/assembler_thumb2.h
@@ -22,11 +22,11 @@
#include <vector>
#include "base/arena_containers.h"
+#include "base/array_ref.h"
#include "base/logging.h"
#include "constants_arm.h"
#include "utils/arm/managed_register_arm.h"
#include "utils/arm/assembler_arm.h"
-#include "utils/array_ref.h"
#include "offsets.h"
namespace art {
diff --git a/compiler/utils/arm/jni_macro_assembler_arm_vixl.cc b/compiler/utils/arm/jni_macro_assembler_arm_vixl.cc
index a03dd74..14d29c4 100644
--- a/compiler/utils/arm/jni_macro_assembler_arm_vixl.cc
+++ b/compiler/utils/arm/jni_macro_assembler_arm_vixl.cc
@@ -314,11 +314,21 @@
CHECK(src.IsCoreRegister()) << src;
___ Mov(dst.AsVIXLRegister(), src.AsVIXLRegister());
} else if (dst.IsDRegister()) {
- CHECK(src.IsDRegister()) << src;
- ___ Vmov(F64, dst.AsVIXLDRegister(), src.AsVIXLDRegister());
+ if (src.IsDRegister()) {
+ ___ Vmov(F64, dst.AsVIXLDRegister(), src.AsVIXLDRegister());
+ } else {
+ // VMOV Dn, Rlo, Rhi (Dn = {Rlo, Rhi})
+ CHECK(src.IsRegisterPair()) << src;
+ ___ Vmov(dst.AsVIXLDRegister(), src.AsVIXLRegisterPairLow(), src.AsVIXLRegisterPairHigh());
+ }
} else if (dst.IsSRegister()) {
- CHECK(src.IsSRegister()) << src;
- ___ Vmov(F32, dst.AsVIXLSRegister(), src.AsVIXLSRegister());
+ if (src.IsSRegister()) {
+ ___ Vmov(F32, dst.AsVIXLSRegister(), src.AsVIXLSRegister());
+ } else {
+ // VMOV Sn, Rn (Sn = Rn)
+ CHECK(src.IsCoreRegister()) << src;
+ ___ Vmov(dst.AsVIXLSRegister(), src.AsVIXLRegister());
+ }
} else {
CHECK(dst.IsRegisterPair()) << dst;
CHECK(src.IsRegisterPair()) << src;
diff --git a/compiler/utils/assembler.h b/compiler/utils/assembler.h
index b616057..314ff8c 100644
--- a/compiler/utils/assembler.h
+++ b/compiler/utils/assembler.h
@@ -24,6 +24,7 @@
#include "arm/constants_arm.h"
#include "base/arena_allocator.h"
#include "base/arena_object.h"
+#include "base/array_ref.h"
#include "base/enums.h"
#include "base/logging.h"
#include "base/macros.h"
@@ -33,7 +34,6 @@
#include "memory_region.h"
#include "mips/constants_mips.h"
#include "offsets.h"
-#include "utils/array_ref.h"
#include "x86/constants_x86.h"
#include "x86_64/constants_x86_64.h"
diff --git a/compiler/utils/dedupe_set_test.cc b/compiler/utils/dedupe_set_test.cc
index 60a891d..4c0979e 100644
--- a/compiler/utils/dedupe_set_test.cc
+++ b/compiler/utils/dedupe_set_test.cc
@@ -20,10 +20,10 @@
#include <cstdio>
#include <vector>
+#include "base/array_ref.h"
#include "dedupe_set-inl.h"
#include "gtest/gtest.h"
#include "thread-inl.h"
-#include "utils/array_ref.h"
namespace art {
diff --git a/compiler/utils/jni_macro_assembler.h b/compiler/utils/jni_macro_assembler.h
index 6f45bd6..0119ae9 100644
--- a/compiler/utils/jni_macro_assembler.h
+++ b/compiler/utils/jni_macro_assembler.h
@@ -22,12 +22,12 @@
#include "arch/instruction_set.h"
#include "base/arena_allocator.h"
#include "base/arena_object.h"
+#include "base/array_ref.h"
#include "base/enums.h"
#include "base/logging.h"
#include "base/macros.h"
#include "managed_register.h"
#include "offsets.h"
-#include "utils/array_ref.h"
namespace art {
diff --git a/compiler/utils/mips/assembler_mips.cc b/compiler/utils/mips/assembler_mips.cc
index 4b580b6..b972c70 100644
--- a/compiler/utils/mips/assembler_mips.cc
+++ b/compiler/utils/mips/assembler_mips.cc
@@ -230,12 +230,14 @@
DsFsmCommitLabel();
SetReorder(false);
EmitLiterals();
+ ReserveJumpTableSpace();
PromoteBranches();
}
void MipsAssembler::FinalizeInstructions(const MemoryRegion& region) {
size_t number_of_delayed_adjust_pcs = cfi().NumberOfDelayedAdvancePCs();
EmitBranches();
+ EmitJumpTables();
Assembler::FinalizeInstructions(region);
PatchCFI(number_of_delayed_adjust_pcs);
}
@@ -1724,47 +1726,68 @@
type_ = (offset_size <= branch_info_[short_type].offset_size) ? short_type : long_type;
}
-void MipsAssembler::Branch::InitializeType(bool is_call, bool is_literal, bool is_r6) {
- CHECK_EQ(is_call && is_literal, false);
+void MipsAssembler::Branch::InitializeType(Type initial_type, bool is_r6) {
OffsetBits offset_size = GetOffsetSizeNeeded(location_, target_);
if (is_r6) {
// R6
- if (is_literal) {
- CHECK(!IsResolved());
- type_ = kR6Literal;
- } else if (is_call) {
- InitShortOrLong(offset_size, kR6Call, kR6LongCall);
- } else {
- switch (condition_) {
- case kUncond:
- InitShortOrLong(offset_size, kR6UncondBranch, kR6LongUncondBranch);
- break;
- case kCondEQZ:
- case kCondNEZ:
- // Special case for beqzc/bnezc with longer offset than in other b<cond>c instructions.
- type_ = (offset_size <= kOffset23) ? kR6CondBranch : kR6LongCondBranch;
- break;
- default:
- InitShortOrLong(offset_size, kR6CondBranch, kR6LongCondBranch);
- break;
- }
+ switch (initial_type) {
+ case kLabel:
+ CHECK(!IsResolved());
+ type_ = kR6Label;
+ break;
+ case kLiteral:
+ CHECK(!IsResolved());
+ type_ = kR6Literal;
+ break;
+ case kCall:
+ InitShortOrLong(offset_size, kR6Call, kR6LongCall);
+ break;
+ case kCondBranch:
+ switch (condition_) {
+ case kUncond:
+ InitShortOrLong(offset_size, kR6UncondBranch, kR6LongUncondBranch);
+ break;
+ case kCondEQZ:
+ case kCondNEZ:
+ // Special case for beqzc/bnezc with longer offset than in other b<cond>c instructions.
+ type_ = (offset_size <= kOffset23) ? kR6CondBranch : kR6LongCondBranch;
+ break;
+ default:
+ InitShortOrLong(offset_size, kR6CondBranch, kR6LongCondBranch);
+ break;
+ }
+ break;
+ default:
+ LOG(FATAL) << "Unexpected branch type " << initial_type;
+ UNREACHABLE();
}
} else {
// R2
- if (is_literal) {
- CHECK(!IsResolved());
- type_ = kLiteral;
- } else if (is_call) {
- InitShortOrLong(offset_size, kCall, kLongCall);
- } else {
- switch (condition_) {
- case kUncond:
- InitShortOrLong(offset_size, kUncondBranch, kLongUncondBranch);
- break;
- default:
- InitShortOrLong(offset_size, kCondBranch, kLongCondBranch);
- break;
- }
+ switch (initial_type) {
+ case kLabel:
+ CHECK(!IsResolved());
+ type_ = kLabel;
+ break;
+ case kLiteral:
+ CHECK(!IsResolved());
+ type_ = kLiteral;
+ break;
+ case kCall:
+ InitShortOrLong(offset_size, kCall, kLongCall);
+ break;
+ case kCondBranch:
+ switch (condition_) {
+ case kUncond:
+ InitShortOrLong(offset_size, kUncondBranch, kLongUncondBranch);
+ break;
+ default:
+ InitShortOrLong(offset_size, kCondBranch, kLongCondBranch);
+ break;
+ }
+ break;
+ default:
+ LOG(FATAL) << "Unexpected branch type " << initial_type;
+ UNREACHABLE();
}
}
old_type_ = type_;
@@ -1804,7 +1827,7 @@
rhs_reg_(0),
condition_(kUncond),
delayed_instruction_(kUnfilledDelaySlot) {
- InitializeType(is_call, /* is_literal */ false, is_r6);
+ InitializeType((is_call ? kCall : kCondBranch), is_r6);
}
MipsAssembler::Branch::Branch(bool is_r6,
@@ -1862,10 +1885,14 @@
// Branch condition is always true, make the branch unconditional.
condition_ = kUncond;
}
- InitializeType(/* is_call */ false, /* is_literal */ false, is_r6);
+ InitializeType(kCondBranch, is_r6);
}
-MipsAssembler::Branch::Branch(bool is_r6, uint32_t location, Register dest_reg, Register base_reg)
+MipsAssembler::Branch::Branch(bool is_r6,
+ uint32_t location,
+ Register dest_reg,
+ Register base_reg,
+ Type label_or_literal_type)
: old_location_(location),
location_(location),
target_(kUnresolved),
@@ -1879,7 +1906,7 @@
} else {
CHECK_NE(base_reg, ZERO);
}
- InitializeType(/* is_call */ false, /* is_literal */ true, is_r6);
+ InitializeType(label_or_literal_type, is_r6);
}
MipsAssembler::BranchCondition MipsAssembler::Branch::OppositeCondition(
@@ -2007,12 +2034,16 @@
case kUncondBranch:
case kCondBranch:
case kCall:
+ // R2 near label.
+ case kLabel:
// R2 near literal.
case kLiteral:
// R6 short branches.
case kR6UncondBranch:
case kR6CondBranch:
case kR6Call:
+ // R6 near label.
+ case kR6Label:
// R6 near literal.
case kR6Literal:
return false;
@@ -2020,12 +2051,16 @@
case kLongUncondBranch:
case kLongCondBranch:
case kLongCall:
+ // R2 far label.
+ case kFarLabel:
// R2 far literal.
case kFarLiteral:
// R6 long branches.
case kR6LongUncondBranch:
case kR6LongCondBranch:
case kR6LongCall:
+ // R6 far label.
+ case kR6FarLabel:
// R6 far literal.
case kR6FarLiteral:
return true;
@@ -2096,6 +2131,10 @@
case kCall:
type_ = kLongCall;
break;
+ // R2 near label.
+ case kLabel:
+ type_ = kFarLabel;
+ break;
// R2 near literal.
case kLiteral:
type_ = kFarLiteral;
@@ -2110,6 +2149,10 @@
case kR6Call:
type_ = kR6LongCall;
break;
+ // R6 near label.
+ case kR6Label:
+ type_ = kR6FarLabel;
+ break;
// R6 near literal.
case kR6Literal:
type_ = kR6FarLiteral;
@@ -2123,6 +2166,8 @@
uint32_t MipsAssembler::GetBranchLocationOrPcRelBase(const MipsAssembler::Branch* branch) const {
switch (branch->GetType()) {
+ case Branch::kLabel:
+ case Branch::kFarLabel:
case Branch::kLiteral:
case Branch::kFarLiteral:
return GetLabelLocation(&pc_rel_base_label_);
@@ -2132,7 +2177,7 @@
}
uint32_t MipsAssembler::Branch::PromoteIfNeeded(uint32_t location, uint32_t max_short_distance) {
- // `location` is either `GetLabelLocation(&pc_rel_base_label_)` for R2 literals or
+ // `location` is either `GetLabelLocation(&pc_rel_base_label_)` for R2 labels/literals or
// `this->GetLocation()` for everything else.
// If the branch is still unresolved or already long, nothing to do.
if (IsLong() || !IsResolved()) {
@@ -2170,6 +2215,8 @@
uint32_t MipsAssembler::GetBranchOrPcRelBaseForEncoding(const MipsAssembler::Branch* branch) const {
switch (branch->GetType()) {
+ case Branch::kLabel:
+ case Branch::kFarLabel:
case Branch::kLiteral:
case Branch::kFarLiteral:
return GetLabelLocation(&pc_rel_base_label_);
@@ -2180,7 +2227,7 @@
}
uint32_t MipsAssembler::Branch::GetOffset(uint32_t location) const {
- // `location` is either `GetLabelLocation(&pc_rel_base_label_)` for R2 literals or
+ // `location` is either `GetLabelLocation(&pc_rel_base_label_)` for R2 labels/literals or
// `this->GetOffsetLocation() + branch_info_[this->GetType()].pc_org * sizeof(uint32_t)`
// for everything else.
CHECK(IsResolved());
@@ -2457,6 +2504,13 @@
FinalizeLabeledBranch(label);
}
+void MipsAssembler::LoadLabelAddress(Register dest_reg, Register base_reg, MipsLabel* label) {
+ // Label address loads are treated as pseudo branches since they require very similar handling.
+ DCHECK(!label->IsBound());
+ branches_.emplace_back(IsR6(), buffer_.Size(), dest_reg, base_reg, Branch::kLabel);
+ FinalizeLabeledBranch(label);
+}
+
Literal* MipsAssembler::NewLiteral(size_t size, const uint8_t* data) {
DCHECK(size == 4u || size == 8u) << size;
literals_.emplace_back(size, data);
@@ -2468,13 +2522,17 @@
DCHECK_EQ(literal->GetSize(), 4u);
MipsLabel* label = literal->GetLabel();
DCHECK(!label->IsBound());
- branches_.emplace_back(IsR6(),
- buffer_.Size(),
- dest_reg,
- base_reg);
+ branches_.emplace_back(IsR6(), buffer_.Size(), dest_reg, base_reg, Branch::kLiteral);
FinalizeLabeledBranch(label);
}
+JumpTable* MipsAssembler::CreateJumpTable(std::vector<MipsLabel*>&& labels) {
+ jump_tables_.emplace_back(std::move(labels));
+ JumpTable* table = &jump_tables_.back();
+ DCHECK(!table->GetLabel()->IsBound());
+ return table;
+}
+
void MipsAssembler::EmitLiterals() {
if (!literals_.empty()) {
// We don't support byte and half-word literals.
@@ -2491,6 +2549,60 @@
}
}
+void MipsAssembler::ReserveJumpTableSpace() {
+ if (!jump_tables_.empty()) {
+ for (JumpTable& table : jump_tables_) {
+ MipsLabel* label = table.GetLabel();
+ Bind(label);
+
+ // Bulk ensure capacity, as this may be large.
+ size_t orig_size = buffer_.Size();
+ size_t required_capacity = orig_size + table.GetSize();
+ if (required_capacity > buffer_.Capacity()) {
+ buffer_.ExtendCapacity(required_capacity);
+ }
+#ifndef NDEBUG
+ buffer_.has_ensured_capacity_ = true;
+#endif
+
+ // Fill the space with dummy data as the data is not final
+ // until the branches have been promoted. And we shouldn't
+ // be moving uninitialized data during branch promotion.
+ for (size_t cnt = table.GetData().size(), i = 0; i < cnt; i++) {
+ buffer_.Emit<uint32_t>(0x1abe1234u);
+ }
+
+#ifndef NDEBUG
+ buffer_.has_ensured_capacity_ = false;
+#endif
+ }
+ }
+}
+
+void MipsAssembler::EmitJumpTables() {
+ if (!jump_tables_.empty()) {
+ CHECK(!overwriting_);
+ // Switch from appending instructions at the end of the buffer to overwriting
+ // existing instructions (here, jump tables) in the buffer.
+ overwriting_ = true;
+
+ for (JumpTable& table : jump_tables_) {
+ MipsLabel* table_label = table.GetLabel();
+ uint32_t start = GetLabelLocation(table_label);
+ overwrite_location_ = start;
+
+ for (MipsLabel* target : table.GetData()) {
+ CHECK_EQ(buffer_.Load<uint32_t>(overwrite_location_), 0x1abe1234u);
+ // The table will contain target addresses relative to the table start.
+ uint32_t offset = GetLabelLocation(target) - start;
+ Emit(offset);
+ }
+ }
+
+ overwriting_ = false;
+ }
+}
+
void MipsAssembler::PromoteBranches() {
// Promote short branches to long as necessary.
bool changed;
@@ -2539,12 +2651,16 @@
{ 2, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kUncondBranch
{ 2, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kCondBranch
{ 2, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kCall
+ // R2 near label.
+ { 1, 0, 0, MipsAssembler::Branch::kOffset16, 0 }, // kLabel
// R2 near literal.
{ 1, 0, 0, MipsAssembler::Branch::kOffset16, 0 }, // kLiteral
// R2 long branches.
{ 9, 3, 1, MipsAssembler::Branch::kOffset32, 0 }, // kLongUncondBranch
{ 10, 4, 1, MipsAssembler::Branch::kOffset32, 0 }, // kLongCondBranch
{ 6, 1, 1, MipsAssembler::Branch::kOffset32, 0 }, // kLongCall
+ // R2 far label.
+ { 3, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kFarLabel
// R2 far literal.
{ 3, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kFarLiteral
// R6 short branches.
@@ -2552,12 +2668,16 @@
{ 2, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kR6CondBranch
// Exception: kOffset23 for beqzc/bnezc.
{ 1, 0, 1, MipsAssembler::Branch::kOffset28, 2 }, // kR6Call
+ // R6 near label.
+ { 1, 0, 0, MipsAssembler::Branch::kOffset21, 2 }, // kR6Label
// R6 near literal.
{ 1, 0, 0, MipsAssembler::Branch::kOffset21, 2 }, // kR6Literal
// R6 long branches.
{ 2, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6LongUncondBranch
{ 3, 1, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6LongCondBranch
{ 2, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6LongCall
+ // R6 far label.
+ { 2, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6FarLabel
// R6 far literal.
{ 2, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6FarLiteral
};
@@ -2614,6 +2734,12 @@
Emit(delayed_instruction);
break;
+ // R2 near label.
+ case Branch::kLabel:
+ DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
+ CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
+ Addiu(lhs, rhs, offset);
+ break;
// R2 near literal.
case Branch::kLiteral:
DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
@@ -2691,6 +2817,14 @@
Nop();
break;
+ // R2 far label.
+ case Branch::kFarLabel:
+ DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
+ CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
+ Lui(AT, High16Bits(offset));
+ Ori(AT, AT, Low16Bits(offset));
+ Addu(lhs, AT, rhs);
+ break;
// R2 far literal.
case Branch::kFarLiteral:
DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
@@ -2725,6 +2859,12 @@
Balc(offset);
break;
+ // R6 near label.
+ case Branch::kR6Label:
+ DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
+ CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
+ Addiupc(lhs, offset);
+ break;
// R6 near literal.
case Branch::kR6Literal:
DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
@@ -2759,6 +2899,14 @@
Jialc(AT, Low16Bits(offset));
break;
+ // R6 far label.
+ case Branch::kR6FarLabel:
+ DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
+ offset += (offset & 0x8000) << 1; // Account for sign extension in addiu.
+ CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
+ Auipc(AT, High16Bits(offset));
+ Addiu(lhs, AT, Low16Bits(offset));
+ break;
// R6 far literal.
case Branch::kR6FarLiteral:
DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
diff --git a/compiler/utils/mips/assembler_mips.h b/compiler/utils/mips/assembler_mips.h
index d50c439..099620c 100644
--- a/compiler/utils/mips/assembler_mips.h
+++ b/compiler/utils/mips/assembler_mips.h
@@ -126,6 +126,36 @@
DISALLOW_COPY_AND_ASSIGN(Literal);
};
+// Jump table: table of labels emitted after the literals. Similar to literals.
+class JumpTable {
+ public:
+ explicit JumpTable(std::vector<MipsLabel*>&& labels)
+ : label_(), labels_(std::move(labels)) {
+ }
+
+ uint32_t GetSize() const {
+ return static_cast<uint32_t>(labels_.size()) * sizeof(uint32_t);
+ }
+
+ const std::vector<MipsLabel*>& GetData() const {
+ return labels_;
+ }
+
+ MipsLabel* GetLabel() {
+ return &label_;
+ }
+
+ const MipsLabel* GetLabel() const {
+ return &label_;
+ }
+
+ private:
+ MipsLabel label_;
+ std::vector<MipsLabel*> labels_;
+
+ DISALLOW_COPY_AND_ASSIGN(JumpTable);
+};
+
// Slowpath entered when Thread::Current()->_exception is non-null.
class MipsExceptionSlowPath {
public:
@@ -158,6 +188,7 @@
ds_fsm_state_(kExpectingLabel),
ds_fsm_target_pc_(0),
literals_(arena->Adapter(kArenaAllocAssembler)),
+ jump_tables_(arena->Adapter(kArenaAllocAssembler)),
last_position_adjustment_(0),
last_old_position_(0),
last_branch_id_(0),
@@ -685,6 +716,11 @@
return NewLiteral(sizeof(value), reinterpret_cast<const uint8_t*>(&value));
}
+ // Load label address using the base register (for R2 only) or using PC-relative loads
+ // (for R6 only; base_reg must be ZERO). To be used with data labels in the literal /
+ // jump table area only and not with regular code labels.
+ void LoadLabelAddress(Register dest_reg, Register base_reg, MipsLabel* label);
+
// Create a new literal with the given data.
Literal* NewLiteral(size_t size, const uint8_t* data);
@@ -692,6 +728,12 @@
// (for R6 only; base_reg must be ZERO).
void LoadLiteral(Register dest_reg, Register base_reg, Literal* literal);
+ // Create a jump table for the given labels that will be emitted when finalizing.
+ // When the table is emitted, offsets will be relative to the location of the table.
+ // The table location is determined by the location of its label (the label precedes
+ // the table data) and should be loaded using LoadLabelAddress().
+ JumpTable* CreateJumpTable(std::vector<MipsLabel*>&& labels);
+
//
// Overridden common assembler high-level functionality.
//
@@ -935,24 +977,32 @@
kUncondBranch,
kCondBranch,
kCall,
+ // R2 near label.
+ kLabel,
// R2 near literal.
kLiteral,
// R2 long branches.
kLongUncondBranch,
kLongCondBranch,
kLongCall,
+ // R2 far label.
+ kFarLabel,
// R2 far literal.
kFarLiteral,
// R6 short branches.
kR6UncondBranch,
kR6CondBranch,
kR6Call,
+ // R6 near label.
+ kR6Label,
// R6 near literal.
kR6Literal,
// R6 long branches.
kR6LongUncondBranch,
kR6LongCondBranch,
kR6LongCall,
+ // R6 far label.
+ kR6FarLabel,
// R6 far literal.
kR6FarLiteral,
};
@@ -1009,8 +1059,12 @@
BranchCondition condition,
Register lhs_reg,
Register rhs_reg);
- // Literal.
- Branch(bool is_r6, uint32_t location, Register dest_reg, Register base_reg);
+ // Label address (in literal area) or literal.
+ Branch(bool is_r6,
+ uint32_t location,
+ Register dest_reg,
+ Register base_reg,
+ Type label_or_literal_type);
// Some conditional branches with lhs = rhs are effectively NOPs, while some
// others are effectively unconditional. MIPSR6 conditional branches require lhs != rhs.
@@ -1105,7 +1159,7 @@
private:
// Completes branch construction by determining and recording its type.
- void InitializeType(bool is_call, bool is_literal, bool is_r6);
+ void InitializeType(Type initial_type, bool is_r6);
// Helper for the above.
void InitShortOrLong(OffsetBits ofs_size, Type short_type, Type long_type);
@@ -1178,6 +1232,8 @@
uint32_t GetBranchOrPcRelBaseForEncoding(const MipsAssembler::Branch* branch) const;
void EmitLiterals();
+ void ReserveJumpTableSpace();
+ void EmitJumpTables();
void PromoteBranches();
void EmitBranch(Branch* branch);
void EmitBranches();
@@ -1227,6 +1283,9 @@
// without invalidating pointers and references to existing elements.
ArenaDeque<Literal> literals_;
+ // Jump table list.
+ ArenaDeque<JumpTable> jump_tables_;
+
// There's no PC-relative addressing on MIPS32R2. So, in order to access literals relative to PC
// we get PC using the NAL instruction. This label marks the position within the assembler buffer
// that PC (from NAL) points to.
diff --git a/compiler/utils/mips/assembler_mips32r6_test.cc b/compiler/utils/mips/assembler_mips32r6_test.cc
index fabb096..750a94d 100644
--- a/compiler/utils/mips/assembler_mips32r6_test.cc
+++ b/compiler/utils/mips/assembler_mips32r6_test.cc
@@ -309,6 +309,12 @@
DriverStr(RepeatRIb(&mips::MipsAssembler::Lwpc, 19, code), "Lwpc");
}
+TEST_F(AssemblerMIPS32r6Test, Addiupc) {
+ // The comment from the Lwpc() test applies to this Addiupc() test as well.
+ const char* code = ".set imm, {imm}\naddiupc ${reg}, (imm - ((imm & 0x40000) << 1)) << 2";
+ DriverStr(RepeatRIb(&mips::MipsAssembler::Addiupc, 19, code), "Addiupc");
+}
+
TEST_F(AssemblerMIPS32r6Test, Bitswap) {
DriverStr(RepeatRR(&mips::MipsAssembler::Bitswap, "bitswap ${reg1}, ${reg2}"), "bitswap");
}
@@ -635,6 +641,40 @@
DriverStr(expected, "StoreDToOffset");
}
+TEST_F(AssemblerMIPS32r6Test, LoadFarthestNearLabelAddress) {
+ mips::MipsLabel label;
+ __ LoadLabelAddress(mips::V0, mips::ZERO, &label);
+ constexpr size_t kAdduCount = 0x3FFDE;
+ for (size_t i = 0; i != kAdduCount; ++i) {
+ __ Addu(mips::ZERO, mips::ZERO, mips::ZERO);
+ }
+ __ Bind(&label);
+
+ std::string expected =
+ "lapc $v0, 1f\n" +
+ RepeatInsn(kAdduCount, "addu $zero, $zero, $zero\n") +
+ "1:\n";
+ DriverStr(expected, "LoadFarthestNearLabelAddress");
+}
+
+TEST_F(AssemblerMIPS32r6Test, LoadNearestFarLabelAddress) {
+ mips::MipsLabel label;
+ __ LoadLabelAddress(mips::V0, mips::ZERO, &label);
+ constexpr size_t kAdduCount = 0x3FFDF;
+ for (size_t i = 0; i != kAdduCount; ++i) {
+ __ Addu(mips::ZERO, mips::ZERO, mips::ZERO);
+ }
+ __ Bind(&label);
+
+ std::string expected =
+ "1:\n"
+ "auipc $at, %hi(2f - 1b)\n"
+ "addiu $v0, $at, %lo(2f - 1b)\n" +
+ RepeatInsn(kAdduCount, "addu $zero, $zero, $zero\n") +
+ "2:\n";
+ DriverStr(expected, "LoadNearestFarLabelAddress");
+}
+
TEST_F(AssemblerMIPS32r6Test, LoadFarthestNearLiteral) {
mips::Literal* literal = __ NewLiteral<uint32_t>(0x12345678);
__ LoadLiteral(mips::V0, mips::ZERO, literal);
@@ -811,8 +851,7 @@
DriverStr(expected, "LongBeqc");
}
-// TODO: MipsAssembler::Addiupc
-// MipsAssembler::Bc
+// TODO: MipsAssembler::Bc
// MipsAssembler::Jic
// MipsAssembler::Jialc
// MipsAssembler::Bltc
diff --git a/compiler/utils/mips/assembler_mips_test.cc b/compiler/utils/mips/assembler_mips_test.cc
index 708bc3d..a92455f 100644
--- a/compiler/utils/mips/assembler_mips_test.cc
+++ b/compiler/utils/mips/assembler_mips_test.cc
@@ -2307,6 +2307,44 @@
DriverStr(expected, "LoadConst32");
}
+TEST_F(AssemblerMIPSTest, LoadFarthestNearLabelAddress) {
+ mips::MipsLabel label;
+ __ BindPcRelBaseLabel();
+ __ LoadLabelAddress(mips::V0, mips::V1, &label);
+ constexpr size_t kAddiuCount = 0x1FDE;
+ for (size_t i = 0; i != kAddiuCount; ++i) {
+ __ Addiu(mips::A0, mips::A1, 0);
+ }
+ __ Bind(&label);
+
+ std::string expected =
+ "1:\n"
+ "addiu $v0, $v1, %lo(2f - 1b)\n" +
+ RepeatInsn(kAddiuCount, "addiu $a0, $a1, %hi(2f - 1b)\n") +
+ "2:\n";
+ DriverStr(expected, "LoadFarthestNearLabelAddress");
+}
+
+TEST_F(AssemblerMIPSTest, LoadNearestFarLabelAddress) {
+ mips::MipsLabel label;
+ __ BindPcRelBaseLabel();
+ __ LoadLabelAddress(mips::V0, mips::V1, &label);
+ constexpr size_t kAdduCount = 0x1FDF;
+ for (size_t i = 0; i != kAdduCount; ++i) {
+ __ Addu(mips::ZERO, mips::ZERO, mips::ZERO);
+ }
+ __ Bind(&label);
+
+ std::string expected =
+ "1:\n"
+ "lui $at, %hi(2f - 1b)\n"
+ "ori $at, $at, %lo(2f - 1b)\n"
+ "addu $v0, $at, $v1\n" +
+ RepeatInsn(kAdduCount, "addu $zero, $zero, $zero\n") +
+ "2:\n";
+ DriverStr(expected, "LoadNearestFarLabelAddress");
+}
+
TEST_F(AssemblerMIPSTest, LoadFarthestNearLiteral) {
mips::Literal* literal = __ NewLiteral<uint32_t>(0x12345678);
__ BindPcRelBaseLabel();
diff --git a/compiler/utils/x86/assembler_x86.h b/compiler/utils/x86/assembler_x86.h
index 9738784..114986b 100644
--- a/compiler/utils/x86/assembler_x86.h
+++ b/compiler/utils/x86/assembler_x86.h
@@ -20,6 +20,7 @@
#include <vector>
#include "base/arena_containers.h"
+#include "base/array_ref.h"
#include "base/bit_utils.h"
#include "base/enums.h"
#include "base/macros.h"
@@ -27,7 +28,6 @@
#include "globals.h"
#include "managed_register_x86.h"
#include "offsets.h"
-#include "utils/array_ref.h"
#include "utils/assembler.h"
namespace art {
diff --git a/compiler/utils/x86/jni_macro_assembler_x86.h b/compiler/utils/x86/jni_macro_assembler_x86.h
index 3f07ede..015584c 100644
--- a/compiler/utils/x86/jni_macro_assembler_x86.h
+++ b/compiler/utils/x86/jni_macro_assembler_x86.h
@@ -21,10 +21,10 @@
#include "assembler_x86.h"
#include "base/arena_containers.h"
+#include "base/array_ref.h"
#include "base/enums.h"
#include "base/macros.h"
#include "offsets.h"
-#include "utils/array_ref.h"
#include "utils/jni_macro_assembler.h"
namespace art {
diff --git a/compiler/utils/x86_64/assembler_x86_64.h b/compiler/utils/x86_64/assembler_x86_64.h
index fdd3aa9..acad86d 100644
--- a/compiler/utils/x86_64/assembler_x86_64.h
+++ b/compiler/utils/x86_64/assembler_x86_64.h
@@ -20,13 +20,13 @@
#include <vector>
#include "base/arena_containers.h"
+#include "base/array_ref.h"
#include "base/bit_utils.h"
#include "base/macros.h"
#include "constants_x86_64.h"
#include "globals.h"
#include "managed_register_x86_64.h"
#include "offsets.h"
-#include "utils/array_ref.h"
#include "utils/assembler.h"
#include "utils/jni_macro_assembler.h"
diff --git a/compiler/utils/x86_64/jni_macro_assembler_x86_64.h b/compiler/utils/x86_64/jni_macro_assembler_x86_64.h
index cc4e57c..9107f3c 100644
--- a/compiler/utils/x86_64/jni_macro_assembler_x86_64.h
+++ b/compiler/utils/x86_64/jni_macro_assembler_x86_64.h
@@ -21,10 +21,10 @@
#include "assembler_x86_64.h"
#include "base/arena_containers.h"
+#include "base/array_ref.h"
#include "base/enums.h"
#include "base/macros.h"
#include "offsets.h"
-#include "utils/array_ref.h"
#include "utils/assembler.h"
#include "utils/jni_macro_assembler.h"
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 1dd9132..1296bcf 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -2782,6 +2782,8 @@
return EXIT_FAILURE;
}
+ VLOG(compiler) << "Running dex2oat (parent PID = " << getppid() << ")";
+
bool result;
if (dex2oat->IsImage()) {
result = CompileImage(*dex2oat);
diff --git a/dexlist/dexlist_test.cc b/dexlist/dexlist_test.cc
index 9a65ba6..da1dd7f 100644
--- a/dexlist/dexlist_test.cc
+++ b/dexlist/dexlist_test.cc
@@ -43,11 +43,7 @@
// Runs test with given arguments.
bool Exec(const std::vector<std::string>& args, std::string* error_msg) {
std::string file_path = GetTestAndroidRoot();
- if (IsHost()) {
- file_path += "/bin/dexlist";
- } else {
- file_path += "/xbin/dexlist";
- }
+ file_path += "/bin/dexlist";
EXPECT_TRUE(OS::FileExists(file_path.c_str())) << file_path << " should be a valid file path";
std::vector<std::string> exec_argv = { file_path };
exec_argv.insert(exec_argv.end(), args.begin(), args.end());
diff --git a/runtime/Android.bp b/runtime/Android.bp
index b61976c..eb7b0c8 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -53,6 +53,7 @@
"compiler_filter.cc",
"debugger.cc",
"dex_file.cc",
+ "dex_file_annotations.cc",
"dex_file_verifier.cc",
"dex_instruction.cc",
"elf_file.cc",
diff --git a/runtime/arch/arm/quick_entrypoints_arm.S b/runtime/arch/arm/quick_entrypoints_arm.S
index 3fc83ba..0b04480 100644
--- a/runtime/arch/arm/quick_entrypoints_arm.S
+++ b/runtime/arch/arm/quick_entrypoints_arm.S
@@ -260,7 +260,7 @@
.fnstart
SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r0 @ save callee saves for throw
mov r0, r9 @ pass Thread::Current
- b artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*)
+ bl artDeliverPendingExceptionFromCode @ artDeliverPendingExceptionFromCode(Thread*)
.endm
.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
@@ -268,7 +268,7 @@
ENTRY \c_name
SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r0 @ save all registers as basis for long jump context
mov r0, r9 @ pass Thread::Current
- b \cxx_name @ \cxx_name(Thread*)
+ bl \cxx_name @ \cxx_name(Thread*)
END \c_name
.endm
@@ -277,7 +277,7 @@
ENTRY \c_name
SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r1 @ save all registers as basis for long jump context
mov r1, r9 @ pass Thread::Current
- b \cxx_name @ \cxx_name(Thread*)
+ bl \cxx_name @ \cxx_name(Thread*)
END \c_name
.endm
@@ -286,7 +286,7 @@
ENTRY \c_name
SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r2 @ save all registers as basis for long jump context
mov r2, r9 @ pass Thread::Current
- b \cxx_name @ \cxx_name(Thread*)
+ bl \cxx_name @ \cxx_name(Thread*)
END \c_name
.endm
@@ -392,7 +392,7 @@
SETUP_SAVE_EVERYTHING_FRAME_CORE_REGS_SAVED r1
mov r0, lr @ pass the fault address stored in LR by the fault handler.
mov r1, r9 @ pass Thread::Current
- b artThrowNullPointerExceptionFromSignal @ (Thread*)
+ bl artThrowNullPointerExceptionFromSignal @ (Thread*)
END art_quick_throw_null_pointer_exception_from_signal
/*
@@ -418,11 +418,6 @@
NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
/*
- * Called by managed code to create and deliver a NoSuchMethodError.
- */
-ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
-
- /*
* All generated callsites for interface invokes and invocation slow paths will load arguments
* as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
* the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
@@ -758,7 +753,7 @@
.cfi_restore lr
SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r2 @ save all registers as basis for long jump context
mov r2, r9 @ pass Thread::Current
- b artThrowClassCastException @ (Class*, Class*, Thread*)
+ bl artThrowClassCastException @ (Class*, Class*, Thread*)
bkpt
END art_quick_check_cast
@@ -901,7 +896,7 @@
SETUP_SAVE_ALL_CALLEE_SAVES_FRAME r3
mov r1, r2
mov r2, r9 @ pass Thread::Current
- b artThrowArrayStoreException @ (Class*, Class*, Thread*)
+ bl artThrowArrayStoreException @ (Class*, Class*, Thread*)
bkpt @ unreached
END art_quick_aput_obj
diff --git a/runtime/arch/arm64/quick_entrypoints_arm64.S b/runtime/arch/arm64/quick_entrypoints_arm64.S
index 5a92659..e9d03d7 100644
--- a/runtime/arch/arm64/quick_entrypoints_arm64.S
+++ b/runtime/arch/arm64/quick_entrypoints_arm64.S
@@ -400,7 +400,7 @@
mov x0, xSELF
// Point of no return.
- b artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*)
+ bl artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*)
brk 0 // Unreached
.endm
@@ -433,7 +433,7 @@
ENTRY \c_name
SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
mov x0, xSELF // pass Thread::Current
- b \cxx_name // \cxx_name(Thread*)
+ bl \cxx_name // \cxx_name(Thread*)
END \c_name
.endm
@@ -442,7 +442,7 @@
ENTRY \c_name
SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context.
mov x1, xSELF // pass Thread::Current.
- b \cxx_name // \cxx_name(arg, Thread*).
+ bl \cxx_name // \cxx_name(arg, Thread*).
brk 0
END \c_name
.endm
@@ -452,7 +452,7 @@
ENTRY \c_name
SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
mov x2, xSELF // pass Thread::Current
- b \cxx_name // \cxx_name(arg1, arg2, Thread*)
+ bl \cxx_name // \cxx_name(arg1, arg2, Thread*)
brk 0
END \c_name
.endm
@@ -483,8 +483,7 @@
SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP_SKIP_X29_LR
mov x0, lr // pass the fault address stored in LR by the fault handler.
mov x1, xSELF // pass Thread::Current.
- // TODO: Change other throwing entrypoints to use BL instead of B. http://b/31468464
- bl artThrowNullPointerExceptionFromSignal // (arg, Thread*).
+ bl artThrowNullPointerExceptionFromSignal // (arg, Thread*).
brk 0
END art_quick_throw_null_pointer_exception_from_signal
@@ -511,11 +510,6 @@
NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
/*
- * Called by managed code to create and deliver a NoSuchMethodError.
- */
-ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
-
- /*
* All generated callsites for interface invokes and invocation slow paths will load arguments
* as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain
* the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
@@ -1307,7 +1301,7 @@
SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
mov x2, xSELF // pass Thread::Current
- b artThrowClassCastException // (Class*, Class*, Thread*)
+ bl artThrowClassCastException // (Class*, Class*, Thread*)
brk 0 // We should not return here...
END art_quick_check_cast
@@ -1471,10 +1465,10 @@
RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
- mov x1, x2 // Pass value.
- mov x2, xSELF // Pass Thread::Current.
- b artThrowArrayStoreException // (Object*, Object*, Thread*).
- brk 0 // Unreached.
+ mov x1, x2 // Pass value.
+ mov x2, xSELF // Pass Thread::Current.
+ bl artThrowArrayStoreException // (Object*, Object*, Thread*).
+ brk 0 // Unreached.
END art_quick_aput_obj
// Macro to facilitate adding new allocation entrypoints.
diff --git a/runtime/arch/mips/entrypoints_init_mips.cc b/runtime/arch/mips/entrypoints_init_mips.cc
index 38aa67c..e10d4e6 100644
--- a/runtime/arch/mips/entrypoints_init_mips.cc
+++ b/runtime/arch/mips/entrypoints_init_mips.cc
@@ -264,8 +264,6 @@
static_assert(!IsDirectEntrypoint(kQuickThrowArrayBounds), "Non-direct C stub marked direct.");
qpoints->pThrowDivZero = art_quick_throw_div_zero;
static_assert(!IsDirectEntrypoint(kQuickThrowDivZero), "Non-direct C stub marked direct.");
- qpoints->pThrowNoSuchMethod = art_quick_throw_no_such_method;
- static_assert(!IsDirectEntrypoint(kQuickThrowNoSuchMethod), "Non-direct C stub marked direct.");
qpoints->pThrowNullPointer = art_quick_throw_null_pointer_exception;
static_assert(!IsDirectEntrypoint(kQuickThrowNullPointer), "Non-direct C stub marked direct.");
qpoints->pThrowStackOverflow = art_quick_throw_stack_overflow;
diff --git a/runtime/arch/mips/quick_entrypoints_mips.S b/runtime/arch/mips/quick_entrypoints_mips.S
index 71b8ae2..4563004 100644
--- a/runtime/arch/mips/quick_entrypoints_mips.S
+++ b/runtime/arch/mips/quick_entrypoints_mips.S
@@ -777,17 +777,6 @@
END art_quick_throw_stack_overflow
/*
- * Called by managed code to create and deliver a NoSuchMethodError.
- */
- .extern artThrowNoSuchMethodFromCode
-ENTRY art_quick_throw_no_such_method
- SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
- la $t9, artThrowNoSuchMethodFromCode
- jalr $zero, $t9 # artThrowNoSuchMethodFromCode(method_idx, Thread*)
- move $a1, rSELF # pass Thread::Current
-END art_quick_throw_no_such_method
-
- /*
* All generated callsites for interface invokes and invocation slow paths will load arguments
* as usual - except instead of loading arg0/$a0 with the target Method*, arg0/$a0 will contain
* the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
diff --git a/runtime/arch/mips64/quick_entrypoints_mips64.S b/runtime/arch/mips64/quick_entrypoints_mips64.S
index 61c9019..c16e855 100644
--- a/runtime/arch/mips64/quick_entrypoints_mips64.S
+++ b/runtime/arch/mips64/quick_entrypoints_mips64.S
@@ -887,17 +887,6 @@
END art_quick_throw_stack_overflow
/*
- * Called by managed code to create and deliver a NoSuchMethodError.
- */
- .extern artThrowNoSuchMethodFromCode
-ENTRY art_quick_throw_no_such_method
- SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
- dla $t9, artThrowNoSuchMethodFromCode
- jalr $zero, $t9 # artThrowNoSuchMethodFromCode(method_idx, Thread*)
- move $a1, rSELF # pass Thread::Current
-END art_quick_throw_no_such_method
-
- /*
* All generated callsites for interface invokes and invocation slow paths will load arguments
* as usual - except instead of loading arg0/$a0 with the target Method*, arg0/$a0 will contain
* the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
diff --git a/runtime/arch/x86/quick_entrypoints_x86.S b/runtime/arch/x86/quick_entrypoints_x86.S
index 0beb2a4..f3793e1 100644
--- a/runtime/arch/x86/quick_entrypoints_x86.S
+++ b/runtime/arch/x86/quick_entrypoints_x86.S
@@ -398,11 +398,6 @@
ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
/*
- * Called by managed code to create and deliver a NoSuchMethodError.
- */
-ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
-
- /*
* Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
* index, arg2 holds limit.
*/
diff --git a/runtime/arch/x86_64/quick_entrypoints_x86_64.S b/runtime/arch/x86_64/quick_entrypoints_x86_64.S
index 089ed75..bfba543 100644
--- a/runtime/arch/x86_64/quick_entrypoints_x86_64.S
+++ b/runtime/arch/x86_64/quick_entrypoints_x86_64.S
@@ -454,11 +454,6 @@
ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
/*
- * Called by managed code to create and deliver a NoSuchMethodError.
- */
-ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
-
- /*
* Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
* index, arg2 holds limit.
*/
diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h
index 1659f33..9b4b38a 100644
--- a/runtime/art_method-inl.h
+++ b/runtime/art_method-inl.h
@@ -24,6 +24,7 @@
#include "class_linker-inl.h"
#include "common_throws.h"
#include "dex_file.h"
+#include "dex_file_annotations.h"
#include "dex_file-inl.h"
#include "gc_root-inl.h"
#include "jit/profiling_info.h"
@@ -347,7 +348,7 @@
if (dex_pc == DexFile::kDexNoIndex) {
return IsNative() ? -2 : -1;
}
- return GetDexFile()->GetLineNumFromPC(this, dex_pc);
+ return annotations::GetLineNumFromPC(GetDexFile(), this, dex_pc);
}
inline const DexFile::ProtoId& ArtMethod::GetPrototype() {
diff --git a/runtime/art_method.cc b/runtime/art_method.cc
index 1392399..fd6c37a 100644
--- a/runtime/art_method.cc
+++ b/runtime/art_method.cc
@@ -25,6 +25,7 @@
#include "class_linker-inl.h"
#include "debugger.h"
#include "dex_file-inl.h"
+#include "dex_file_annotations.h"
#include "dex_instruction.h"
#include "entrypoints/runtime_asm_entrypoints.h"
#include "gc/accounting/card_table-inl.h"
@@ -107,7 +108,7 @@
}
bool ArtMethod::HasSameNameAndSignature(ArtMethod* other) {
- ScopedAssertNoThreadSuspension ants(Thread::Current(), "HasSameNameAndSignature");
+ ScopedAssertNoThreadSuspension ants("HasSameNameAndSignature");
const DexFile* dex_file = GetDexFile();
const DexFile::MethodId& mid = dex_file->GetMethodId(GetDexMethodIndex());
if (GetDexCache() == other->GetDexCache()) {
@@ -349,8 +350,6 @@
ScopedObjectAccess soa(self);
StackHandleScope<1> shs(self);
- const DexFile& dex_file = GetDeclaringClass()->GetDexFile();
-
mirror::Class* annotation = soa.Decode<mirror::Class*>(klass);
DCHECK(annotation->IsAnnotation());
Handle<mirror::Class> annotation_handle(shs.NewHandle(annotation));
@@ -358,7 +357,7 @@
// Note: Resolves any method annotations' classes as a side-effect.
// -- This seems allowed by the spec since it says we can preload any classes
// referenced by another classes's constant pool table.
- return dex_file.IsMethodAnnotationPresent(this, annotation_handle, visibility);
+ return annotations::IsMethodAnnotationPresent(this, annotation_handle, visibility);
}
bool ArtMethod::EqualParameters(Handle<mirror::ObjectArray<mirror::Class>> params) {
diff --git a/runtime/art_method.h b/runtime/art_method.h
index 8051a1f..b1baccd 100644
--- a/runtime/art_method.h
+++ b/runtime/art_method.h
@@ -33,6 +33,7 @@
namespace art {
+template<class T> class Handle;
union JValue;
class OatQuickMethodHeader;
class ProfilingInfo;
diff --git a/runtime/asm_support.h b/runtime/asm_support.h
index f4addf7..b8f7272 100644
--- a/runtime/asm_support.h
+++ b/runtime/asm_support.h
@@ -89,20 +89,20 @@
ADD_TEST_EQ(THREAD_SELF_OFFSET,
art::Thread::SelfOffset<POINTER_SIZE>().Int32Value())
-// Offset of field Thread::tlsPtr_.thread_local_objects.
-#define THREAD_LOCAL_OBJECTS_OFFSET (THREAD_CARD_TABLE_OFFSET + 199 * __SIZEOF_POINTER__)
-ADD_TEST_EQ(THREAD_LOCAL_OBJECTS_OFFSET,
- art::Thread::ThreadLocalObjectsOffset<POINTER_SIZE>().Int32Value())
// Offset of field Thread::tlsPtr_.thread_local_pos.
-#define THREAD_LOCAL_POS_OFFSET (THREAD_LOCAL_OBJECTS_OFFSET + __SIZEOF_SIZE_T__)
+#define THREAD_LOCAL_POS_OFFSET (THREAD_CARD_TABLE_OFFSET + 198 * __SIZEOF_POINTER__)
ADD_TEST_EQ(THREAD_LOCAL_POS_OFFSET,
art::Thread::ThreadLocalPosOffset<POINTER_SIZE>().Int32Value())
// Offset of field Thread::tlsPtr_.thread_local_end.
#define THREAD_LOCAL_END_OFFSET (THREAD_LOCAL_POS_OFFSET + __SIZEOF_POINTER__)
ADD_TEST_EQ(THREAD_LOCAL_END_OFFSET,
art::Thread::ThreadLocalEndOffset<POINTER_SIZE>().Int32Value())
+// Offset of field Thread::tlsPtr_.thread_local_objects.
+#define THREAD_LOCAL_OBJECTS_OFFSET (THREAD_LOCAL_END_OFFSET + __SIZEOF_POINTER__)
+ADD_TEST_EQ(THREAD_LOCAL_OBJECTS_OFFSET,
+ art::Thread::ThreadLocalObjectsOffset<POINTER_SIZE>().Int32Value())
// Offset of field Thread::tlsPtr_.mterp_current_ibase.
-#define THREAD_CURRENT_IBASE_OFFSET (THREAD_LOCAL_END_OFFSET + __SIZEOF_POINTER__)
+#define THREAD_CURRENT_IBASE_OFFSET (THREAD_LOCAL_OBJECTS_OFFSET + __SIZEOF_SIZE_T__)
ADD_TEST_EQ(THREAD_CURRENT_IBASE_OFFSET,
art::Thread::MterpCurrentIBaseOffset<POINTER_SIZE>().Int32Value())
// Offset of field Thread::tlsPtr_.mterp_default_ibase.
diff --git a/compiler/utils/array_ref.h b/runtime/base/array_ref.h
similarity index 97%
rename from compiler/utils/array_ref.h
rename to runtime/base/array_ref.h
index 8dc9ab4..00b9bad 100644
--- a/compiler/utils/array_ref.h
+++ b/runtime/base/array_ref.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef ART_COMPILER_UTILS_ARRAY_REF_H_
-#define ART_COMPILER_UTILS_ARRAY_REF_H_
+#ifndef ART_RUNTIME_BASE_ARRAY_REF_H_
+#define ART_RUNTIME_BASE_ARRAY_REF_H_
#include <type_traits>
#include <vector>
@@ -197,4 +197,4 @@
} // namespace art
-#endif // ART_COMPILER_UTILS_ARRAY_REF_H_
+#endif // ART_RUNTIME_BASE_ARRAY_REF_H_
diff --git a/compiler/utils/transform_array_ref.h b/runtime/base/transform_array_ref.h
similarity index 96%
rename from compiler/utils/transform_array_ref.h
rename to runtime/base/transform_array_ref.h
index a6da34f..a4e0bc2 100644
--- a/compiler/utils/transform_array_ref.h
+++ b/runtime/base/transform_array_ref.h
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-#ifndef ART_COMPILER_UTILS_TRANSFORM_ARRAY_REF_H_
-#define ART_COMPILER_UTILS_TRANSFORM_ARRAY_REF_H_
+#ifndef ART_RUNTIME_BASE_TRANSFORM_ARRAY_REF_H_
+#define ART_RUNTIME_BASE_TRANSFORM_ARRAY_REF_H_
#include <type_traits>
-#include "utils/array_ref.h"
-#include "utils/transform_iterator.h"
+#include "base/array_ref.h"
+#include "base/transform_iterator.h"
namespace art {
@@ -193,4 +193,4 @@
} // namespace art
-#endif // ART_COMPILER_UTILS_TRANSFORM_ARRAY_REF_H_
+#endif // ART_RUNTIME_BASE_TRANSFORM_ARRAY_REF_H_
diff --git a/compiler/utils/transform_array_ref_test.cc b/runtime/base/transform_array_ref_test.cc
similarity index 99%
rename from compiler/utils/transform_array_ref_test.cc
rename to runtime/base/transform_array_ref_test.cc
index 8d71fd7..494dbb2 100644
--- a/compiler/utils/transform_array_ref_test.cc
+++ b/runtime/base/transform_array_ref_test.cc
@@ -19,7 +19,7 @@
#include "gtest/gtest.h"
-#include "utils/transform_array_ref.h"
+#include "base/transform_array_ref.h"
namespace art {
diff --git a/compiler/utils/transform_iterator.h b/runtime/base/transform_iterator.h
similarity index 97%
rename from compiler/utils/transform_iterator.h
rename to runtime/base/transform_iterator.h
index 3bc9046..9c8f822 100644
--- a/compiler/utils/transform_iterator.h
+++ b/runtime/base/transform_iterator.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef ART_COMPILER_UTILS_TRANSFORM_ITERATOR_H_
-#define ART_COMPILER_UTILS_TRANSFORM_ITERATOR_H_
+#ifndef ART_RUNTIME_BASE_TRANSFORM_ITERATOR_H_
+#define ART_RUNTIME_BASE_TRANSFORM_ITERATOR_H_
#include <iterator>
#include <type_traits>
@@ -175,4 +175,4 @@
} // namespace art
-#endif // ART_COMPILER_UTILS_TRANSFORM_ITERATOR_H_
+#endif // ART_RUNTIME_BASE_TRANSFORM_ITERATOR_H_
diff --git a/compiler/utils/transform_iterator_test.cc b/runtime/base/transform_iterator_test.cc
similarity index 99%
rename from compiler/utils/transform_iterator_test.cc
rename to runtime/base/transform_iterator_test.cc
index 57ff0a6..a85dda8 100644
--- a/compiler/utils/transform_iterator_test.cc
+++ b/runtime/base/transform_iterator_test.cc
@@ -22,7 +22,7 @@
#include "gtest/gtest.h"
-#include "utils/transform_iterator.h"
+#include "base/transform_iterator.h"
namespace art {
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 4d252e1..6d93736 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -1533,7 +1533,7 @@
bool ClassLinker::OpenImageDexFiles(gc::space::ImageSpace* space,
std::vector<std::unique_ptr<const DexFile>>* out_dex_files,
std::string* error_msg) {
- ScopedAssertNoThreadSuspension nts(Thread::Current(), __FUNCTION__);
+ ScopedAssertNoThreadSuspension nts(__FUNCTION__);
const ImageHeader& header = space->GetImageHeader();
mirror::Object* dex_caches_object = header.GetImageRoot(ImageHeader::kDexCaches);
DCHECK(dex_caches_object != nullptr);
@@ -1923,7 +1923,7 @@
ReaderMutexLock mu(self, *Locks::classlinker_classes_lock_);
// Not safe to have thread suspension when we are holding a lock.
if (self != nullptr) {
- ScopedAssertNoThreadSuspension nts(self, __FUNCTION__);
+ ScopedAssertNoThreadSuspension nts(__FUNCTION__);
VisitClassesInternal(visitor);
} else {
VisitClassesInternal(visitor);
@@ -1965,9 +1965,8 @@
void ClassLinker::VisitClassesWithoutClassesLock(ClassVisitor* visitor) {
// TODO: it may be possible to avoid secondary storage if we iterate over dex caches. The problem
// is avoiding duplicates.
- Thread* const self = Thread::Current();
if (!kMovingClasses) {
- ScopedAssertNoThreadSuspension nts(self, __FUNCTION__);
+ ScopedAssertNoThreadSuspension nts(__FUNCTION__);
GetClassesInToVector accumulator;
VisitClasses(&accumulator);
for (mirror::Class* klass : accumulator.classes_) {
@@ -1976,6 +1975,7 @@
}
}
} else {
+ Thread* const self = Thread::Current();
StackHandleScope<1> hs(self);
auto classes = hs.NewHandle<mirror::ObjectArray<mirror::Class>>(nullptr);
// We size the array assuming classes won't be added to the class table during the visit.
@@ -3047,7 +3047,7 @@
{
// Note: We cannot have thread suspension until the field and method arrays are setup or else
// Class::VisitFieldRoots may miss some fields or methods.
- ScopedAssertNoThreadSuspension nts(self, __FUNCTION__);
+ ScopedAssertNoThreadSuspension nts(__FUNCTION__);
// Load static fields.
// We allow duplicate definitions of the same field in a class_data_item
// but ignore the repeated indexes here, b/21868015.
@@ -3113,7 +3113,7 @@
// TODO These should really use the iterators.
for (size_t i = 0; it.HasNextDirectMethod(); i++, it.Next()) {
ArtMethod* method = klass->GetDirectMethodUnchecked(i, image_pointer_size_);
- LoadMethod(self, dex_file, it, klass, method);
+ LoadMethod(dex_file, it, klass, method);
LinkCode(method, oat_class, class_def_method_index);
uint32_t it_method_index = it.GetMemberIndex();
if (last_dex_method_index == it_method_index) {
@@ -3128,7 +3128,7 @@
}
for (size_t i = 0; it.HasNextVirtualMethod(); i++, it.Next()) {
ArtMethod* method = klass->GetVirtualMethodUnchecked(i, image_pointer_size_);
- LoadMethod(self, dex_file, it, klass, method);
+ LoadMethod(dex_file, it, klass, method);
DCHECK_EQ(class_def_method_index, it.NumDirectMethods() + i);
LinkCode(method, oat_class, class_def_method_index);
class_def_method_index++;
@@ -3149,8 +3149,7 @@
dst->SetAccessFlags(it.GetFieldAccessFlags());
}
-void ClassLinker::LoadMethod(Thread* self,
- const DexFile& dex_file,
+void ClassLinker::LoadMethod(const DexFile& dex_file,
const ClassDataItemIterator& it,
Handle<mirror::Class> klass,
ArtMethod* dst) {
@@ -3158,7 +3157,7 @@
const DexFile::MethodId& method_id = dex_file.GetMethodId(dex_method_idx);
const char* method_name = dex_file.StringDataByIdx(method_id.name_idx_);
- ScopedAssertNoThreadSuspension ants(self, "LoadMethod");
+ ScopedAssertNoThreadSuspension ants("LoadMethod");
dst->SetDexMethodIndex(dex_method_idx);
dst->SetDeclaringClass(klass.Get());
dst->SetCodeItemOffset(it.GetMethodCodeItemOffset());
@@ -3692,7 +3691,7 @@
mirror::ClassLoader* class_loader) {
Thread* self = Thread::Current();
WriterMutexLock mu(self, *Locks::classlinker_classes_lock_);
- ScopedAssertNoThreadSuspension ants(self, "Moving image classes to class table");
+ ScopedAssertNoThreadSuspension ants("Moving image classes to class table");
ClassTable* const class_table = InsertClassTableForClassLoader(class_loader);
@@ -3747,7 +3746,7 @@
}
mirror::Class* ClassLinker::LookupClassFromBootImage(const char* descriptor) {
- ScopedAssertNoThreadSuspension ants(Thread::Current(), "Image class lookup");
+ ScopedAssertNoThreadSuspension ants("Image class lookup");
std::vector<mirror::ObjectArray<mirror::DexCache>*> dex_caches_vector =
GetImageDexCaches(Runtime::Current()->GetHeap()->GetBootImageSpaces());
for (mirror::ObjectArray<mirror::DexCache>* dex_caches : dex_caches_vector) {
@@ -4639,8 +4638,11 @@
}
}
- EncodedStaticFieldValueIterator value_it(dex_file, &dex_cache, &class_loader,
- this, *dex_class_def);
+ annotations::RuntimeEncodedStaticFieldValueIterator value_it(dex_file,
+ &dex_cache,
+ &class_loader,
+ this,
+ *dex_class_def);
const uint8_t* class_data = dex_file.GetClassData(*dex_class_def);
ClassDataItemIterator field_it(dex_file, class_data);
if (value_it.HasNext()) {
@@ -6505,7 +6507,7 @@
size_t new_ifcount;
{
- ScopedAssertNoThreadSuspension nts(self, "Copying mirror::Class*'s for FillIfTable");
+ ScopedAssertNoThreadSuspension nts("Copying mirror::Class*'s for FillIfTable");
std::vector<mirror::Class*> to_add;
for (size_t i = 0; i < num_interfaces; i++) {
mirror::Class* interface = have_interfaces ? interfaces->Get(i) :
@@ -8268,7 +8270,7 @@
std::set<DexCacheResolvedClasses> ClassLinker::GetResolvedClasses(bool ignore_boot_classes) {
ScopedTrace trace(__PRETTY_FUNCTION__);
ScopedObjectAccess soa(Thread::Current());
- ScopedAssertNoThreadSuspension ants(soa.Self(), __FUNCTION__);
+ ScopedAssertNoThreadSuspension ants(__FUNCTION__);
std::set<DexCacheResolvedClasses> ret;
VLOG(class_linker) << "Collecting resolved classes";
const uint64_t start_time = NanoTime();
@@ -8342,7 +8344,7 @@
Thread* const self = Thread::Current();
std::unordered_map<std::string, const DexFile*> location_to_dex_file;
ScopedObjectAccess soa(self);
- ScopedAssertNoThreadSuspension ants(soa.Self(), __FUNCTION__);
+ ScopedAssertNoThreadSuspension ants(__FUNCTION__);
ReaderMutexLock mu(self, *DexLock());
for (const ClassLinker::DexCacheData& data : GetDexCachesData()) {
if (!self->IsJWeakCleared(data.weak_root)) {
diff --git a/runtime/class_linker.h b/runtime/class_linker.h
index 5e4ae03..0a46e2e 100644
--- a/runtime/class_linker.h
+++ b/runtime/class_linker.h
@@ -769,8 +769,7 @@
void LoadField(const ClassDataItemIterator& it, Handle<mirror::Class> klass, ArtField* dst)
REQUIRES_SHARED(Locks::mutator_lock_);
- void LoadMethod(Thread* self,
- const DexFile& dex_file,
+ void LoadMethod(const DexFile& dex_file,
const ClassDataItemIterator& it,
Handle<mirror::Class> klass, ArtMethod* dst)
REQUIRES_SHARED(Locks::mutator_lock_);
diff --git a/runtime/common_throws.cc b/runtime/common_throws.cc
index 77362a5..1e4c772 100644
--- a/runtime/common_throws.cc
+++ b/runtime/common_throws.cc
@@ -357,16 +357,6 @@
ThrowException("Ljava/lang/NoSuchMethodError;", c, msg.str().c_str());
}
-void ThrowNoSuchMethodError(uint32_t method_idx) {
- ArtMethod* method = Thread::Current()->GetCurrentMethod(nullptr);
- mirror::DexCache* dex_cache = method->GetDeclaringClass()->GetDexCache();
- const DexFile& dex_file = *dex_cache->GetDexFile();
- std::ostringstream msg;
- msg << "No method '" << PrettyMethod(method_idx, dex_file, true) << "'";
- ThrowException("Ljava/lang/NoSuchMethodError;",
- method->GetDeclaringClass(), msg.str().c_str());
-}
-
// NullPointerException
void ThrowNullPointerExceptionForFieldAccess(ArtField* field, bool is_read) {
diff --git a/runtime/common_throws.h b/runtime/common_throws.h
index ab25543..945dc2d 100644
--- a/runtime/common_throws.h
+++ b/runtime/common_throws.h
@@ -178,9 +178,6 @@
const Signature& signature)
REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
-void ThrowNoSuchMethodError(uint32_t method_idx)
- REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
-
// NullPointerException
void ThrowNullPointerExceptionForFieldAccess(ArtField* field,
diff --git a/runtime/debugger.cc b/runtime/debugger.cc
index 9f3c2aa..b49c01c 100644
--- a/runtime/debugger.cc
+++ b/runtime/debugger.cc
@@ -28,6 +28,7 @@
#include "class_linker.h"
#include "class_linker-inl.h"
#include "dex_file-inl.h"
+#include "dex_file_annotations.h"
#include "dex_instruction.h"
#include "entrypoints/runtime_asm_entrypoints.h"
#include "gc/accounting/card_table-inl.h"
@@ -1986,7 +1987,7 @@
if (error != JDWP::ERR_NONE) {
return JDWP::ERR_INVALID_OBJECT;
}
- ScopedAssertNoThreadSuspension ants(soa.Self(), "Debugger: GetThreadGroup");
+ ScopedAssertNoThreadSuspension ants("Debugger: GetThreadGroup");
// Okay, so it's an object, but is it actually a thread?
DecodeThread(soa, thread_id, &error);
if (error == JDWP::ERR_THREAD_NOT_ALIVE) {
@@ -2036,7 +2037,7 @@
if (error != JDWP::ERR_NONE) {
return error;
}
- ScopedAssertNoThreadSuspension ants(soa.Self(), "Debugger: GetThreadGroupName");
+ ScopedAssertNoThreadSuspension ants("Debugger: GetThreadGroupName");
ArtField* f = soa.DecodeField(WellKnownClasses::java_lang_ThreadGroup_name);
CHECK(f != nullptr);
mirror::String* s = reinterpret_cast<mirror::String*>(f->GetObject(thread_group));
@@ -2055,7 +2056,7 @@
}
mirror::Object* parent;
{
- ScopedAssertNoThreadSuspension ants(soa.Self(), "Debugger: GetThreadGroupParent");
+ ScopedAssertNoThreadSuspension ants("Debugger: GetThreadGroupParent");
ArtField* f = soa.DecodeField(WellKnownClasses::java_lang_ThreadGroup_parent);
CHECK(f != nullptr);
parent = f->GetObject(thread_group);
@@ -3694,8 +3695,8 @@
mirror::DexCache* dex_cache = m->GetDeclaringClass()->GetDexCache();
method = m;
if (dex_cache != nullptr) {
- const DexFile& dex_file = *dex_cache->GetDexFile();
- line_number = dex_file.GetLineNumFromPC(m, GetDexPc());
+ const DexFile* dex_file = dex_cache->GetDexFile();
+ line_number = annotations::GetLineNumFromPC(dex_file, m, GetDexPc());
}
}
}
diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc
index 76cd348..ccc4c16 100644
--- a/runtime/dex_file.cc
+++ b/runtime/dex_file.cc
@@ -27,28 +27,20 @@
#include <memory>
#include <sstream>
-#include "art_field-inl.h"
-#include "art_method-inl.h"
#include "base/enums.h"
#include "base/file_magic.h"
#include "base/hash_map.h"
#include "base/logging.h"
#include "base/stl_util.h"
-#include "base/stringprintf.h"
#include "base/systrace.h"
#include "base/unix_file/fd_file.h"
#include "class_linker-inl.h"
#include "dex_file-inl.h"
#include "dex_file_verifier.h"
#include "globals.h"
-#include "handle_scope-inl.h"
#include "jvalue.h"
#include "leb128.h"
-#include "mirror/field.h"
-#include "mirror/method.h"
-#include "mirror/string.h"
#include "os.h"
-#include "reflection.h"
#include "safe_map.h"
#include "thread.h"
#include "type_lookup_table.h"
@@ -864,22 +856,6 @@
return Signature(this, *proto_id);
}
-int32_t DexFile::GetLineNumFromPC(ArtMethod* method, uint32_t rel_pc) const {
- // For native method, lineno should be -2 to indicate it is native. Note that
- // "line number == -2" is how libcore tells from StackTraceElement.
- if (method->GetCodeItemOffset() == 0) {
- return -2;
- }
-
- const CodeItem* code_item = GetCodeItem(method->GetCodeItemOffset());
- DCHECK(code_item != nullptr) << PrettyMethod(method) << " " << GetLocation();
-
- // A method with no line number info should return -1
- LineNumFromPcContext context(rel_pc, -1);
- DecodeDebugPositionInfo(code_item, LineNumForPcCb, &context);
- return context.line_num_;
-}
-
int32_t DexFile::FindTryItem(const CodeItem &code_item, uint32_t address) {
// Note: Signed type is important for max and min.
int32_t min = 0;
@@ -1186,7 +1162,7 @@
}
// Read a signed integer. "zwidth" is the zero-based byte count.
-static int32_t ReadSignedInt(const uint8_t* ptr, int zwidth) {
+int32_t DexFile::ReadSignedInt(const uint8_t* ptr, int zwidth) {
int32_t val = 0;
for (int i = zwidth; i >= 0; --i) {
val = ((uint32_t)val >> 8) | (((int32_t)*ptr++) << 24);
@@ -1197,7 +1173,7 @@
// Read an unsigned integer. "zwidth" is the zero-based byte count,
// "fill_on_right" indicates which side we want to zero-fill from.
-static uint32_t ReadUnsignedInt(const uint8_t* ptr, int zwidth, bool fill_on_right) {
+uint32_t DexFile::ReadUnsignedInt(const uint8_t* ptr, int zwidth, bool fill_on_right) {
uint32_t val = 0;
for (int i = zwidth; i >= 0; --i) {
val = (val >> 8) | (((uint32_t)*ptr++) << 24);
@@ -1209,7 +1185,7 @@
}
// Read a signed long. "zwidth" is the zero-based byte count.
-static int64_t ReadSignedLong(const uint8_t* ptr, int zwidth) {
+int64_t DexFile::ReadSignedLong(const uint8_t* ptr, int zwidth) {
int64_t val = 0;
for (int i = zwidth; i >= 0; --i) {
val = ((uint64_t)val >> 8) | (((int64_t)*ptr++) << 56);
@@ -1220,7 +1196,7 @@
// Read an unsigned long. "zwidth" is the zero-based byte count,
// "fill_on_right" indicates which side we want to zero-fill from.
-static uint64_t ReadUnsignedLong(const uint8_t* ptr, int zwidth, bool fill_on_right) {
+uint64_t DexFile::ReadUnsignedLong(const uint8_t* ptr, int zwidth, bool fill_on_right) {
uint64_t val = 0;
for (int i = zwidth; i >= 0; --i) {
val = (val >> 8) | (((uint64_t)*ptr++) << 56);
@@ -1233,1150 +1209,6 @@
// Checks that visibility is as expected. Includes special behavior for M and
// before to allow runtime and build visibility when expecting runtime.
-static bool IsVisibilityCompatible(uint32_t actual, uint32_t expected) {
- if (expected == DexFile::kDexVisibilityRuntime) {
- int32_t sdk_version = Runtime::Current()->GetTargetSdkVersion();
- if (sdk_version > 0 && sdk_version <= 23) {
- return actual == DexFile::kDexVisibilityRuntime || actual == DexFile::kDexVisibilityBuild;
- }
- }
- return actual == expected;
-}
-
-const DexFile::AnnotationSetItem* DexFile::FindAnnotationSetForField(ArtField* field) const {
- mirror::Class* klass = field->GetDeclaringClass();
- const AnnotationsDirectoryItem* annotations_dir = GetAnnotationsDirectory(*klass->GetClassDef());
- if (annotations_dir == nullptr) {
- return nullptr;
- }
- const FieldAnnotationsItem* field_annotations = GetFieldAnnotations(annotations_dir);
- if (field_annotations == nullptr) {
- return nullptr;
- }
- uint32_t field_index = field->GetDexFieldIndex();
- uint32_t field_count = annotations_dir->fields_size_;
- for (uint32_t i = 0; i < field_count; ++i) {
- if (field_annotations[i].field_idx_ == field_index) {
- return GetFieldAnnotationSetItem(field_annotations[i]);
- }
- }
- return nullptr;
-}
-
-mirror::Object* DexFile::GetAnnotationForField(ArtField* field,
- Handle<mirror::Class> annotation_class) const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForField(field);
- if (annotation_set == nullptr) {
- return nullptr;
- }
- StackHandleScope<1> hs(Thread::Current());
- Handle<mirror::Class> field_class(hs.NewHandle(field->GetDeclaringClass()));
- return GetAnnotationObjectFromAnnotationSet(
- field_class, annotation_set, kDexVisibilityRuntime, annotation_class);
-}
-
-mirror::ObjectArray<mirror::Object>* DexFile::GetAnnotationsForField(ArtField* field) const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForField(field);
- StackHandleScope<1> hs(Thread::Current());
- Handle<mirror::Class> field_class(hs.NewHandle(field->GetDeclaringClass()));
- return ProcessAnnotationSet(field_class, annotation_set, kDexVisibilityRuntime);
-}
-
-mirror::ObjectArray<mirror::String>* DexFile::GetSignatureAnnotationForField(ArtField* field)
- const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForField(field);
- if (annotation_set == nullptr) {
- return nullptr;
- }
- StackHandleScope<1> hs(Thread::Current());
- Handle<mirror::Class> field_class(hs.NewHandle(field->GetDeclaringClass()));
- return GetSignatureValue(field_class, annotation_set);
-}
-
-bool DexFile::IsFieldAnnotationPresent(ArtField* field, Handle<mirror::Class> annotation_class)
- const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForField(field);
- if (annotation_set == nullptr) {
- return false;
- }
- StackHandleScope<1> hs(Thread::Current());
- Handle<mirror::Class> field_class(hs.NewHandle(field->GetDeclaringClass()));
- const AnnotationItem* annotation_item = GetAnnotationItemFromAnnotationSet(
- field_class, annotation_set, kDexVisibilityRuntime, annotation_class);
- return annotation_item != nullptr;
-}
-
-const DexFile::AnnotationSetItem* DexFile::FindAnnotationSetForMethod(ArtMethod* method) const {
- mirror::Class* klass = method->GetDeclaringClass();
- const AnnotationsDirectoryItem* annotations_dir = GetAnnotationsDirectory(*klass->GetClassDef());
- if (annotations_dir == nullptr) {
- return nullptr;
- }
- const MethodAnnotationsItem* method_annotations = GetMethodAnnotations(annotations_dir);
- if (method_annotations == nullptr) {
- return nullptr;
- }
- uint32_t method_index = method->GetDexMethodIndex();
- uint32_t method_count = annotations_dir->methods_size_;
- for (uint32_t i = 0; i < method_count; ++i) {
- if (method_annotations[i].method_idx_ == method_index) {
- return GetMethodAnnotationSetItem(method_annotations[i]);
- }
- }
- return nullptr;
-}
-
-const DexFile::ParameterAnnotationsItem* DexFile::FindAnnotationsItemForMethod(ArtMethod* method)
- const {
- mirror::Class* klass = method->GetDeclaringClass();
- const AnnotationsDirectoryItem* annotations_dir = GetAnnotationsDirectory(*klass->GetClassDef());
- if (annotations_dir == nullptr) {
- return nullptr;
- }
- const ParameterAnnotationsItem* parameter_annotations = GetParameterAnnotations(annotations_dir);
- if (parameter_annotations == nullptr) {
- return nullptr;
- }
- uint32_t method_index = method->GetDexMethodIndex();
- uint32_t parameter_count = annotations_dir->parameters_size_;
- for (uint32_t i = 0; i < parameter_count; ++i) {
- if (parameter_annotations[i].method_idx_ == method_index) {
- return ¶meter_annotations[i];
- }
- }
- return nullptr;
-}
-
-mirror::Object* DexFile::GetAnnotationDefaultValue(ArtMethod* method) const {
- mirror::Class* klass = method->GetDeclaringClass();
- const AnnotationsDirectoryItem* annotations_dir = GetAnnotationsDirectory(*klass->GetClassDef());
- if (annotations_dir == nullptr) {
- return nullptr;
- }
- const AnnotationSetItem* annotation_set = GetClassAnnotationSet(annotations_dir);
- if (annotation_set == nullptr) {
- return nullptr;
- }
- const AnnotationItem* annotation_item = SearchAnnotationSet(annotation_set,
- "Ldalvik/annotation/AnnotationDefault;", kDexVisibilitySystem);
- if (annotation_item == nullptr) {
- return nullptr;
- }
- const uint8_t* annotation = SearchEncodedAnnotation(annotation_item->annotation_, "value");
- if (annotation == nullptr) {
- return nullptr;
- }
- uint8_t header_byte = *(annotation++);
- if ((header_byte & kDexAnnotationValueTypeMask) != kDexAnnotationAnnotation) {
- return nullptr;
- }
- annotation = SearchEncodedAnnotation(annotation, method->GetName());
- if (annotation == nullptr) {
- return nullptr;
- }
- AnnotationValue annotation_value;
- StackHandleScope<2> hs(Thread::Current());
- Handle<mirror::Class> h_klass(hs.NewHandle(klass));
- PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
- Handle<mirror::Class> return_type(hs.NewHandle(
- method->GetReturnType(true /* resolve */, pointer_size)));
- if (!ProcessAnnotationValue(h_klass, &annotation, &annotation_value, return_type, kAllObjects)) {
- return nullptr;
- }
- return annotation_value.value_.GetL();
-}
-
-mirror::Object* DexFile::GetAnnotationForMethod(ArtMethod* method,
- Handle<mirror::Class> annotation_class) const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForMethod(method);
- if (annotation_set == nullptr) {
- return nullptr;
- }
- StackHandleScope<1> hs(Thread::Current());
- Handle<mirror::Class> method_class(hs.NewHandle(method->GetDeclaringClass()));
- return GetAnnotationObjectFromAnnotationSet(method_class, annotation_set,
- kDexVisibilityRuntime, annotation_class);
-}
-
-mirror::ObjectArray<mirror::Object>* DexFile::GetAnnotationsForMethod(ArtMethod* method) const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForMethod(method);
- StackHandleScope<1> hs(Thread::Current());
- Handle<mirror::Class> method_class(hs.NewHandle(method->GetDeclaringClass()));
- return ProcessAnnotationSet(method_class, annotation_set, kDexVisibilityRuntime);
-}
-
-mirror::ObjectArray<mirror::Class>* DexFile::GetExceptionTypesForMethod(ArtMethod* method) const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForMethod(method);
- if (annotation_set == nullptr) {
- return nullptr;
- }
- StackHandleScope<1> hs(Thread::Current());
- Handle<mirror::Class> method_class(hs.NewHandle(method->GetDeclaringClass()));
- return GetThrowsValue(method_class, annotation_set);
-}
-
-mirror::ObjectArray<mirror::Object>* DexFile::GetParameterAnnotations(ArtMethod* method) const {
- const ParameterAnnotationsItem* parameter_annotations = FindAnnotationsItemForMethod(method);
- if (parameter_annotations == nullptr) {
- return nullptr;
- }
- const AnnotationSetRefList* set_ref_list =
- GetParameterAnnotationSetRefList(parameter_annotations);
- if (set_ref_list == nullptr) {
- return nullptr;
- }
- uint32_t size = set_ref_list->size_;
- StackHandleScope<1> hs(Thread::Current());
- Handle<mirror::Class> method_class(hs.NewHandle(method->GetDeclaringClass()));
- return ProcessAnnotationSetRefList(method_class, set_ref_list, size);
-}
-
-mirror::Object* DexFile::GetAnnotationForMethodParameter(ArtMethod* method,
- uint32_t parameter_idx,
- Handle<mirror::Class> annotation_class)
- const {
- const ParameterAnnotationsItem* parameter_annotations = FindAnnotationsItemForMethod(method);
- if (parameter_annotations == nullptr) {
- return nullptr;
- }
- const AnnotationSetRefList* set_ref_list =
- GetParameterAnnotationSetRefList(parameter_annotations);
- if (set_ref_list == nullptr) {
- return nullptr;
- }
-
- if (parameter_idx >= set_ref_list->size_) {
- return nullptr;
- }
- const AnnotationSetRefItem* annotation_set_ref = &set_ref_list->list_[parameter_idx];
- const AnnotationSetItem* annotation_set = GetSetRefItemItem(annotation_set_ref);
-
- StackHandleScope<1> hs(Thread::Current());
- Handle<mirror::Class> method_class(hs.NewHandle(method->GetDeclaringClass()));
- return GetAnnotationObjectFromAnnotationSet(method_class,
- annotation_set,
- kDexVisibilityRuntime,
- annotation_class);
-}
-
-mirror::ObjectArray<mirror::String>* DexFile::GetSignatureAnnotationForMethod(ArtMethod* method)
- const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForMethod(method);
- if (annotation_set == nullptr) {
- return nullptr;
- }
- StackHandleScope<1> hs(Thread::Current());
- Handle<mirror::Class> method_class(hs.NewHandle(method->GetDeclaringClass()));
- return GetSignatureValue(method_class, annotation_set);
-}
-
-bool DexFile::IsMethodAnnotationPresent(ArtMethod* method,
- Handle<mirror::Class> annotation_class,
- uint32_t visibility /* = kDexVisibilityRuntime */)
- const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForMethod(method);
- if (annotation_set == nullptr) {
- return false;
- }
- StackHandleScope<1> hs(Thread::Current());
- Handle<mirror::Class> method_class(hs.NewHandle(method->GetDeclaringClass()));
- const AnnotationItem* annotation_item = GetAnnotationItemFromAnnotationSet(method_class,
- annotation_set,
- visibility,
- annotation_class);
- return annotation_item != nullptr;
-}
-
-const DexFile::AnnotationSetItem* DexFile::FindAnnotationSetForClass(Handle<mirror::Class> klass)
- const {
- const AnnotationsDirectoryItem* annotations_dir = GetAnnotationsDirectory(*klass->GetClassDef());
- if (annotations_dir == nullptr) {
- return nullptr;
- }
- return GetClassAnnotationSet(annotations_dir);
-}
-
-mirror::Object* DexFile::GetAnnotationForClass(Handle<mirror::Class> klass,
- Handle<mirror::Class> annotation_class) const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
- if (annotation_set == nullptr) {
- return nullptr;
- }
- return GetAnnotationObjectFromAnnotationSet(klass, annotation_set, kDexVisibilityRuntime,
- annotation_class);
-}
-
-mirror::ObjectArray<mirror::Object>* DexFile::GetAnnotationsForClass(Handle<mirror::Class> klass)
- const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
- return ProcessAnnotationSet(klass, annotation_set, kDexVisibilityRuntime);
-}
-
-mirror::ObjectArray<mirror::Class>* DexFile::GetDeclaredClasses(Handle<mirror::Class> klass) const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
- if (annotation_set == nullptr) {
- return nullptr;
- }
- const AnnotationItem* annotation_item = SearchAnnotationSet(
- annotation_set, "Ldalvik/annotation/MemberClasses;", kDexVisibilitySystem);
- if (annotation_item == nullptr) {
- return nullptr;
- }
- StackHandleScope<1> hs(Thread::Current());
- mirror::Class* class_class = mirror::Class::GetJavaLangClass();
- Handle<mirror::Class> class_array_class(hs.NewHandle(
- Runtime::Current()->GetClassLinker()->FindArrayClass(hs.Self(), &class_class)));
- if (class_array_class.Get() == nullptr) {
- return nullptr;
- }
- mirror::Object* obj = GetAnnotationValue(
- klass, annotation_item, "value", class_array_class, kDexAnnotationArray);
- if (obj == nullptr) {
- return nullptr;
- }
- return obj->AsObjectArray<mirror::Class>();
-}
-
-mirror::Class* DexFile::GetDeclaringClass(Handle<mirror::Class> klass) const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
- if (annotation_set == nullptr) {
- return nullptr;
- }
- const AnnotationItem* annotation_item = SearchAnnotationSet(
- annotation_set, "Ldalvik/annotation/EnclosingClass;", kDexVisibilitySystem);
- if (annotation_item == nullptr) {
- return nullptr;
- }
- mirror::Object* obj = GetAnnotationValue(klass,
- annotation_item,
- "value",
- ScopedNullHandle<mirror::Class>(),
- kDexAnnotationType);
- if (obj == nullptr) {
- return nullptr;
- }
- return obj->AsClass();
-}
-
-mirror::Class* DexFile::GetEnclosingClass(Handle<mirror::Class> klass) const {
- mirror::Class* declaring_class = GetDeclaringClass(klass);
- if (declaring_class != nullptr) {
- return declaring_class;
- }
- const AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
- if (annotation_set == nullptr) {
- return nullptr;
- }
- const AnnotationItem* annotation_item = SearchAnnotationSet(
- annotation_set, "Ldalvik/annotation/EnclosingMethod;", kDexVisibilitySystem);
- if (annotation_item == nullptr) {
- return nullptr;
- }
- const uint8_t* annotation = SearchEncodedAnnotation(annotation_item->annotation_, "value");
- if (annotation == nullptr) {
- return nullptr;
- }
- AnnotationValue annotation_value;
- if (!ProcessAnnotationValue(klass,
- &annotation,
- &annotation_value,
- ScopedNullHandle<mirror::Class>(),
- kAllRaw)) {
- return nullptr;
- }
- if (annotation_value.type_ != kDexAnnotationMethod) {
- return nullptr;
- }
- StackHandleScope<2> hs(Thread::Current());
- Handle<mirror::DexCache> dex_cache(hs.NewHandle(klass->GetDexCache()));
- Handle<mirror::ClassLoader> class_loader(hs.NewHandle(klass->GetClassLoader()));
- ArtMethod* method = Runtime::Current()->GetClassLinker()->ResolveMethodWithoutInvokeType(
- klass->GetDexFile(), annotation_value.value_.GetI(), dex_cache, class_loader);
- if (method == nullptr) {
- return nullptr;
- }
- return method->GetDeclaringClass();
-}
-
-mirror::Object* DexFile::GetEnclosingMethod(Handle<mirror::Class> klass) const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
- if (annotation_set == nullptr) {
- return nullptr;
- }
- const AnnotationItem* annotation_item = SearchAnnotationSet(
- annotation_set, "Ldalvik/annotation/EnclosingMethod;", kDexVisibilitySystem);
- if (annotation_item == nullptr) {
- return nullptr;
- }
- return GetAnnotationValue(
- klass, annotation_item, "value", ScopedNullHandle<mirror::Class>(), kDexAnnotationMethod);
-}
-
-bool DexFile::GetInnerClass(Handle<mirror::Class> klass, mirror::String** name) const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
- if (annotation_set == nullptr) {
- return false;
- }
- const AnnotationItem* annotation_item = SearchAnnotationSet(
- annotation_set, "Ldalvik/annotation/InnerClass;", kDexVisibilitySystem);
- if (annotation_item == nullptr) {
- return false;
- }
- const uint8_t* annotation = SearchEncodedAnnotation(annotation_item->annotation_, "name");
- if (annotation == nullptr) {
- return false;
- }
- AnnotationValue annotation_value;
- if (!ProcessAnnotationValue(klass,
- &annotation,
- &annotation_value,
- ScopedNullHandle<mirror::Class>(),
- kAllObjects)) {
- return false;
- }
- if (annotation_value.type_ != kDexAnnotationNull &&
- annotation_value.type_ != kDexAnnotationString) {
- return false;
- }
- *name = down_cast<mirror::String*>(annotation_value.value_.GetL());
- return true;
-}
-
-bool DexFile::GetInnerClassFlags(Handle<mirror::Class> klass, uint32_t* flags) const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
- if (annotation_set == nullptr) {
- return false;
- }
- const AnnotationItem* annotation_item = SearchAnnotationSet(
- annotation_set, "Ldalvik/annotation/InnerClass;", kDexVisibilitySystem);
- if (annotation_item == nullptr) {
- return false;
- }
- const uint8_t* annotation = SearchEncodedAnnotation(annotation_item->annotation_, "accessFlags");
- if (annotation == nullptr) {
- return false;
- }
- AnnotationValue annotation_value;
- if (!ProcessAnnotationValue(klass,
- &annotation,
- &annotation_value,
- ScopedNullHandle<mirror::Class>(),
- kAllRaw)) {
- return false;
- }
- if (annotation_value.type_ != kDexAnnotationInt) {
- return false;
- }
- *flags = annotation_value.value_.GetI();
- return true;
-}
-
-mirror::ObjectArray<mirror::String>* DexFile::GetSignatureAnnotationForClass(
- Handle<mirror::Class> klass) const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
- if (annotation_set == nullptr) {
- return nullptr;
- }
- return GetSignatureValue(klass, annotation_set);
-}
-
-bool DexFile::IsClassAnnotationPresent(Handle<mirror::Class> klass,
- Handle<mirror::Class> annotation_class) const {
- const AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
- if (annotation_set == nullptr) {
- return false;
- }
- const AnnotationItem* annotation_item = GetAnnotationItemFromAnnotationSet(
- klass, annotation_set, kDexVisibilityRuntime, annotation_class);
- return annotation_item != nullptr;
-}
-
-mirror::Object* DexFile::CreateAnnotationMember(Handle<mirror::Class> klass,
- Handle<mirror::Class> annotation_class, const uint8_t** annotation) const {
- Thread* self = Thread::Current();
- ScopedObjectAccessUnchecked soa(self);
- StackHandleScope<5> hs(self);
- uint32_t element_name_index = DecodeUnsignedLeb128(annotation);
- const char* name = StringDataByIdx(element_name_index);
- Handle<mirror::String> string_name(
- hs.NewHandle(mirror::String::AllocFromModifiedUtf8(self, name)));
-
- PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
- ArtMethod* annotation_method =
- annotation_class->FindDeclaredVirtualMethodByName(name, pointer_size);
- if (annotation_method == nullptr) {
- return nullptr;
- }
- Handle<mirror::Class> method_return(hs.NewHandle(
- annotation_method->GetReturnType(true /* resolve */, pointer_size)));
-
- AnnotationValue annotation_value;
- if (!ProcessAnnotationValue(klass, annotation, &annotation_value, method_return, kAllObjects)) {
- return nullptr;
- }
- Handle<mirror::Object> value_object(hs.NewHandle(annotation_value.value_.GetL()));
-
- mirror::Class* annotation_member_class =
- WellKnownClasses::ToClass(WellKnownClasses::libcore_reflect_AnnotationMember);
- Handle<mirror::Object> new_member(hs.NewHandle(annotation_member_class->AllocObject(self)));
- mirror::Method* method_obj_ptr;
- DCHECK(!Runtime::Current()->IsActiveTransaction());
- if (pointer_size == PointerSize::k64) {
- method_obj_ptr = mirror::Method::CreateFromArtMethod<PointerSize::k64, false>(
- self, annotation_method);
- } else {
- method_obj_ptr = mirror::Method::CreateFromArtMethod<PointerSize::k32, false>(
- self, annotation_method);
- }
- Handle<mirror::Method> method_object(hs.NewHandle(method_obj_ptr));
-
- if (new_member.Get() == nullptr || string_name.Get() == nullptr ||
- method_object.Get() == nullptr || method_return.Get() == nullptr) {
- LOG(ERROR) << StringPrintf("Failed creating annotation element (m=%p n=%p a=%p r=%p",
- new_member.Get(), string_name.Get(), method_object.Get(), method_return.Get());
- return nullptr;
- }
-
- JValue result;
- ArtMethod* annotation_member_init =
- soa.DecodeMethod(WellKnownClasses::libcore_reflect_AnnotationMember_init);
- uint32_t args[5] = { static_cast<uint32_t>(reinterpret_cast<uintptr_t>(new_member.Get())),
- static_cast<uint32_t>(reinterpret_cast<uintptr_t>(string_name.Get())),
- static_cast<uint32_t>(reinterpret_cast<uintptr_t>(value_object.Get())),
- static_cast<uint32_t>(reinterpret_cast<uintptr_t>(method_return.Get())),
- static_cast<uint32_t>(reinterpret_cast<uintptr_t>(method_object.Get()))
- };
- annotation_member_init->Invoke(self, args, sizeof(args), &result, "VLLLL");
- if (self->IsExceptionPending()) {
- LOG(INFO) << "Exception in AnnotationMember.<init>";
- return nullptr;
- }
-
- return new_member.Get();
-}
-
-const DexFile::AnnotationItem* DexFile::GetAnnotationItemFromAnnotationSet(
- Handle<mirror::Class> klass, const AnnotationSetItem* annotation_set, uint32_t visibility,
- Handle<mirror::Class> annotation_class) const {
- for (uint32_t i = 0; i < annotation_set->size_; ++i) {
- const AnnotationItem* annotation_item = GetAnnotationItem(annotation_set, i);
- if (!IsVisibilityCompatible(annotation_item->visibility_, visibility)) {
- continue;
- }
- const uint8_t* annotation = annotation_item->annotation_;
- uint32_t type_index = DecodeUnsignedLeb128(&annotation);
- mirror::Class* resolved_class = Runtime::Current()->GetClassLinker()->ResolveType(
- klass->GetDexFile(), type_index, klass.Get());
- if (resolved_class == nullptr) {
- std::string temp;
- LOG(WARNING) << StringPrintf("Unable to resolve %s annotation class %d",
- klass->GetDescriptor(&temp), type_index);
- CHECK(Thread::Current()->IsExceptionPending());
- Thread::Current()->ClearException();
- continue;
- }
- if (resolved_class == annotation_class.Get()) {
- return annotation_item;
- }
- }
-
- return nullptr;
-}
-
-mirror::Object* DexFile::GetAnnotationObjectFromAnnotationSet(Handle<mirror::Class> klass,
- const AnnotationSetItem* annotation_set, uint32_t visibility,
- Handle<mirror::Class> annotation_class) const {
- const AnnotationItem* annotation_item =
- GetAnnotationItemFromAnnotationSet(klass, annotation_set, visibility, annotation_class);
- if (annotation_item == nullptr) {
- return nullptr;
- }
- const uint8_t* annotation = annotation_item->annotation_;
- return ProcessEncodedAnnotation(klass, &annotation);
-}
-
-mirror::Object* DexFile::GetAnnotationValue(Handle<mirror::Class> klass,
- const AnnotationItem* annotation_item, const char* annotation_name,
- Handle<mirror::Class> array_class, uint32_t expected_type) const {
- const uint8_t* annotation =
- SearchEncodedAnnotation(annotation_item->annotation_, annotation_name);
- if (annotation == nullptr) {
- return nullptr;
- }
- AnnotationValue annotation_value;
- if (!ProcessAnnotationValue(klass, &annotation, &annotation_value, array_class, kAllObjects)) {
- return nullptr;
- }
- if (annotation_value.type_ != expected_type) {
- return nullptr;
- }
- return annotation_value.value_.GetL();
-}
-
-mirror::ObjectArray<mirror::String>* DexFile::GetSignatureValue(Handle<mirror::Class> klass,
- const AnnotationSetItem* annotation_set) const {
- StackHandleScope<1> hs(Thread::Current());
- const AnnotationItem* annotation_item =
- SearchAnnotationSet(annotation_set, "Ldalvik/annotation/Signature;", kDexVisibilitySystem);
- if (annotation_item == nullptr) {
- return nullptr;
- }
- mirror::Class* string_class = mirror::String::GetJavaLangString();
- Handle<mirror::Class> string_array_class(hs.NewHandle(
- Runtime::Current()->GetClassLinker()->FindArrayClass(Thread::Current(), &string_class)));
- if (string_array_class.Get() == nullptr) {
- return nullptr;
- }
- mirror::Object* obj =
- GetAnnotationValue(klass, annotation_item, "value", string_array_class, kDexAnnotationArray);
- if (obj == nullptr) {
- return nullptr;
- }
- return obj->AsObjectArray<mirror::String>();
-}
-
-mirror::ObjectArray<mirror::Class>* DexFile::GetThrowsValue(Handle<mirror::Class> klass,
- const AnnotationSetItem* annotation_set) const {
- StackHandleScope<1> hs(Thread::Current());
- const AnnotationItem* annotation_item =
- SearchAnnotationSet(annotation_set, "Ldalvik/annotation/Throws;", kDexVisibilitySystem);
- if (annotation_item == nullptr) {
- return nullptr;
- }
- mirror::Class* class_class = mirror::Class::GetJavaLangClass();
- Handle<mirror::Class> class_array_class(hs.NewHandle(
- Runtime::Current()->GetClassLinker()->FindArrayClass(Thread::Current(), &class_class)));
- if (class_array_class.Get() == nullptr) {
- return nullptr;
- }
- mirror::Object* obj =
- GetAnnotationValue(klass, annotation_item, "value", class_array_class, kDexAnnotationArray);
- if (obj == nullptr) {
- return nullptr;
- }
- return obj->AsObjectArray<mirror::Class>();
-}
-
-mirror::ObjectArray<mirror::Object>* DexFile::ProcessAnnotationSet(Handle<mirror::Class> klass,
- const AnnotationSetItem* annotation_set, uint32_t visibility) const {
- Thread* self = Thread::Current();
- ScopedObjectAccessUnchecked soa(self);
- StackHandleScope<2> hs(self);
- Handle<mirror::Class> annotation_array_class(hs.NewHandle(
- soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_annotation_Annotation__array)));
- if (annotation_set == nullptr) {
- return mirror::ObjectArray<mirror::Object>::Alloc(self, annotation_array_class.Get(), 0);
- }
-
- uint32_t size = annotation_set->size_;
- Handle<mirror::ObjectArray<mirror::Object>> result(hs.NewHandle(
- mirror::ObjectArray<mirror::Object>::Alloc(self, annotation_array_class.Get(), size)));
- if (result.Get() == nullptr) {
- return nullptr;
- }
-
- uint32_t dest_index = 0;
- for (uint32_t i = 0; i < size; ++i) {
- const AnnotationItem* annotation_item = GetAnnotationItem(annotation_set, i);
- // Note that we do not use IsVisibilityCompatible here because older code
- // was correct for this case.
- if (annotation_item->visibility_ != visibility) {
- continue;
- }
- const uint8_t* annotation = annotation_item->annotation_;
- mirror::Object* annotation_obj = ProcessEncodedAnnotation(klass, &annotation);
- if (annotation_obj != nullptr) {
- result->SetWithoutChecks<false>(dest_index, annotation_obj);
- ++dest_index;
- } else if (self->IsExceptionPending()) {
- return nullptr;
- }
- }
-
- if (dest_index == size) {
- return result.Get();
- }
-
- mirror::ObjectArray<mirror::Object>* trimmed_result =
- mirror::ObjectArray<mirror::Object>::Alloc(self, annotation_array_class.Get(), dest_index);
- if (trimmed_result == nullptr) {
- return nullptr;
- }
-
- for (uint32_t i = 0; i < dest_index; ++i) {
- mirror::Object* obj = result->GetWithoutChecks(i);
- trimmed_result->SetWithoutChecks<false>(i, obj);
- }
-
- return trimmed_result;
-}
-
-mirror::ObjectArray<mirror::Object>* DexFile::ProcessAnnotationSetRefList(
- Handle<mirror::Class> klass, const AnnotationSetRefList* set_ref_list, uint32_t size) const {
- Thread* self = Thread::Current();
- ScopedObjectAccessUnchecked soa(self);
- StackHandleScope<1> hs(self);
- mirror::Class* annotation_array_class =
- soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_annotation_Annotation__array);
- mirror::Class* annotation_array_array_class =
- Runtime::Current()->GetClassLinker()->FindArrayClass(self, &annotation_array_class);
- if (annotation_array_array_class == nullptr) {
- return nullptr;
- }
- Handle<mirror::ObjectArray<mirror::Object>> annotation_array_array(hs.NewHandle(
- mirror::ObjectArray<mirror::Object>::Alloc(self, annotation_array_array_class, size)));
- if (annotation_array_array.Get() == nullptr) {
- LOG(ERROR) << "Annotation set ref array allocation failed";
- return nullptr;
- }
- for (uint32_t index = 0; index < size; ++index) {
- const AnnotationSetRefItem* set_ref_item = &set_ref_list->list_[index];
- const AnnotationSetItem* set_item = GetSetRefItemItem(set_ref_item);
- mirror::Object* annotation_set = ProcessAnnotationSet(klass, set_item, kDexVisibilityRuntime);
- if (annotation_set == nullptr) {
- return nullptr;
- }
- annotation_array_array->SetWithoutChecks<false>(index, annotation_set);
- }
- return annotation_array_array.Get();
-}
-
-bool DexFile::ProcessAnnotationValue(Handle<mirror::Class> klass, const uint8_t** annotation_ptr,
- AnnotationValue* annotation_value, Handle<mirror::Class> array_class,
- DexFile::AnnotationResultStyle result_style) const {
- Thread* self = Thread::Current();
- mirror::Object* element_object = nullptr;
- bool set_object = false;
- Primitive::Type primitive_type = Primitive::kPrimVoid;
- const uint8_t* annotation = *annotation_ptr;
- uint8_t header_byte = *(annotation++);
- uint8_t value_type = header_byte & kDexAnnotationValueTypeMask;
- uint8_t value_arg = header_byte >> kDexAnnotationValueArgShift;
- int32_t width = value_arg + 1;
- annotation_value->type_ = value_type;
-
- switch (value_type) {
- case kDexAnnotationByte:
- annotation_value->value_.SetB(static_cast<int8_t>(ReadSignedInt(annotation, value_arg)));
- primitive_type = Primitive::kPrimByte;
- break;
- case kDexAnnotationShort:
- annotation_value->value_.SetS(static_cast<int16_t>(ReadSignedInt(annotation, value_arg)));
- primitive_type = Primitive::kPrimShort;
- break;
- case kDexAnnotationChar:
- annotation_value->value_.SetC(static_cast<uint16_t>(ReadUnsignedInt(annotation, value_arg,
- false)));
- primitive_type = Primitive::kPrimChar;
- break;
- case kDexAnnotationInt:
- annotation_value->value_.SetI(ReadSignedInt(annotation, value_arg));
- primitive_type = Primitive::kPrimInt;
- break;
- case kDexAnnotationLong:
- annotation_value->value_.SetJ(ReadSignedLong(annotation, value_arg));
- primitive_type = Primitive::kPrimLong;
- break;
- case kDexAnnotationFloat:
- annotation_value->value_.SetI(ReadUnsignedInt(annotation, value_arg, true));
- primitive_type = Primitive::kPrimFloat;
- break;
- case kDexAnnotationDouble:
- annotation_value->value_.SetJ(ReadUnsignedLong(annotation, value_arg, true));
- primitive_type = Primitive::kPrimDouble;
- break;
- case kDexAnnotationBoolean:
- annotation_value->value_.SetZ(value_arg != 0);
- primitive_type = Primitive::kPrimBoolean;
- width = 0;
- break;
- case kDexAnnotationString: {
- uint32_t index = ReadUnsignedInt(annotation, value_arg, false);
- if (result_style == kAllRaw) {
- annotation_value->value_.SetI(index);
- } else {
- StackHandleScope<1> hs(self);
- Handle<mirror::DexCache> dex_cache(hs.NewHandle(klass->GetDexCache()));
- element_object = Runtime::Current()->GetClassLinker()->ResolveString(
- klass->GetDexFile(), index, dex_cache);
- set_object = true;
- if (element_object == nullptr) {
- return false;
- }
- }
- break;
- }
- case kDexAnnotationType: {
- uint32_t index = ReadUnsignedInt(annotation, value_arg, false);
- if (result_style == kAllRaw) {
- annotation_value->value_.SetI(index);
- } else {
- element_object = Runtime::Current()->GetClassLinker()->ResolveType(
- klass->GetDexFile(), index, klass.Get());
- set_object = true;
- if (element_object == nullptr) {
- CHECK(self->IsExceptionPending());
- if (result_style == kAllObjects) {
- const char* msg = StringByTypeIdx(index);
- self->ThrowNewWrappedException("Ljava/lang/TypeNotPresentException;", msg);
- element_object = self->GetException();
- self->ClearException();
- } else {
- return false;
- }
- }
- }
- break;
- }
- case kDexAnnotationMethod: {
- uint32_t index = ReadUnsignedInt(annotation, value_arg, false);
- if (result_style == kAllRaw) {
- annotation_value->value_.SetI(index);
- } else {
- StackHandleScope<2> hs(self);
- Handle<mirror::DexCache> dex_cache(hs.NewHandle(klass->GetDexCache()));
- Handle<mirror::ClassLoader> class_loader(hs.NewHandle(klass->GetClassLoader()));
- ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
- ArtMethod* method = class_linker->ResolveMethodWithoutInvokeType(
- klass->GetDexFile(), index, dex_cache, class_loader);
- if (method == nullptr) {
- return false;
- }
- PointerSize pointer_size = class_linker->GetImagePointerSize();
- set_object = true;
- DCHECK(!Runtime::Current()->IsActiveTransaction());
- if (method->IsConstructor()) {
- if (pointer_size == PointerSize::k64) {
- element_object = mirror::Constructor::CreateFromArtMethod<PointerSize::k64,
- false>(self, method);
- } else {
- element_object = mirror::Constructor::CreateFromArtMethod<PointerSize::k32,
- false>(self, method);
- }
- } else {
- if (pointer_size == PointerSize::k64) {
- element_object = mirror::Method::CreateFromArtMethod<PointerSize::k64,
- false>(self, method);
- } else {
- element_object = mirror::Method::CreateFromArtMethod<PointerSize::k32,
- false>(self, method);
- }
- }
- if (element_object == nullptr) {
- return false;
- }
- }
- break;
- }
- case kDexAnnotationField: {
- uint32_t index = ReadUnsignedInt(annotation, value_arg, false);
- if (result_style == kAllRaw) {
- annotation_value->value_.SetI(index);
- } else {
- StackHandleScope<2> hs(self);
- Handle<mirror::DexCache> dex_cache(hs.NewHandle(klass->GetDexCache()));
- Handle<mirror::ClassLoader> class_loader(hs.NewHandle(klass->GetClassLoader()));
- ArtField* field = Runtime::Current()->GetClassLinker()->ResolveFieldJLS(
- klass->GetDexFile(), index, dex_cache, class_loader);
- if (field == nullptr) {
- return false;
- }
- set_object = true;
- PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
- if (pointer_size == PointerSize::k64) {
- element_object = mirror::Field::CreateFromArtField<PointerSize::k64>(self, field, true);
- } else {
- element_object = mirror::Field::CreateFromArtField<PointerSize::k32>(self, field, true);
- }
- if (element_object == nullptr) {
- return false;
- }
- }
- break;
- }
- case kDexAnnotationEnum: {
- uint32_t index = ReadUnsignedInt(annotation, value_arg, false);
- if (result_style == kAllRaw) {
- annotation_value->value_.SetI(index);
- } else {
- StackHandleScope<3> hs(self);
- Handle<mirror::DexCache> dex_cache(hs.NewHandle(klass->GetDexCache()));
- Handle<mirror::ClassLoader> class_loader(hs.NewHandle(klass->GetClassLoader()));
- ArtField* enum_field = Runtime::Current()->GetClassLinker()->ResolveField(
- klass->GetDexFile(), index, dex_cache, class_loader, true);
- if (enum_field == nullptr) {
- return false;
- } else {
- Handle<mirror::Class> field_class(hs.NewHandle(enum_field->GetDeclaringClass()));
- Runtime::Current()->GetClassLinker()->EnsureInitialized(self, field_class, true, true);
- element_object = enum_field->GetObject(field_class.Get());
- set_object = true;
- }
- }
- break;
- }
- case kDexAnnotationArray:
- if (result_style == kAllRaw || array_class.Get() == nullptr) {
- return false;
- } else {
- ScopedObjectAccessUnchecked soa(self);
- StackHandleScope<2> hs(self);
- uint32_t size = DecodeUnsignedLeb128(&annotation);
- Handle<mirror::Class> component_type(hs.NewHandle(array_class->GetComponentType()));
- Handle<mirror::Array> new_array(hs.NewHandle(mirror::Array::Alloc<true>(
- self, array_class.Get(), size, array_class->GetComponentSizeShift(),
- Runtime::Current()->GetHeap()->GetCurrentAllocator())));
- if (new_array.Get() == nullptr) {
- LOG(ERROR) << "Annotation element array allocation failed with size " << size;
- return false;
- }
- AnnotationValue new_annotation_value;
- for (uint32_t i = 0; i < size; ++i) {
- if (!ProcessAnnotationValue(klass, &annotation, &new_annotation_value, component_type,
- kPrimitivesOrObjects)) {
- return false;
- }
- if (!component_type->IsPrimitive()) {
- mirror::Object* obj = new_annotation_value.value_.GetL();
- new_array->AsObjectArray<mirror::Object>()->SetWithoutChecks<false>(i, obj);
- } else {
- switch (new_annotation_value.type_) {
- case kDexAnnotationByte:
- new_array->AsByteArray()->SetWithoutChecks<false>(
- i, new_annotation_value.value_.GetB());
- break;
- case kDexAnnotationShort:
- new_array->AsShortArray()->SetWithoutChecks<false>(
- i, new_annotation_value.value_.GetS());
- break;
- case kDexAnnotationChar:
- new_array->AsCharArray()->SetWithoutChecks<false>(
- i, new_annotation_value.value_.GetC());
- break;
- case kDexAnnotationInt:
- new_array->AsIntArray()->SetWithoutChecks<false>(
- i, new_annotation_value.value_.GetI());
- break;
- case kDexAnnotationLong:
- new_array->AsLongArray()->SetWithoutChecks<false>(
- i, new_annotation_value.value_.GetJ());
- break;
- case kDexAnnotationFloat:
- new_array->AsFloatArray()->SetWithoutChecks<false>(
- i, new_annotation_value.value_.GetF());
- break;
- case kDexAnnotationDouble:
- new_array->AsDoubleArray()->SetWithoutChecks<false>(
- i, new_annotation_value.value_.GetD());
- break;
- case kDexAnnotationBoolean:
- new_array->AsBooleanArray()->SetWithoutChecks<false>(
- i, new_annotation_value.value_.GetZ());
- break;
- default:
- LOG(FATAL) << "Found invalid annotation value type while building annotation array";
- return false;
- }
- }
- }
- element_object = new_array.Get();
- set_object = true;
- width = 0;
- }
- break;
- case kDexAnnotationAnnotation:
- if (result_style == kAllRaw) {
- return false;
- }
- element_object = ProcessEncodedAnnotation(klass, &annotation);
- if (element_object == nullptr) {
- return false;
- }
- set_object = true;
- width = 0;
- break;
- case kDexAnnotationNull:
- if (result_style == kAllRaw) {
- annotation_value->value_.SetI(0);
- } else {
- CHECK(element_object == nullptr);
- set_object = true;
- }
- width = 0;
- break;
- default:
- LOG(ERROR) << StringPrintf("Bad annotation element value type 0x%02x", value_type);
- return false;
- }
-
- annotation += width;
- *annotation_ptr = annotation;
-
- if (result_style == kAllObjects && primitive_type != Primitive::kPrimVoid) {
- element_object = BoxPrimitive(primitive_type, annotation_value->value_);
- set_object = true;
- }
-
- if (set_object) {
- annotation_value->value_.SetL(element_object);
- }
-
- return true;
-}
-
-mirror::Object* DexFile::ProcessEncodedAnnotation(Handle<mirror::Class> klass,
- const uint8_t** annotation) const {
- uint32_t type_index = DecodeUnsignedLeb128(annotation);
- uint32_t size = DecodeUnsignedLeb128(annotation);
-
- Thread* self = Thread::Current();
- ScopedObjectAccessUnchecked soa(self);
- StackHandleScope<2> hs(self);
- ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
- Handle<mirror::Class> annotation_class(hs.NewHandle(
- class_linker->ResolveType(klass->GetDexFile(), type_index, klass.Get())));
- if (annotation_class.Get() == nullptr) {
- LOG(INFO) << "Unable to resolve " << PrettyClass(klass.Get()) << " annotation class "
- << type_index;
- DCHECK(Thread::Current()->IsExceptionPending());
- Thread::Current()->ClearException();
- return nullptr;
- }
-
- mirror::Class* annotation_member_class =
- soa.Decode<mirror::Class*>(WellKnownClasses::libcore_reflect_AnnotationMember);
- mirror::Class* annotation_member_array_class =
- class_linker->FindArrayClass(self, &annotation_member_class);
- if (annotation_member_array_class == nullptr) {
- return nullptr;
- }
- mirror::ObjectArray<mirror::Object>* element_array = nullptr;
- if (size > 0) {
- element_array =
- mirror::ObjectArray<mirror::Object>::Alloc(self, annotation_member_array_class, size);
- if (element_array == nullptr) {
- LOG(ERROR) << "Failed to allocate annotation member array (" << size << " elements)";
- return nullptr;
- }
- }
-
- Handle<mirror::ObjectArray<mirror::Object>> h_element_array(hs.NewHandle(element_array));
- for (uint32_t i = 0; i < size; ++i) {
- mirror::Object* new_member = CreateAnnotationMember(klass, annotation_class, annotation);
- if (new_member == nullptr) {
- return nullptr;
- }
- h_element_array->SetWithoutChecks<false>(i, new_member);
- }
-
- JValue result;
- ArtMethod* create_annotation_method =
- soa.DecodeMethod(WellKnownClasses::libcore_reflect_AnnotationFactory_createAnnotation);
- uint32_t args[2] = { static_cast<uint32_t>(reinterpret_cast<uintptr_t>(annotation_class.Get())),
- static_cast<uint32_t>(reinterpret_cast<uintptr_t>(h_element_array.Get())) };
- create_annotation_method->Invoke(self, args, sizeof(args), &result, "LLL");
- if (self->IsExceptionPending()) {
- LOG(INFO) << "Exception in AnnotationFactory.createAnnotation";
- return nullptr;
- }
-
- return result.GetL();
-}
-
-const DexFile::AnnotationItem* DexFile::SearchAnnotationSet(const AnnotationSetItem* annotation_set,
- const char* descriptor, uint32_t visibility) const {
- const AnnotationItem* result = nullptr;
- for (uint32_t i = 0; i < annotation_set->size_; ++i) {
- const AnnotationItem* annotation_item = GetAnnotationItem(annotation_set, i);
- if (!IsVisibilityCompatible(annotation_item->visibility_, visibility)) {
- continue;
- }
- const uint8_t* annotation = annotation_item->annotation_;
- uint32_t type_index = DecodeUnsignedLeb128(&annotation);
-
- if (strcmp(descriptor, StringByTypeIdx(type_index)) == 0) {
- result = annotation_item;
- break;
- }
- }
- return result;
-}
-
-const uint8_t* DexFile::SearchEncodedAnnotation(const uint8_t* annotation, const char* name) const {
- DecodeUnsignedLeb128(&annotation); // unused type_index
- uint32_t size = DecodeUnsignedLeb128(&annotation);
-
- while (size != 0) {
- uint32_t element_name_index = DecodeUnsignedLeb128(&annotation);
- const char* element_name = GetStringData(GetStringId(element_name_index));
- if (strcmp(name, element_name) == 0) {
- return annotation;
- }
- SkipAnnotationValue(&annotation);
- size--;
- }
- return nullptr;
-}
-
-bool DexFile::SkipAnnotationValue(const uint8_t** annotation_ptr) const {
- const uint8_t* annotation = *annotation_ptr;
- uint8_t header_byte = *(annotation++);
- uint8_t value_type = header_byte & kDexAnnotationValueTypeMask;
- uint8_t value_arg = header_byte >> kDexAnnotationValueArgShift;
- int32_t width = value_arg + 1;
-
- switch (value_type) {
- case kDexAnnotationByte:
- case kDexAnnotationShort:
- case kDexAnnotationChar:
- case kDexAnnotationInt:
- case kDexAnnotationLong:
- case kDexAnnotationFloat:
- case kDexAnnotationDouble:
- case kDexAnnotationString:
- case kDexAnnotationType:
- case kDexAnnotationMethod:
- case kDexAnnotationField:
- case kDexAnnotationEnum:
- break;
- case kDexAnnotationArray:
- {
- uint32_t size = DecodeUnsignedLeb128(&annotation);
- while (size--) {
- if (!SkipAnnotationValue(&annotation)) {
- return false;
- }
- }
- width = 0;
- break;
- }
- case kDexAnnotationAnnotation:
- {
- DecodeUnsignedLeb128(&annotation); // unused type_index
- uint32_t size = DecodeUnsignedLeb128(&annotation);
- while (size--) {
- DecodeUnsignedLeb128(&annotation); // unused element_name_index
- if (!SkipAnnotationValue(&annotation)) {
- return false;
- }
- }
- width = 0;
- break;
- }
- case kDexAnnotationBoolean:
- case kDexAnnotationNull:
- width = 0;
- break;
- default:
- LOG(FATAL) << StringPrintf("Bad annotation element value byte 0x%02x", value_type);
- return false;
- }
-
- annotation += width;
- *annotation_ptr = annotation;
- return true;
-}
-
std::ostream& operator<<(std::ostream& os, const DexFile& dex_file) {
os << StringPrintf("[DexFile: %s dex-checksum=%08x location-checksum=%08x %p-%p]",
dex_file.GetLocation().c_str(),
@@ -2460,50 +1292,13 @@
}
}
-EncodedStaticFieldValueIterator::EncodedStaticFieldValueIterator(
- const DexFile& dex_file,
- const DexFile::ClassDef& class_def)
- : EncodedStaticFieldValueIterator(dex_file,
- nullptr,
- nullptr,
- nullptr,
- class_def,
- -1,
- kByte) {
-}
-
-EncodedStaticFieldValueIterator::EncodedStaticFieldValueIterator(
- const DexFile& dex_file,
- Handle<mirror::DexCache>* dex_cache,
- Handle<mirror::ClassLoader>* class_loader,
- ClassLinker* linker,
- const DexFile::ClassDef& class_def)
- : EncodedStaticFieldValueIterator(dex_file,
- dex_cache, class_loader,
- linker,
- class_def,
- -1,
- kByte) {
- DCHECK(dex_cache_ != nullptr);
- DCHECK(class_loader_ != nullptr);
-}
-
-EncodedStaticFieldValueIterator::EncodedStaticFieldValueIterator(
- const DexFile& dex_file,
- Handle<mirror::DexCache>* dex_cache,
- Handle<mirror::ClassLoader>* class_loader,
- ClassLinker* linker,
- const DexFile::ClassDef& class_def,
- size_t pos,
- ValueType type)
+EncodedStaticFieldValueIterator::EncodedStaticFieldValueIterator(const DexFile& dex_file,
+ const DexFile::ClassDef& class_def)
: dex_file_(dex_file),
- dex_cache_(dex_cache),
- class_loader_(class_loader),
- linker_(linker),
array_size_(),
- pos_(pos),
- type_(type) {
- ptr_ = dex_file.GetEncodedStaticFieldValuesArray(class_def);
+ pos_(-1),
+ type_(kByte) {
+ ptr_ = dex_file_.GetEncodedStaticFieldValuesArray(class_def);
if (ptr_ == nullptr) {
array_size_ = 0;
} else {
@@ -2529,32 +1324,32 @@
width = 0;
break;
case kByte:
- jval_.i = ReadSignedInt(ptr_, value_arg);
+ jval_.i = DexFile::ReadSignedInt(ptr_, value_arg);
CHECK(IsInt<8>(jval_.i));
break;
case kShort:
- jval_.i = ReadSignedInt(ptr_, value_arg);
+ jval_.i = DexFile::ReadSignedInt(ptr_, value_arg);
CHECK(IsInt<16>(jval_.i));
break;
case kChar:
- jval_.i = ReadUnsignedInt(ptr_, value_arg, false);
+ jval_.i = DexFile::ReadUnsignedInt(ptr_, value_arg, false);
CHECK(IsUint<16>(jval_.i));
break;
case kInt:
- jval_.i = ReadSignedInt(ptr_, value_arg);
+ jval_.i = DexFile::ReadSignedInt(ptr_, value_arg);
break;
case kLong:
- jval_.j = ReadSignedLong(ptr_, value_arg);
+ jval_.j = DexFile::ReadSignedLong(ptr_, value_arg);
break;
case kFloat:
- jval_.i = ReadUnsignedInt(ptr_, value_arg, true);
+ jval_.i = DexFile::ReadUnsignedInt(ptr_, value_arg, true);
break;
case kDouble:
- jval_.j = ReadUnsignedLong(ptr_, value_arg, true);
+ jval_.j = DexFile::ReadUnsignedLong(ptr_, value_arg, true);
break;
case kString:
case kType:
- jval_.i = ReadUnsignedInt(ptr_, value_arg, false);
+ jval_.i = DexFile::ReadUnsignedInt(ptr_, value_arg, false);
break;
case kField:
case kMethod:
@@ -2574,38 +1369,6 @@
ptr_ += width;
}
-template<bool kTransactionActive>
-void EncodedStaticFieldValueIterator::ReadValueToField(ArtField* field) const {
- DCHECK(dex_cache_ != nullptr);
- DCHECK(class_loader_ != nullptr);
- switch (type_) {
- case kBoolean: field->SetBoolean<kTransactionActive>(field->GetDeclaringClass(), jval_.z);
- break;
- case kByte: field->SetByte<kTransactionActive>(field->GetDeclaringClass(), jval_.b); break;
- case kShort: field->SetShort<kTransactionActive>(field->GetDeclaringClass(), jval_.s); break;
- case kChar: field->SetChar<kTransactionActive>(field->GetDeclaringClass(), jval_.c); break;
- case kInt: field->SetInt<kTransactionActive>(field->GetDeclaringClass(), jval_.i); break;
- case kLong: field->SetLong<kTransactionActive>(field->GetDeclaringClass(), jval_.j); break;
- case kFloat: field->SetFloat<kTransactionActive>(field->GetDeclaringClass(), jval_.f); break;
- case kDouble: field->SetDouble<kTransactionActive>(field->GetDeclaringClass(), jval_.d); break;
- case kNull: field->SetObject<kTransactionActive>(field->GetDeclaringClass(), nullptr); break;
- case kString: {
- mirror::String* resolved = linker_->ResolveString(dex_file_, jval_.i, *dex_cache_);
- field->SetObject<kTransactionActive>(field->GetDeclaringClass(), resolved);
- break;
- }
- case kType: {
- mirror::Class* resolved = linker_->ResolveType(dex_file_, jval_.i, *dex_cache_,
- *class_loader_);
- field->SetObject<kTransactionActive>(field->GetDeclaringClass(), resolved);
- break;
- }
- default: UNIMPLEMENTED(FATAL) << ": type " << type_;
- }
-}
-template void EncodedStaticFieldValueIterator::ReadValueToField<true>(ArtField* field) const;
-template void EncodedStaticFieldValueIterator::ReadValueToField<false>(ArtField* field) const;
-
CatchHandlerIterator::CatchHandlerIterator(const DexFile::CodeItem& code_item, uint32_t address) {
handler_.address_ = -1;
int32_t offset = -1;
diff --git a/runtime/dex_file.h b/runtime/dex_file.h
index 23676bd..0ae36f7 100644
--- a/runtime/dex_file.h
+++ b/runtime/dex_file.h
@@ -27,27 +27,14 @@
#include "globals.h"
#include "invoke_type.h"
#include "jni.h"
-#include "mirror/object_array.h"
#include "modifiers.h"
#include "utf.h"
namespace art {
-// TODO: remove dependencies on mirror classes, primarily by moving
-// EncodedStaticFieldValueIterator to its own file.
-namespace mirror {
- class ClassLoader;
- class DexCache;
-} // namespace mirror
-class ArtField;
-class ArtMethod;
-class ClassLinker;
-template <class Key, class Value, class EmptyFn, class HashFn, class Pred, class Alloc>
-class HashMap;
class MemMap;
class OatDexFile;
class Signature;
-template<class T> class Handle;
class StringPiece;
class TypeLookupTable;
class ZipArchive;
@@ -402,6 +389,8 @@
kAllRaw
};
+ struct AnnotationValue;
+
// Returns the checksum of a file for comparison with GetLocationChecksum().
// For .dex files, this is the header checksum.
// For zip files, this is the classes.dex zip entry CRC32 checksum.
@@ -934,110 +923,6 @@
return reinterpret_cast<const AnnotationSetItem*>(begin_ + offset);
}
- const AnnotationSetItem* FindAnnotationSetForField(ArtField* field) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::Object* GetAnnotationForField(ArtField* field, Handle<mirror::Class> annotation_class)
- const REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::ObjectArray<mirror::Object>* GetAnnotationsForField(ArtField* field) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForField(ArtField* field) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- bool IsFieldAnnotationPresent(ArtField* field, Handle<mirror::Class> annotation_class) const
- REQUIRES_SHARED(Locks::mutator_lock_);
-
- const AnnotationSetItem* FindAnnotationSetForMethod(ArtMethod* method) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- const ParameterAnnotationsItem* FindAnnotationsItemForMethod(ArtMethod* method) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::Object* GetAnnotationDefaultValue(ArtMethod* method) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::Object* GetAnnotationForMethod(ArtMethod* method, Handle<mirror::Class> annotation_class)
- const REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::Object* GetAnnotationForMethodParameter(ArtMethod* method,
- uint32_t parameter_idx,
- Handle<mirror::Class> annotation_class) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::ObjectArray<mirror::Object>* GetAnnotationsForMethod(ArtMethod* method) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::ObjectArray<mirror::Class>* GetExceptionTypesForMethod(ArtMethod* method) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::ObjectArray<mirror::Object>* GetParameterAnnotations(ArtMethod* method) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForMethod(ArtMethod* method) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- bool IsMethodAnnotationPresent(ArtMethod* method,
- Handle<mirror::Class> annotation_class,
- uint32_t visibility = kDexVisibilityRuntime) const
- REQUIRES_SHARED(Locks::mutator_lock_);
-
- const AnnotationSetItem* FindAnnotationSetForClass(Handle<mirror::Class> klass) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::Object* GetAnnotationForClass(Handle<mirror::Class> klass,
- Handle<mirror::Class> annotation_class) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::ObjectArray<mirror::Object>* GetAnnotationsForClass(Handle<mirror::Class> klass) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::ObjectArray<mirror::Class>* GetDeclaredClasses(Handle<mirror::Class> klass) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::Class* GetDeclaringClass(Handle<mirror::Class> klass) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::Class* GetEnclosingClass(Handle<mirror::Class> klass) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::Object* GetEnclosingMethod(Handle<mirror::Class> klass) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- bool GetInnerClass(Handle<mirror::Class> klass, mirror::String** name) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- bool GetInnerClassFlags(Handle<mirror::Class> klass, uint32_t* flags) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForClass(Handle<mirror::Class> klass)
- const REQUIRES_SHARED(Locks::mutator_lock_);
- bool IsClassAnnotationPresent(Handle<mirror::Class> klass, Handle<mirror::Class> annotation_class)
- const REQUIRES_SHARED(Locks::mutator_lock_);
-
- mirror::Object* CreateAnnotationMember(Handle<mirror::Class> klass,
- Handle<mirror::Class> annotation_class,
- const uint8_t** annotation) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- const AnnotationItem* GetAnnotationItemFromAnnotationSet(Handle<mirror::Class> klass,
- const AnnotationSetItem* annotation_set,
- uint32_t visibility,
- Handle<mirror::Class> annotation_class)
- const REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::Object* GetAnnotationObjectFromAnnotationSet(Handle<mirror::Class> klass,
- const AnnotationSetItem* annotation_set,
- uint32_t visibility,
- Handle<mirror::Class> annotation_class) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::Object* GetAnnotationValue(Handle<mirror::Class> klass,
- const AnnotationItem* annotation_item,
- const char* annotation_name,
- Handle<mirror::Class> array_class,
- uint32_t expected_type) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::ObjectArray<mirror::String>* GetSignatureValue(Handle<mirror::Class> klass,
- const AnnotationSetItem* annotation_set)
- const REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::ObjectArray<mirror::Class>* GetThrowsValue(Handle<mirror::Class> klass,
- const AnnotationSetItem* annotation_set) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::ObjectArray<mirror::Object>* ProcessAnnotationSet(Handle<mirror::Class> klass,
- const AnnotationSetItem* annotation_set,
- uint32_t visibility) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::ObjectArray<mirror::Object>* ProcessAnnotationSetRefList(Handle<mirror::Class> klass,
- const AnnotationSetRefList* set_ref_list, uint32_t size) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- mirror::Object* ProcessEncodedAnnotation(Handle<mirror::Class> klass,
- const uint8_t** annotation) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- const AnnotationItem* SearchAnnotationSet(const AnnotationSetItem* annotation_set,
- const char* descriptor, uint32_t visibility) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- const uint8_t* SearchEncodedAnnotation(const uint8_t* annotation, const char* name) const
- REQUIRES_SHARED(Locks::mutator_lock_);
- bool SkipAnnotationValue(const uint8_t** annotation_ptr) const
- REQUIRES_SHARED(Locks::mutator_lock_);
-
// Debug info opcodes and constants
enum {
DBG_END_SEQUENCE = 0x00,
@@ -1064,17 +949,6 @@
DISALLOW_COPY_AND_ASSIGN(LineNumFromPcContext);
};
- // Determine the source file line number based on the program counter.
- // "pc" is an offset, in 16-bit units, from the start of the method's code.
- //
- // Returns -1 if no match was found (possibly because the source files were
- // compiled without "-g", so no line number information is present).
- // Returns -2 for native methods (as expected in exception traces).
- //
- // This is used by runtime; therefore use art::Method not art::DexFile::Method.
- int32_t GetLineNumFromPC(ArtMethod* method, uint32_t rel_pc) const
- REQUIRES_SHARED(Locks::mutator_lock_);
-
// Returns false if there is no debugging information or if it cannot be decoded.
bool DecodeDebugLocalInfo(const CodeItem* code_item, bool is_static, uint32_t method_idx,
DexDebugNewLocalCb local_cb, void* context) const;
@@ -1140,6 +1014,12 @@
void CreateTypeLookupTable(uint8_t* storage = nullptr) const;
+ // Utility methods for reading integral values from a buffer.
+ static int32_t ReadSignedInt(const uint8_t* ptr, int zwidth);
+ static uint32_t ReadUnsignedInt(const uint8_t* ptr, int zwidth, bool fill_on_right);
+ static int64_t ReadSignedLong(const uint8_t* ptr, int zwidth);
+ static uint64_t ReadUnsignedLong(const uint8_t* ptr, int zwidth, bool fill_on_right);
+
private:
// Opens a .dex file
static std::unique_ptr<const DexFile> OpenFile(int fd,
@@ -1204,13 +1084,6 @@
// whether the string contains the separator character.
static bool IsMultiDexLocation(const char* location);
- struct AnnotationValue;
-
- bool ProcessAnnotationValue(Handle<mirror::Class> klass, const uint8_t** annotation_ptr,
- AnnotationValue* annotation_value, Handle<mirror::Class> return_class,
- DexFile::AnnotationResultStyle result_style) const
- REQUIRES_SHARED(Locks::mutator_lock_);
-
// The base address of the memory mapping.
const uint8_t* const begin_;
@@ -1514,22 +1387,9 @@
class EncodedStaticFieldValueIterator {
public:
- // A constructor for static tools. You cannot call
- // ReadValueToField() for an object created by this.
EncodedStaticFieldValueIterator(const DexFile& dex_file,
const DexFile::ClassDef& class_def);
- // A constructor meant to be called from runtime code.
- EncodedStaticFieldValueIterator(const DexFile& dex_file,
- Handle<mirror::DexCache>* dex_cache,
- Handle<mirror::ClassLoader>* class_loader,
- ClassLinker* linker,
- const DexFile::ClassDef& class_def)
- REQUIRES_SHARED(Locks::mutator_lock_);
-
- template<bool kTransactionActive>
- void ReadValueToField(ArtField* field) const REQUIRES_SHARED(Locks::mutator_lock_);
-
bool HasNext() const { return pos_ < array_size_; }
void Next();
@@ -1556,27 +1416,18 @@
ValueType GetValueType() const { return type_; }
const jvalue& GetJavaValue() const { return jval_; }
- private:
- EncodedStaticFieldValueIterator(const DexFile& dex_file,
- Handle<mirror::DexCache>* dex_cache,
- Handle<mirror::ClassLoader>* class_loader,
- ClassLinker* linker,
- const DexFile::ClassDef& class_def,
- size_t pos,
- ValueType type);
-
+ protected:
static constexpr uint8_t kEncodedValueTypeMask = 0x1f; // 0b11111
static constexpr uint8_t kEncodedValueArgShift = 5;
const DexFile& dex_file_;
- Handle<mirror::DexCache>* const dex_cache_; // Dex cache to resolve literal objects.
- Handle<mirror::ClassLoader>* const class_loader_; // ClassLoader to resolve types.
- ClassLinker* linker_; // Linker to resolve literal objects.
size_t array_size_; // Size of array.
size_t pos_; // Current position.
const uint8_t* ptr_; // Pointer into encoded data array.
ValueType type_; // Type of current encoded value.
jvalue jval_; // Value of current encoded value.
+
+ private:
DISALLOW_IMPLICIT_CONSTRUCTORS(EncodedStaticFieldValueIterator);
};
std::ostream& operator<<(std::ostream& os, const EncodedStaticFieldValueIterator::ValueType& code);
diff --git a/runtime/dex_file_annotations.cc b/runtime/dex_file_annotations.cc
new file mode 100644
index 0000000..c6c87fd
--- /dev/null
+++ b/runtime/dex_file_annotations.cc
@@ -0,0 +1,1303 @@
+/*
+ * 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.
+ */
+
+#include "dex_file_annotations.h"
+
+#include <stdlib.h>
+
+#include "art_field-inl.h"
+#include "art_method-inl.h"
+#include "class_linker-inl.h"
+#include "dex_file-inl.h"
+#include "jvalue.h"
+#include "mirror/field.h"
+#include "mirror/method.h"
+#include "reflection.h"
+#include "thread.h"
+
+namespace art {
+
+struct DexFile::AnnotationValue {
+ JValue value_;
+ uint8_t type_;
+};
+
+namespace {
+mirror::Object* CreateAnnotationMember(Handle<mirror::Class> klass,
+ Handle<mirror::Class> annotation_class,
+ const uint8_t** annotation)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+
+bool IsVisibilityCompatible(uint32_t actual, uint32_t expected) {
+ if (expected == DexFile::kDexVisibilityRuntime) {
+ int32_t sdk_version = Runtime::Current()->GetTargetSdkVersion();
+ if (sdk_version > 0 && sdk_version <= 23) {
+ return actual == DexFile::kDexVisibilityRuntime || actual == DexFile::kDexVisibilityBuild;
+ }
+ }
+ return actual == expected;
+}
+
+const DexFile::AnnotationSetItem* FindAnnotationSetForField(ArtField* field)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ const DexFile* dex_file = field->GetDexFile();
+ mirror::Class* klass = field->GetDeclaringClass();
+ const DexFile::AnnotationsDirectoryItem* annotations_dir =
+ dex_file->GetAnnotationsDirectory(*klass->GetClassDef());
+ if (annotations_dir == nullptr) {
+ return nullptr;
+ }
+ const DexFile::FieldAnnotationsItem* field_annotations =
+ dex_file->GetFieldAnnotations(annotations_dir);
+ if (field_annotations == nullptr) {
+ return nullptr;
+ }
+ uint32_t field_index = field->GetDexFieldIndex();
+ uint32_t field_count = annotations_dir->fields_size_;
+ for (uint32_t i = 0; i < field_count; ++i) {
+ if (field_annotations[i].field_idx_ == field_index) {
+ return dex_file->GetFieldAnnotationSetItem(field_annotations[i]);
+ }
+ }
+ return nullptr;
+}
+
+const DexFile::AnnotationItem* SearchAnnotationSet(const DexFile& dex_file,
+ const DexFile::AnnotationSetItem* annotation_set,
+ const char* descriptor,
+ uint32_t visibility)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ const DexFile::AnnotationItem* result = nullptr;
+ for (uint32_t i = 0; i < annotation_set->size_; ++i) {
+ const DexFile::AnnotationItem* annotation_item = dex_file.GetAnnotationItem(annotation_set, i);
+ if (!IsVisibilityCompatible(annotation_item->visibility_, visibility)) {
+ continue;
+ }
+ const uint8_t* annotation = annotation_item->annotation_;
+ uint32_t type_index = DecodeUnsignedLeb128(&annotation);
+
+ if (strcmp(descriptor, dex_file.StringByTypeIdx(type_index)) == 0) {
+ result = annotation_item;
+ break;
+ }
+ }
+ return result;
+}
+
+bool SkipAnnotationValue(const DexFile& dex_file, const uint8_t** annotation_ptr)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ const uint8_t* annotation = *annotation_ptr;
+ uint8_t header_byte = *(annotation++);
+ uint8_t value_type = header_byte & DexFile::kDexAnnotationValueTypeMask;
+ uint8_t value_arg = header_byte >> DexFile::kDexAnnotationValueArgShift;
+ int32_t width = value_arg + 1;
+
+ switch (value_type) {
+ case DexFile::kDexAnnotationByte:
+ case DexFile::kDexAnnotationShort:
+ case DexFile::kDexAnnotationChar:
+ case DexFile::kDexAnnotationInt:
+ case DexFile::kDexAnnotationLong:
+ case DexFile::kDexAnnotationFloat:
+ case DexFile::kDexAnnotationDouble:
+ case DexFile::kDexAnnotationString:
+ case DexFile::kDexAnnotationType:
+ case DexFile::kDexAnnotationMethod:
+ case DexFile::kDexAnnotationField:
+ case DexFile::kDexAnnotationEnum:
+ break;
+ case DexFile::kDexAnnotationArray:
+ {
+ uint32_t size = DecodeUnsignedLeb128(&annotation);
+ while (size--) {
+ if (!SkipAnnotationValue(dex_file, &annotation)) {
+ return false;
+ }
+ }
+ width = 0;
+ break;
+ }
+ case DexFile::kDexAnnotationAnnotation:
+ {
+ DecodeUnsignedLeb128(&annotation); // unused type_index
+ uint32_t size = DecodeUnsignedLeb128(&annotation);
+ while (size--) {
+ DecodeUnsignedLeb128(&annotation); // unused element_name_index
+ if (!SkipAnnotationValue(dex_file, &annotation)) {
+ return false;
+ }
+ }
+ width = 0;
+ break;
+ }
+ case DexFile::kDexAnnotationBoolean:
+ case DexFile::kDexAnnotationNull:
+ width = 0;
+ break;
+ default:
+ LOG(FATAL) << StringPrintf("Bad annotation element value byte 0x%02x", value_type);
+ return false;
+ }
+
+ annotation += width;
+ *annotation_ptr = annotation;
+ return true;
+}
+
+const uint8_t* SearchEncodedAnnotation(const DexFile& dex_file,
+ const uint8_t* annotation,
+ const char* name)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ DecodeUnsignedLeb128(&annotation); // unused type_index
+ uint32_t size = DecodeUnsignedLeb128(&annotation);
+
+ while (size != 0) {
+ uint32_t element_name_index = DecodeUnsignedLeb128(&annotation);
+ const char* element_name = dex_file.GetStringData(dex_file.GetStringId(element_name_index));
+ if (strcmp(name, element_name) == 0) {
+ return annotation;
+ }
+ SkipAnnotationValue(dex_file, &annotation);
+ size--;
+ }
+ return nullptr;
+}
+
+const DexFile::AnnotationSetItem* FindAnnotationSetForMethod(ArtMethod* method)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ const DexFile* dex_file = method->GetDexFile();
+ mirror::Class* klass = method->GetDeclaringClass();
+ const DexFile::AnnotationsDirectoryItem* annotations_dir =
+ dex_file->GetAnnotationsDirectory(*klass->GetClassDef());
+ if (annotations_dir == nullptr) {
+ return nullptr;
+ }
+ const DexFile::MethodAnnotationsItem* method_annotations =
+ dex_file->GetMethodAnnotations(annotations_dir);
+ if (method_annotations == nullptr) {
+ return nullptr;
+ }
+ uint32_t method_index = method->GetDexMethodIndex();
+ uint32_t method_count = annotations_dir->methods_size_;
+ for (uint32_t i = 0; i < method_count; ++i) {
+ if (method_annotations[i].method_idx_ == method_index) {
+ return dex_file->GetMethodAnnotationSetItem(method_annotations[i]);
+ }
+ }
+ return nullptr;
+}
+
+const DexFile::ParameterAnnotationsItem* FindAnnotationsItemForMethod(ArtMethod* method)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ const DexFile* dex_file = method->GetDexFile();
+ mirror::Class* klass = method->GetDeclaringClass();
+ const DexFile::AnnotationsDirectoryItem* annotations_dir =
+ dex_file->GetAnnotationsDirectory(*klass->GetClassDef());
+ if (annotations_dir == nullptr) {
+ return nullptr;
+ }
+ const DexFile::ParameterAnnotationsItem* parameter_annotations =
+ dex_file->GetParameterAnnotations(annotations_dir);
+ if (parameter_annotations == nullptr) {
+ return nullptr;
+ }
+ uint32_t method_index = method->GetDexMethodIndex();
+ uint32_t parameter_count = annotations_dir->parameters_size_;
+ for (uint32_t i = 0; i < parameter_count; ++i) {
+ if (parameter_annotations[i].method_idx_ == method_index) {
+ return ¶meter_annotations[i];
+ }
+ }
+ return nullptr;
+}
+
+const DexFile::AnnotationSetItem* FindAnnotationSetForClass(Handle<mirror::Class> klass)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ const DexFile& dex_file = klass->GetDexFile();
+ const DexFile::AnnotationsDirectoryItem* annotations_dir =
+ dex_file.GetAnnotationsDirectory(*klass->GetClassDef());
+ if (annotations_dir == nullptr) {
+ return nullptr;
+ }
+ return dex_file.GetClassAnnotationSet(annotations_dir);
+}
+
+mirror::Object* ProcessEncodedAnnotation(Handle<mirror::Class> klass, const uint8_t** annotation)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ uint32_t type_index = DecodeUnsignedLeb128(annotation);
+ uint32_t size = DecodeUnsignedLeb128(annotation);
+
+ Thread* self = Thread::Current();
+ ScopedObjectAccessUnchecked soa(self);
+ StackHandleScope<2> hs(self);
+ ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
+ Handle<mirror::Class> annotation_class(hs.NewHandle(
+ class_linker->ResolveType(klass->GetDexFile(), type_index, klass.Get())));
+ if (annotation_class.Get() == nullptr) {
+ LOG(INFO) << "Unable to resolve " << PrettyClass(klass.Get()) << " annotation class "
+ << type_index;
+ DCHECK(Thread::Current()->IsExceptionPending());
+ Thread::Current()->ClearException();
+ return nullptr;
+ }
+
+ mirror::Class* annotation_member_class =
+ soa.Decode<mirror::Class*>(WellKnownClasses::libcore_reflect_AnnotationMember);
+ mirror::Class* annotation_member_array_class =
+ class_linker->FindArrayClass(self, &annotation_member_class);
+ if (annotation_member_array_class == nullptr) {
+ return nullptr;
+ }
+ mirror::ObjectArray<mirror::Object>* element_array = nullptr;
+ if (size > 0) {
+ element_array =
+ mirror::ObjectArray<mirror::Object>::Alloc(self, annotation_member_array_class, size);
+ if (element_array == nullptr) {
+ LOG(ERROR) << "Failed to allocate annotation member array (" << size << " elements)";
+ return nullptr;
+ }
+ }
+
+ Handle<mirror::ObjectArray<mirror::Object>> h_element_array(hs.NewHandle(element_array));
+ for (uint32_t i = 0; i < size; ++i) {
+ mirror::Object* new_member = CreateAnnotationMember(klass, annotation_class, annotation);
+ if (new_member == nullptr) {
+ return nullptr;
+ }
+ h_element_array->SetWithoutChecks<false>(i, new_member);
+ }
+
+ JValue result;
+ ArtMethod* create_annotation_method =
+ soa.DecodeMethod(WellKnownClasses::libcore_reflect_AnnotationFactory_createAnnotation);
+ uint32_t args[2] = { static_cast<uint32_t>(reinterpret_cast<uintptr_t>(annotation_class.Get())),
+ static_cast<uint32_t>(reinterpret_cast<uintptr_t>(h_element_array.Get())) };
+ create_annotation_method->Invoke(self, args, sizeof(args), &result, "LLL");
+ if (self->IsExceptionPending()) {
+ LOG(INFO) << "Exception in AnnotationFactory.createAnnotation";
+ return nullptr;
+ }
+
+ return result.GetL();
+}
+
+bool ProcessAnnotationValue(Handle<mirror::Class> klass,
+ const uint8_t** annotation_ptr,
+ DexFile::AnnotationValue* annotation_value,
+ Handle<mirror::Class> array_class,
+ DexFile::AnnotationResultStyle result_style)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ const DexFile& dex_file = klass->GetDexFile();
+ Thread* self = Thread::Current();
+ mirror::Object* element_object = nullptr;
+ bool set_object = false;
+ Primitive::Type primitive_type = Primitive::kPrimVoid;
+ const uint8_t* annotation = *annotation_ptr;
+ uint8_t header_byte = *(annotation++);
+ uint8_t value_type = header_byte & DexFile::kDexAnnotationValueTypeMask;
+ uint8_t value_arg = header_byte >> DexFile::kDexAnnotationValueArgShift;
+ int32_t width = value_arg + 1;
+ annotation_value->type_ = value_type;
+
+ switch (value_type) {
+ case DexFile::kDexAnnotationByte:
+ annotation_value->value_.SetB(
+ static_cast<int8_t>(DexFile::ReadSignedInt(annotation, value_arg)));
+ primitive_type = Primitive::kPrimByte;
+ break;
+ case DexFile::kDexAnnotationShort:
+ annotation_value->value_.SetS(
+ static_cast<int16_t>(DexFile::ReadSignedInt(annotation, value_arg)));
+ primitive_type = Primitive::kPrimShort;
+ break;
+ case DexFile::kDexAnnotationChar:
+ annotation_value->value_.SetC(
+ static_cast<uint16_t>(DexFile::ReadUnsignedInt(annotation, value_arg, false)));
+ primitive_type = Primitive::kPrimChar;
+ break;
+ case DexFile::kDexAnnotationInt:
+ annotation_value->value_.SetI(DexFile::ReadSignedInt(annotation, value_arg));
+ primitive_type = Primitive::kPrimInt;
+ break;
+ case DexFile::kDexAnnotationLong:
+ annotation_value->value_.SetJ(DexFile::ReadSignedLong(annotation, value_arg));
+ primitive_type = Primitive::kPrimLong;
+ break;
+ case DexFile::kDexAnnotationFloat:
+ annotation_value->value_.SetI(DexFile::ReadUnsignedInt(annotation, value_arg, true));
+ primitive_type = Primitive::kPrimFloat;
+ break;
+ case DexFile::kDexAnnotationDouble:
+ annotation_value->value_.SetJ(DexFile::ReadUnsignedLong(annotation, value_arg, true));
+ primitive_type = Primitive::kPrimDouble;
+ break;
+ case DexFile::kDexAnnotationBoolean:
+ annotation_value->value_.SetZ(value_arg != 0);
+ primitive_type = Primitive::kPrimBoolean;
+ width = 0;
+ break;
+ case DexFile::kDexAnnotationString: {
+ uint32_t index = DexFile::ReadUnsignedInt(annotation, value_arg, false);
+ if (result_style == DexFile::kAllRaw) {
+ annotation_value->value_.SetI(index);
+ } else {
+ StackHandleScope<1> hs(self);
+ Handle<mirror::DexCache> dex_cache(hs.NewHandle(klass->GetDexCache()));
+ element_object = Runtime::Current()->GetClassLinker()->ResolveString(
+ klass->GetDexFile(), index, dex_cache);
+ set_object = true;
+ if (element_object == nullptr) {
+ return false;
+ }
+ }
+ break;
+ }
+ case DexFile::kDexAnnotationType: {
+ uint32_t index = DexFile::ReadUnsignedInt(annotation, value_arg, false);
+ if (result_style == DexFile::kAllRaw) {
+ annotation_value->value_.SetI(index);
+ } else {
+ element_object = Runtime::Current()->GetClassLinker()->ResolveType(
+ klass->GetDexFile(), index, klass.Get());
+ set_object = true;
+ if (element_object == nullptr) {
+ CHECK(self->IsExceptionPending());
+ if (result_style == DexFile::kAllObjects) {
+ const char* msg = dex_file.StringByTypeIdx(index);
+ self->ThrowNewWrappedException("Ljava/lang/TypeNotPresentException;", msg);
+ element_object = self->GetException();
+ self->ClearException();
+ } else {
+ return false;
+ }
+ }
+ }
+ break;
+ }
+ case DexFile::kDexAnnotationMethod: {
+ uint32_t index = DexFile::ReadUnsignedInt(annotation, value_arg, false);
+ if (result_style == DexFile::kAllRaw) {
+ annotation_value->value_.SetI(index);
+ } else {
+ StackHandleScope<2> hs(self);
+ Handle<mirror::DexCache> dex_cache(hs.NewHandle(klass->GetDexCache()));
+ Handle<mirror::ClassLoader> class_loader(hs.NewHandle(klass->GetClassLoader()));
+ ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
+ ArtMethod* method = class_linker->ResolveMethodWithoutInvokeType(
+ klass->GetDexFile(), index, dex_cache, class_loader);
+ if (method == nullptr) {
+ return false;
+ }
+ PointerSize pointer_size = class_linker->GetImagePointerSize();
+ set_object = true;
+ DCHECK(!Runtime::Current()->IsActiveTransaction());
+ if (method->IsConstructor()) {
+ if (pointer_size == PointerSize::k64) {
+ element_object = mirror::Constructor::CreateFromArtMethod<PointerSize::k64,
+ false>(self, method);
+ } else {
+ element_object = mirror::Constructor::CreateFromArtMethod<PointerSize::k32,
+ false>(self, method);
+ }
+ } else {
+ if (pointer_size == PointerSize::k64) {
+ element_object = mirror::Method::CreateFromArtMethod<PointerSize::k64,
+ false>(self, method);
+ } else {
+ element_object = mirror::Method::CreateFromArtMethod<PointerSize::k32,
+ false>(self, method);
+ }
+ }
+ if (element_object == nullptr) {
+ return false;
+ }
+ }
+ break;
+ }
+ case DexFile::kDexAnnotationField: {
+ uint32_t index = DexFile::ReadUnsignedInt(annotation, value_arg, false);
+ if (result_style == DexFile::kAllRaw) {
+ annotation_value->value_.SetI(index);
+ } else {
+ StackHandleScope<2> hs(self);
+ Handle<mirror::DexCache> dex_cache(hs.NewHandle(klass->GetDexCache()));
+ Handle<mirror::ClassLoader> class_loader(hs.NewHandle(klass->GetClassLoader()));
+ ArtField* field = Runtime::Current()->GetClassLinker()->ResolveFieldJLS(
+ klass->GetDexFile(), index, dex_cache, class_loader);
+ if (field == nullptr) {
+ return false;
+ }
+ set_object = true;
+ PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
+ if (pointer_size == PointerSize::k64) {
+ element_object = mirror::Field::CreateFromArtField<PointerSize::k64>(self, field, true);
+ } else {
+ element_object = mirror::Field::CreateFromArtField<PointerSize::k32>(self, field, true);
+ }
+ if (element_object == nullptr) {
+ return false;
+ }
+ }
+ break;
+ }
+ case DexFile::kDexAnnotationEnum: {
+ uint32_t index = DexFile::ReadUnsignedInt(annotation, value_arg, false);
+ if (result_style == DexFile::kAllRaw) {
+ annotation_value->value_.SetI(index);
+ } else {
+ StackHandleScope<3> hs(self);
+ Handle<mirror::DexCache> dex_cache(hs.NewHandle(klass->GetDexCache()));
+ Handle<mirror::ClassLoader> class_loader(hs.NewHandle(klass->GetClassLoader()));
+ ArtField* enum_field = Runtime::Current()->GetClassLinker()->ResolveField(
+ klass->GetDexFile(), index, dex_cache, class_loader, true);
+ if (enum_field == nullptr) {
+ return false;
+ } else {
+ Handle<mirror::Class> field_class(hs.NewHandle(enum_field->GetDeclaringClass()));
+ Runtime::Current()->GetClassLinker()->EnsureInitialized(self, field_class, true, true);
+ element_object = enum_field->GetObject(field_class.Get());
+ set_object = true;
+ }
+ }
+ break;
+ }
+ case DexFile::kDexAnnotationArray:
+ if (result_style == DexFile::kAllRaw || array_class.Get() == nullptr) {
+ return false;
+ } else {
+ ScopedObjectAccessUnchecked soa(self);
+ StackHandleScope<2> hs(self);
+ uint32_t size = DecodeUnsignedLeb128(&annotation);
+ Handle<mirror::Class> component_type(hs.NewHandle(array_class->GetComponentType()));
+ Handle<mirror::Array> new_array(hs.NewHandle(mirror::Array::Alloc<true>(
+ self, array_class.Get(), size, array_class->GetComponentSizeShift(),
+ Runtime::Current()->GetHeap()->GetCurrentAllocator())));
+ if (new_array.Get() == nullptr) {
+ LOG(ERROR) << "Annotation element array allocation failed with size " << size;
+ return false;
+ }
+ DexFile::AnnotationValue new_annotation_value;
+ for (uint32_t i = 0; i < size; ++i) {
+ if (!ProcessAnnotationValue(klass, &annotation, &new_annotation_value,
+ component_type, DexFile::kPrimitivesOrObjects)) {
+ return false;
+ }
+ if (!component_type->IsPrimitive()) {
+ mirror::Object* obj = new_annotation_value.value_.GetL();
+ new_array->AsObjectArray<mirror::Object>()->SetWithoutChecks<false>(i, obj);
+ } else {
+ switch (new_annotation_value.type_) {
+ case DexFile::kDexAnnotationByte:
+ new_array->AsByteArray()->SetWithoutChecks<false>(
+ i, new_annotation_value.value_.GetB());
+ break;
+ case DexFile::kDexAnnotationShort:
+ new_array->AsShortArray()->SetWithoutChecks<false>(
+ i, new_annotation_value.value_.GetS());
+ break;
+ case DexFile::kDexAnnotationChar:
+ new_array->AsCharArray()->SetWithoutChecks<false>(
+ i, new_annotation_value.value_.GetC());
+ break;
+ case DexFile::kDexAnnotationInt:
+ new_array->AsIntArray()->SetWithoutChecks<false>(
+ i, new_annotation_value.value_.GetI());
+ break;
+ case DexFile::kDexAnnotationLong:
+ new_array->AsLongArray()->SetWithoutChecks<false>(
+ i, new_annotation_value.value_.GetJ());
+ break;
+ case DexFile::kDexAnnotationFloat:
+ new_array->AsFloatArray()->SetWithoutChecks<false>(
+ i, new_annotation_value.value_.GetF());
+ break;
+ case DexFile::kDexAnnotationDouble:
+ new_array->AsDoubleArray()->SetWithoutChecks<false>(
+ i, new_annotation_value.value_.GetD());
+ break;
+ case DexFile::kDexAnnotationBoolean:
+ new_array->AsBooleanArray()->SetWithoutChecks<false>(
+ i, new_annotation_value.value_.GetZ());
+ break;
+ default:
+ LOG(FATAL) << "Found invalid annotation value type while building annotation array";
+ return false;
+ }
+ }
+ }
+ element_object = new_array.Get();
+ set_object = true;
+ width = 0;
+ }
+ break;
+ case DexFile::kDexAnnotationAnnotation:
+ if (result_style == DexFile::kAllRaw) {
+ return false;
+ }
+ element_object = ProcessEncodedAnnotation(klass, &annotation);
+ if (element_object == nullptr) {
+ return false;
+ }
+ set_object = true;
+ width = 0;
+ break;
+ case DexFile::kDexAnnotationNull:
+ if (result_style == DexFile::kAllRaw) {
+ annotation_value->value_.SetI(0);
+ } else {
+ CHECK(element_object == nullptr);
+ set_object = true;
+ }
+ width = 0;
+ break;
+ default:
+ LOG(ERROR) << StringPrintf("Bad annotation element value type 0x%02x", value_type);
+ return false;
+ }
+
+ annotation += width;
+ *annotation_ptr = annotation;
+
+ if (result_style == DexFile::kAllObjects && primitive_type != Primitive::kPrimVoid) {
+ element_object = BoxPrimitive(primitive_type, annotation_value->value_);
+ set_object = true;
+ }
+
+ if (set_object) {
+ annotation_value->value_.SetL(element_object);
+ }
+
+ return true;
+}
+
+mirror::Object* CreateAnnotationMember(Handle<mirror::Class> klass,
+ Handle<mirror::Class> annotation_class,
+ const uint8_t** annotation) {
+ const DexFile& dex_file = klass->GetDexFile();
+ Thread* self = Thread::Current();
+ ScopedObjectAccessUnchecked soa(self);
+ StackHandleScope<5> hs(self);
+ uint32_t element_name_index = DecodeUnsignedLeb128(annotation);
+ const char* name = dex_file.StringDataByIdx(element_name_index);
+ Handle<mirror::String> string_name(
+ hs.NewHandle(mirror::String::AllocFromModifiedUtf8(self, name)));
+
+ PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
+ ArtMethod* annotation_method =
+ annotation_class->FindDeclaredVirtualMethodByName(name, pointer_size);
+ if (annotation_method == nullptr) {
+ return nullptr;
+ }
+ Handle<mirror::Class> method_return(hs.NewHandle(
+ annotation_method->GetReturnType(true /* resolve */, pointer_size)));
+
+ DexFile::AnnotationValue annotation_value;
+ if (!ProcessAnnotationValue(klass, annotation, &annotation_value, method_return,
+ DexFile::kAllObjects)) {
+ return nullptr;
+ }
+ Handle<mirror::Object> value_object(hs.NewHandle(annotation_value.value_.GetL()));
+
+ mirror::Class* annotation_member_class =
+ WellKnownClasses::ToClass(WellKnownClasses::libcore_reflect_AnnotationMember);
+ Handle<mirror::Object> new_member(hs.NewHandle(annotation_member_class->AllocObject(self)));
+ mirror::Method* method_obj_ptr;
+ DCHECK(!Runtime::Current()->IsActiveTransaction());
+ if (pointer_size == PointerSize::k64) {
+ method_obj_ptr = mirror::Method::CreateFromArtMethod<PointerSize::k64, false>(
+ self, annotation_method);
+ } else {
+ method_obj_ptr = mirror::Method::CreateFromArtMethod<PointerSize::k32, false>(
+ self, annotation_method);
+ }
+ Handle<mirror::Method> method_object(hs.NewHandle(method_obj_ptr));
+
+ if (new_member.Get() == nullptr || string_name.Get() == nullptr ||
+ method_object.Get() == nullptr || method_return.Get() == nullptr) {
+ LOG(ERROR) << StringPrintf("Failed creating annotation element (m=%p n=%p a=%p r=%p",
+ new_member.Get(), string_name.Get(), method_object.Get(), method_return.Get());
+ return nullptr;
+ }
+
+ JValue result;
+ ArtMethod* annotation_member_init =
+ soa.DecodeMethod(WellKnownClasses::libcore_reflect_AnnotationMember_init);
+ uint32_t args[5] = { static_cast<uint32_t>(reinterpret_cast<uintptr_t>(new_member.Get())),
+ static_cast<uint32_t>(reinterpret_cast<uintptr_t>(string_name.Get())),
+ static_cast<uint32_t>(reinterpret_cast<uintptr_t>(value_object.Get())),
+ static_cast<uint32_t>(reinterpret_cast<uintptr_t>(method_return.Get())),
+ static_cast<uint32_t>(reinterpret_cast<uintptr_t>(method_object.Get()))
+ };
+ annotation_member_init->Invoke(self, args, sizeof(args), &result, "VLLLL");
+ if (self->IsExceptionPending()) {
+ LOG(INFO) << "Exception in AnnotationMember.<init>";
+ return nullptr;
+ }
+
+ return new_member.Get();
+}
+
+const DexFile::AnnotationItem* GetAnnotationItemFromAnnotationSet(
+ Handle<mirror::Class> klass,
+ const DexFile::AnnotationSetItem* annotation_set,
+ uint32_t visibility,
+ Handle<mirror::Class> annotation_class)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ const DexFile& dex_file = klass->GetDexFile();
+ for (uint32_t i = 0; i < annotation_set->size_; ++i) {
+ const DexFile::AnnotationItem* annotation_item = dex_file.GetAnnotationItem(annotation_set, i);
+ if (!IsVisibilityCompatible(annotation_item->visibility_, visibility)) {
+ continue;
+ }
+ const uint8_t* annotation = annotation_item->annotation_;
+ uint32_t type_index = DecodeUnsignedLeb128(&annotation);
+ mirror::Class* resolved_class = Runtime::Current()->GetClassLinker()->ResolveType(
+ klass->GetDexFile(), type_index, klass.Get());
+ if (resolved_class == nullptr) {
+ std::string temp;
+ LOG(WARNING) << StringPrintf("Unable to resolve %s annotation class %d",
+ klass->GetDescriptor(&temp), type_index);
+ CHECK(Thread::Current()->IsExceptionPending());
+ Thread::Current()->ClearException();
+ continue;
+ }
+ if (resolved_class == annotation_class.Get()) {
+ return annotation_item;
+ }
+ }
+
+ return nullptr;
+}
+
+mirror::Object* GetAnnotationObjectFromAnnotationSet(
+ Handle<mirror::Class> klass,
+ const DexFile::AnnotationSetItem* annotation_set,
+ uint32_t visibility,
+ Handle<mirror::Class> annotation_class)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ const DexFile::AnnotationItem* annotation_item =
+ GetAnnotationItemFromAnnotationSet(klass, annotation_set, visibility, annotation_class);
+ if (annotation_item == nullptr) {
+ return nullptr;
+ }
+ const uint8_t* annotation = annotation_item->annotation_;
+ return ProcessEncodedAnnotation(klass, &annotation);
+}
+
+mirror::Object* GetAnnotationValue(Handle<mirror::Class> klass,
+ const DexFile::AnnotationItem* annotation_item,
+ const char* annotation_name,
+ Handle<mirror::Class> array_class,
+ uint32_t expected_type)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ const DexFile& dex_file = klass->GetDexFile();
+ const uint8_t* annotation =
+ SearchEncodedAnnotation(dex_file, annotation_item->annotation_, annotation_name);
+ if (annotation == nullptr) {
+ return nullptr;
+ }
+ DexFile::AnnotationValue annotation_value;
+ if (!ProcessAnnotationValue(klass, &annotation, &annotation_value, array_class,
+ DexFile::kAllObjects)) {
+ return nullptr;
+ }
+ if (annotation_value.type_ != expected_type) {
+ return nullptr;
+ }
+ return annotation_value.value_.GetL();
+}
+
+mirror::ObjectArray<mirror::String>* GetSignatureValue(Handle<mirror::Class> klass,
+ const DexFile::AnnotationSetItem* annotation_set)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ const DexFile& dex_file = klass->GetDexFile();
+ StackHandleScope<1> hs(Thread::Current());
+ const DexFile::AnnotationItem* annotation_item =
+ SearchAnnotationSet(dex_file, annotation_set, "Ldalvik/annotation/Signature;",
+ DexFile::kDexVisibilitySystem);
+ if (annotation_item == nullptr) {
+ return nullptr;
+ }
+ mirror::Class* string_class = mirror::String::GetJavaLangString();
+ Handle<mirror::Class> string_array_class(hs.NewHandle(
+ Runtime::Current()->GetClassLinker()->FindArrayClass(Thread::Current(), &string_class)));
+ if (string_array_class.Get() == nullptr) {
+ return nullptr;
+ }
+ mirror::Object* obj =
+ GetAnnotationValue(klass, annotation_item, "value", string_array_class,
+ DexFile::kDexAnnotationArray);
+ if (obj == nullptr) {
+ return nullptr;
+ }
+ return obj->AsObjectArray<mirror::String>();
+}
+
+mirror::ObjectArray<mirror::Class>* GetThrowsValue(Handle<mirror::Class> klass,
+ const DexFile::AnnotationSetItem* annotation_set)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ const DexFile& dex_file = klass->GetDexFile();
+ StackHandleScope<1> hs(Thread::Current());
+ const DexFile::AnnotationItem* annotation_item =
+ SearchAnnotationSet(dex_file, annotation_set, "Ldalvik/annotation/Throws;",
+ DexFile::kDexVisibilitySystem);
+ if (annotation_item == nullptr) {
+ return nullptr;
+ }
+ mirror::Class* class_class = mirror::Class::GetJavaLangClass();
+ Handle<mirror::Class> class_array_class(hs.NewHandle(
+ Runtime::Current()->GetClassLinker()->FindArrayClass(Thread::Current(), &class_class)));
+ if (class_array_class.Get() == nullptr) {
+ return nullptr;
+ }
+ mirror::Object* obj =
+ GetAnnotationValue(klass, annotation_item, "value", class_array_class,
+ DexFile::kDexAnnotationArray);
+ if (obj == nullptr) {
+ return nullptr;
+ }
+ return obj->AsObjectArray<mirror::Class>();
+}
+
+mirror::ObjectArray<mirror::Object>* ProcessAnnotationSet(
+ Handle<mirror::Class> klass,
+ const DexFile::AnnotationSetItem* annotation_set,
+ uint32_t visibility)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ const DexFile& dex_file = klass->GetDexFile();
+ Thread* self = Thread::Current();
+ ScopedObjectAccessUnchecked soa(self);
+ StackHandleScope<2> hs(self);
+ Handle<mirror::Class> annotation_array_class(hs.NewHandle(
+ soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_annotation_Annotation__array)));
+ if (annotation_set == nullptr) {
+ return mirror::ObjectArray<mirror::Object>::Alloc(self, annotation_array_class.Get(), 0);
+ }
+
+ uint32_t size = annotation_set->size_;
+ Handle<mirror::ObjectArray<mirror::Object>> result(hs.NewHandle(
+ mirror::ObjectArray<mirror::Object>::Alloc(self, annotation_array_class.Get(), size)));
+ if (result.Get() == nullptr) {
+ return nullptr;
+ }
+
+ uint32_t dest_index = 0;
+ for (uint32_t i = 0; i < size; ++i) {
+ const DexFile::AnnotationItem* annotation_item = dex_file.GetAnnotationItem(annotation_set, i);
+ // Note that we do not use IsVisibilityCompatible here because older code
+ // was correct for this case.
+ if (annotation_item->visibility_ != visibility) {
+ continue;
+ }
+ const uint8_t* annotation = annotation_item->annotation_;
+ mirror::Object* annotation_obj = ProcessEncodedAnnotation(klass, &annotation);
+ if (annotation_obj != nullptr) {
+ result->SetWithoutChecks<false>(dest_index, annotation_obj);
+ ++dest_index;
+ } else if (self->IsExceptionPending()) {
+ return nullptr;
+ }
+ }
+
+ if (dest_index == size) {
+ return result.Get();
+ }
+
+ mirror::ObjectArray<mirror::Object>* trimmed_result =
+ mirror::ObjectArray<mirror::Object>::Alloc(self, annotation_array_class.Get(), dest_index);
+ if (trimmed_result == nullptr) {
+ return nullptr;
+ }
+
+ for (uint32_t i = 0; i < dest_index; ++i) {
+ mirror::Object* obj = result->GetWithoutChecks(i);
+ trimmed_result->SetWithoutChecks<false>(i, obj);
+ }
+
+ return trimmed_result;
+}
+
+mirror::ObjectArray<mirror::Object>* ProcessAnnotationSetRefList(
+ Handle<mirror::Class> klass,
+ const DexFile::AnnotationSetRefList* set_ref_list,
+ uint32_t size)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ const DexFile& dex_file = klass->GetDexFile();
+ Thread* self = Thread::Current();
+ ScopedObjectAccessUnchecked soa(self);
+ StackHandleScope<1> hs(self);
+ mirror::Class* annotation_array_class =
+ soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_annotation_Annotation__array);
+ mirror::Class* annotation_array_array_class =
+ Runtime::Current()->GetClassLinker()->FindArrayClass(self, &annotation_array_class);
+ if (annotation_array_array_class == nullptr) {
+ return nullptr;
+ }
+ Handle<mirror::ObjectArray<mirror::Object>> annotation_array_array(hs.NewHandle(
+ mirror::ObjectArray<mirror::Object>::Alloc(self, annotation_array_array_class, size)));
+ if (annotation_array_array.Get() == nullptr) {
+ LOG(ERROR) << "Annotation set ref array allocation failed";
+ return nullptr;
+ }
+ for (uint32_t index = 0; index < size; ++index) {
+ const DexFile::AnnotationSetRefItem* set_ref_item = &set_ref_list->list_[index];
+ const DexFile::AnnotationSetItem* set_item = dex_file.GetSetRefItemItem(set_ref_item);
+ mirror::Object* annotation_set = ProcessAnnotationSet(klass, set_item,
+ DexFile::kDexVisibilityRuntime);
+ if (annotation_set == nullptr) {
+ return nullptr;
+ }
+ annotation_array_array->SetWithoutChecks<false>(index, annotation_set);
+ }
+ return annotation_array_array.Get();
+}
+} // namespace
+
+namespace annotations {
+
+mirror::Object* GetAnnotationForField(ArtField* field, Handle<mirror::Class> annotation_class) {
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForField(field);
+ if (annotation_set == nullptr) {
+ return nullptr;
+ }
+ StackHandleScope<1> hs(Thread::Current());
+ Handle<mirror::Class> field_class(hs.NewHandle(field->GetDeclaringClass()));
+ return GetAnnotationObjectFromAnnotationSet(field_class, annotation_set,
+ DexFile::kDexVisibilityRuntime, annotation_class);
+}
+
+mirror::ObjectArray<mirror::Object>* GetAnnotationsForField(ArtField* field) {
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForField(field);
+ StackHandleScope<1> hs(Thread::Current());
+ Handle<mirror::Class> field_class(hs.NewHandle(field->GetDeclaringClass()));
+ return ProcessAnnotationSet(field_class, annotation_set, DexFile::kDexVisibilityRuntime);
+}
+
+mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForField(ArtField* field) {
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForField(field);
+ if (annotation_set == nullptr) {
+ return nullptr;
+ }
+ StackHandleScope<1> hs(Thread::Current());
+ Handle<mirror::Class> field_class(hs.NewHandle(field->GetDeclaringClass()));
+ return GetSignatureValue(field_class, annotation_set);
+}
+
+bool IsFieldAnnotationPresent(ArtField* field, Handle<mirror::Class> annotation_class) {
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForField(field);
+ if (annotation_set == nullptr) {
+ return false;
+ }
+ StackHandleScope<1> hs(Thread::Current());
+ Handle<mirror::Class> field_class(hs.NewHandle(field->GetDeclaringClass()));
+ const DexFile::AnnotationItem* annotation_item = GetAnnotationItemFromAnnotationSet(
+ field_class, annotation_set, DexFile::kDexVisibilityRuntime, annotation_class);
+ return annotation_item != nullptr;
+}
+
+mirror::Object* GetAnnotationDefaultValue(ArtMethod* method) {
+ const DexFile* dex_file = method->GetDexFile();
+ mirror::Class* klass = method->GetDeclaringClass();
+ const DexFile::AnnotationsDirectoryItem* annotations_dir =
+ dex_file->GetAnnotationsDirectory(*klass->GetClassDef());
+ if (annotations_dir == nullptr) {
+ return nullptr;
+ }
+ const DexFile::AnnotationSetItem* annotation_set =
+ dex_file->GetClassAnnotationSet(annotations_dir);
+ if (annotation_set == nullptr) {
+ return nullptr;
+ }
+ const DexFile::AnnotationItem* annotation_item = SearchAnnotationSet(*dex_file, annotation_set,
+ "Ldalvik/annotation/AnnotationDefault;", DexFile::kDexVisibilitySystem);
+ if (annotation_item == nullptr) {
+ return nullptr;
+ }
+ const uint8_t* annotation =
+ SearchEncodedAnnotation(*dex_file, annotation_item->annotation_, "value");
+ if (annotation == nullptr) {
+ return nullptr;
+ }
+ uint8_t header_byte = *(annotation++);
+ if ((header_byte & DexFile::kDexAnnotationValueTypeMask) != DexFile::kDexAnnotationAnnotation) {
+ return nullptr;
+ }
+ annotation = SearchEncodedAnnotation(*dex_file, annotation, method->GetName());
+ if (annotation == nullptr) {
+ return nullptr;
+ }
+ DexFile::AnnotationValue annotation_value;
+ StackHandleScope<2> hs(Thread::Current());
+ Handle<mirror::Class> h_klass(hs.NewHandle(klass));
+ PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
+ Handle<mirror::Class> return_type(hs.NewHandle(
+ method->GetReturnType(true /* resolve */, pointer_size)));
+ if (!ProcessAnnotationValue(h_klass, &annotation, &annotation_value, return_type,
+ DexFile::kAllObjects)) {
+ return nullptr;
+ }
+ return annotation_value.value_.GetL();
+}
+
+mirror::Object* GetAnnotationForMethod(ArtMethod* method, Handle<mirror::Class> annotation_class) {
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForMethod(method);
+ if (annotation_set == nullptr) {
+ return nullptr;
+ }
+ StackHandleScope<1> hs(Thread::Current());
+ Handle<mirror::Class> method_class(hs.NewHandle(method->GetDeclaringClass()));
+ return GetAnnotationObjectFromAnnotationSet(method_class, annotation_set,
+ DexFile::kDexVisibilityRuntime, annotation_class);
+}
+
+mirror::ObjectArray<mirror::Object>* GetAnnotationsForMethod(ArtMethod* method) {
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForMethod(method);
+ StackHandleScope<1> hs(Thread::Current());
+ Handle<mirror::Class> method_class(hs.NewHandle(method->GetDeclaringClass()));
+ return ProcessAnnotationSet(method_class, annotation_set, DexFile::kDexVisibilityRuntime);
+}
+
+mirror::ObjectArray<mirror::Class>* GetExceptionTypesForMethod(ArtMethod* method) {
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForMethod(method);
+ if (annotation_set == nullptr) {
+ return nullptr;
+ }
+ StackHandleScope<1> hs(Thread::Current());
+ Handle<mirror::Class> method_class(hs.NewHandle(method->GetDeclaringClass()));
+ return GetThrowsValue(method_class, annotation_set);
+}
+
+mirror::ObjectArray<mirror::Object>* GetParameterAnnotations(ArtMethod* method) {
+ const DexFile* dex_file = method->GetDexFile();
+ const DexFile::ParameterAnnotationsItem* parameter_annotations =
+ FindAnnotationsItemForMethod(method);
+ if (parameter_annotations == nullptr) {
+ return nullptr;
+ }
+ const DexFile::AnnotationSetRefList* set_ref_list =
+ dex_file->GetParameterAnnotationSetRefList(parameter_annotations);
+ if (set_ref_list == nullptr) {
+ return nullptr;
+ }
+ uint32_t size = set_ref_list->size_;
+ StackHandleScope<1> hs(Thread::Current());
+ Handle<mirror::Class> method_class(hs.NewHandle(method->GetDeclaringClass()));
+ return ProcessAnnotationSetRefList(method_class, set_ref_list, size);
+}
+
+mirror::Object* GetAnnotationForMethodParameter(ArtMethod* method,
+ uint32_t parameter_idx,
+ Handle<mirror::Class> annotation_class) {
+ const DexFile* dex_file = method->GetDexFile();
+ const DexFile::ParameterAnnotationsItem* parameter_annotations =
+ FindAnnotationsItemForMethod(method);
+ if (parameter_annotations == nullptr) {
+ return nullptr;
+ }
+ const DexFile::AnnotationSetRefList* set_ref_list =
+ dex_file->GetParameterAnnotationSetRefList(parameter_annotations);
+ if (set_ref_list == nullptr) {
+ return nullptr;
+ }
+ if (parameter_idx >= set_ref_list->size_) {
+ return nullptr;
+ }
+ const DexFile::AnnotationSetRefItem* annotation_set_ref = &set_ref_list->list_[parameter_idx];
+ const DexFile::AnnotationSetItem* annotation_set =
+ dex_file->GetSetRefItemItem(annotation_set_ref);
+
+ StackHandleScope<1> hs(Thread::Current());
+ Handle<mirror::Class> method_class(hs.NewHandle(method->GetDeclaringClass()));
+ return GetAnnotationObjectFromAnnotationSet(method_class,
+ annotation_set,
+ DexFile::kDexVisibilityRuntime,
+ annotation_class);
+}
+
+mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForMethod(ArtMethod* method) {
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForMethod(method);
+ if (annotation_set == nullptr) {
+ return nullptr;
+ }
+ StackHandleScope<1> hs(Thread::Current());
+ Handle<mirror::Class> method_class(hs.NewHandle(method->GetDeclaringClass()));
+ return GetSignatureValue(method_class, annotation_set);
+}
+
+bool IsMethodAnnotationPresent(ArtMethod* method, Handle<mirror::Class> annotation_class,
+ uint32_t visibility /* = DexFile::kDexVisibilityRuntime */) {
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForMethod(method);
+ if (annotation_set == nullptr) {
+ return false;
+ }
+ StackHandleScope<1> hs(Thread::Current());
+ Handle<mirror::Class> method_class(hs.NewHandle(method->GetDeclaringClass()));
+ const DexFile::AnnotationItem* annotation_item =
+ GetAnnotationItemFromAnnotationSet(method_class, annotation_set, visibility,
+ annotation_class);
+ return annotation_item != nullptr;
+}
+
+mirror::Object* GetAnnotationForClass(Handle<mirror::Class> klass,
+ Handle<mirror::Class> annotation_class) {
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
+ if (annotation_set == nullptr) {
+ return nullptr;
+ }
+ return GetAnnotationObjectFromAnnotationSet(klass, annotation_set, DexFile::kDexVisibilityRuntime,
+ annotation_class);
+}
+
+mirror::ObjectArray<mirror::Object>* GetAnnotationsForClass(Handle<mirror::Class> klass) {
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
+ return ProcessAnnotationSet(klass, annotation_set, DexFile::kDexVisibilityRuntime);
+}
+
+mirror::ObjectArray<mirror::Class>* GetDeclaredClasses(Handle<mirror::Class> klass) {
+ const DexFile& dex_file = klass->GetDexFile();
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
+ if (annotation_set == nullptr) {
+ return nullptr;
+ }
+ const DexFile::AnnotationItem* annotation_item =
+ SearchAnnotationSet(dex_file, annotation_set, "Ldalvik/annotation/MemberClasses;",
+ DexFile::kDexVisibilitySystem);
+ if (annotation_item == nullptr) {
+ return nullptr;
+ }
+ StackHandleScope<1> hs(Thread::Current());
+ mirror::Class* class_class = mirror::Class::GetJavaLangClass();
+ Handle<mirror::Class> class_array_class(hs.NewHandle(
+ Runtime::Current()->GetClassLinker()->FindArrayClass(hs.Self(), &class_class)));
+ if (class_array_class.Get() == nullptr) {
+ return nullptr;
+ }
+ mirror::Object* obj =
+ GetAnnotationValue(klass, annotation_item, "value", class_array_class,
+ DexFile::kDexAnnotationArray);
+ if (obj == nullptr) {
+ return nullptr;
+ }
+ return obj->AsObjectArray<mirror::Class>();
+}
+
+mirror::Class* GetDeclaringClass(Handle<mirror::Class> klass) {
+ const DexFile& dex_file = klass->GetDexFile();
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
+ if (annotation_set == nullptr) {
+ return nullptr;
+ }
+ const DexFile::AnnotationItem* annotation_item =
+ SearchAnnotationSet(dex_file, annotation_set, "Ldalvik/annotation/EnclosingClass;",
+ DexFile::kDexVisibilitySystem);
+ if (annotation_item == nullptr) {
+ return nullptr;
+ }
+ mirror::Object* obj = GetAnnotationValue(klass, annotation_item, "value",
+ ScopedNullHandle<mirror::Class>(),
+ DexFile::kDexAnnotationType);
+ if (obj == nullptr) {
+ return nullptr;
+ }
+ return obj->AsClass();
+}
+
+mirror::Class* GetEnclosingClass(Handle<mirror::Class> klass) {
+ const DexFile& dex_file = klass->GetDexFile();
+ mirror::Class* declaring_class = GetDeclaringClass(klass);
+ if (declaring_class != nullptr) {
+ return declaring_class;
+ }
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
+ if (annotation_set == nullptr) {
+ return nullptr;
+ }
+ const DexFile::AnnotationItem* annotation_item =
+ SearchAnnotationSet(dex_file, annotation_set, "Ldalvik/annotation/EnclosingMethod;",
+ DexFile::kDexVisibilitySystem);
+ if (annotation_item == nullptr) {
+ return nullptr;
+ }
+ const uint8_t* annotation =
+ SearchEncodedAnnotation(dex_file, annotation_item->annotation_, "value");
+ if (annotation == nullptr) {
+ return nullptr;
+ }
+ DexFile::AnnotationValue annotation_value;
+ if (!ProcessAnnotationValue(klass, &annotation, &annotation_value,
+ ScopedNullHandle<mirror::Class>(), DexFile::kAllRaw)) {
+ return nullptr;
+ }
+ if (annotation_value.type_ != DexFile::kDexAnnotationMethod) {
+ return nullptr;
+ }
+ StackHandleScope<2> hs(Thread::Current());
+ Handle<mirror::DexCache> dex_cache(hs.NewHandle(klass->GetDexCache()));
+ Handle<mirror::ClassLoader> class_loader(hs.NewHandle(klass->GetClassLoader()));
+ ArtMethod* method = Runtime::Current()->GetClassLinker()->ResolveMethodWithoutInvokeType(
+ klass->GetDexFile(), annotation_value.value_.GetI(), dex_cache, class_loader);
+ if (method == nullptr) {
+ return nullptr;
+ }
+ return method->GetDeclaringClass();
+}
+
+mirror::Object* GetEnclosingMethod(Handle<mirror::Class> klass) {
+ const DexFile& dex_file = klass->GetDexFile();
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
+ if (annotation_set == nullptr) {
+ return nullptr;
+ }
+ const DexFile::AnnotationItem* annotation_item =
+ SearchAnnotationSet(dex_file, annotation_set, "Ldalvik/annotation/EnclosingMethod;",
+ DexFile::kDexVisibilitySystem);
+ if (annotation_item == nullptr) {
+ return nullptr;
+ }
+ return GetAnnotationValue(klass, annotation_item, "value", ScopedNullHandle<mirror::Class>(),
+ DexFile::kDexAnnotationMethod);
+}
+
+bool GetInnerClass(Handle<mirror::Class> klass, mirror::String** name) {
+ const DexFile& dex_file = klass->GetDexFile();
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
+ if (annotation_set == nullptr) {
+ return false;
+ }
+ const DexFile::AnnotationItem* annotation_item = SearchAnnotationSet(
+ dex_file, annotation_set, "Ldalvik/annotation/InnerClass;", DexFile::kDexVisibilitySystem);
+ if (annotation_item == nullptr) {
+ return false;
+ }
+ const uint8_t* annotation =
+ SearchEncodedAnnotation(dex_file, annotation_item->annotation_, "name");
+ if (annotation == nullptr) {
+ return false;
+ }
+ DexFile::AnnotationValue annotation_value;
+ if (!ProcessAnnotationValue(klass, &annotation, &annotation_value,
+ ScopedNullHandle<mirror::Class>(),
+ DexFile::kAllObjects)) {
+ return false;
+ }
+ if (annotation_value.type_ != DexFile::kDexAnnotationNull &&
+ annotation_value.type_ != DexFile::kDexAnnotationString) {
+ return false;
+ }
+ *name = down_cast<mirror::String*>(annotation_value.value_.GetL());
+ return true;
+}
+
+bool GetInnerClassFlags(Handle<mirror::Class> klass, uint32_t* flags) {
+ const DexFile& dex_file = klass->GetDexFile();
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
+ if (annotation_set == nullptr) {
+ return false;
+ }
+ const DexFile::AnnotationItem* annotation_item =
+ SearchAnnotationSet(dex_file, annotation_set, "Ldalvik/annotation/InnerClass;",
+ DexFile::kDexVisibilitySystem);
+ if (annotation_item == nullptr) {
+ return false;
+ }
+ const uint8_t* annotation =
+ SearchEncodedAnnotation(dex_file, annotation_item->annotation_, "accessFlags");
+ if (annotation == nullptr) {
+ return false;
+ }
+ DexFile::AnnotationValue annotation_value;
+ if (!ProcessAnnotationValue(klass, &annotation, &annotation_value,
+ ScopedNullHandle<mirror::Class>(), DexFile::kAllRaw)) {
+ return false;
+ }
+ if (annotation_value.type_ != DexFile::kDexAnnotationInt) {
+ return false;
+ }
+ *flags = annotation_value.value_.GetI();
+ return true;
+}
+
+mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForClass(Handle<mirror::Class> klass) {
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
+ if (annotation_set == nullptr) {
+ return nullptr;
+ }
+ return GetSignatureValue(klass, annotation_set);
+}
+
+bool IsClassAnnotationPresent(Handle<mirror::Class> klass, Handle<mirror::Class> annotation_class) {
+ const DexFile::AnnotationSetItem* annotation_set = FindAnnotationSetForClass(klass);
+ if (annotation_set == nullptr) {
+ return false;
+ }
+ const DexFile::AnnotationItem* annotation_item = GetAnnotationItemFromAnnotationSet(
+ klass, annotation_set, DexFile::kDexVisibilityRuntime, annotation_class);
+ return annotation_item != nullptr;
+}
+
+int32_t GetLineNumFromPC(const DexFile* dex_file, ArtMethod* method, uint32_t rel_pc) {
+ // For native method, lineno should be -2 to indicate it is native. Note that
+ // "line number == -2" is how libcore tells from StackTraceElement.
+ if (method->GetCodeItemOffset() == 0) {
+ return -2;
+ }
+
+ const DexFile::CodeItem* code_item = dex_file->GetCodeItem(method->GetCodeItemOffset());
+ DCHECK(code_item != nullptr) << PrettyMethod(method) << " " << dex_file->GetLocation();
+
+ // A method with no line number info should return -1
+ DexFile::LineNumFromPcContext context(rel_pc, -1);
+ dex_file->DecodeDebugPositionInfo(code_item, DexFile::LineNumForPcCb, &context);
+ return context.line_num_;
+}
+
+template<bool kTransactionActive>
+void RuntimeEncodedStaticFieldValueIterator::ReadValueToField(ArtField* field) const {
+ DCHECK(dex_cache_ != nullptr);
+ DCHECK(class_loader_ != nullptr);
+ switch (type_) {
+ case kBoolean: field->SetBoolean<kTransactionActive>(field->GetDeclaringClass(), jval_.z);
+ break;
+ case kByte: field->SetByte<kTransactionActive>(field->GetDeclaringClass(), jval_.b); break;
+ case kShort: field->SetShort<kTransactionActive>(field->GetDeclaringClass(), jval_.s); break;
+ case kChar: field->SetChar<kTransactionActive>(field->GetDeclaringClass(), jval_.c); break;
+ case kInt: field->SetInt<kTransactionActive>(field->GetDeclaringClass(), jval_.i); break;
+ case kLong: field->SetLong<kTransactionActive>(field->GetDeclaringClass(), jval_.j); break;
+ case kFloat: field->SetFloat<kTransactionActive>(field->GetDeclaringClass(), jval_.f); break;
+ case kDouble: field->SetDouble<kTransactionActive>(field->GetDeclaringClass(), jval_.d); break;
+ case kNull: field->SetObject<kTransactionActive>(field->GetDeclaringClass(), nullptr); break;
+ case kString: {
+ mirror::String* resolved = linker_->ResolveString(dex_file_, jval_.i, *dex_cache_);
+ field->SetObject<kTransactionActive>(field->GetDeclaringClass(), resolved);
+ break;
+ }
+ case kType: {
+ mirror::Class* resolved = linker_->ResolveType(dex_file_, jval_.i, *dex_cache_,
+ *class_loader_);
+ field->SetObject<kTransactionActive>(field->GetDeclaringClass(), resolved);
+ break;
+ }
+ default: UNIMPLEMENTED(FATAL) << ": type " << type_;
+ }
+}
+template
+void RuntimeEncodedStaticFieldValueIterator::ReadValueToField<true>(ArtField* field) const;
+template
+void RuntimeEncodedStaticFieldValueIterator::ReadValueToField<false>(ArtField* field) const;
+
+} // namespace annotations
+
+} // namespace art
diff --git a/runtime/dex_file_annotations.h b/runtime/dex_file_annotations.h
new file mode 100644
index 0000000..7b4e856
--- /dev/null
+++ b/runtime/dex_file_annotations.h
@@ -0,0 +1,125 @@
+/*
+ * 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_DEX_FILE_ANNOTATIONS_H_
+#define ART_RUNTIME_DEX_FILE_ANNOTATIONS_H_
+
+#include "dex_file.h"
+
+#include "mirror/object_array.h"
+
+namespace art {
+
+namespace mirror {
+ class ClassLoader;
+ class DexCache;
+} // namespace mirror
+class ArtField;
+class ArtMethod;
+class ClassLinker;
+
+namespace annotations {
+
+// Field annotations.
+mirror::Object* GetAnnotationForField(ArtField* field, Handle<mirror::Class> annotation_class)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+mirror::ObjectArray<mirror::Object>* GetAnnotationsForField(ArtField* field)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForField(ArtField* field)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+bool IsFieldAnnotationPresent(ArtField* field, Handle<mirror::Class> annotation_class)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+
+// Method annotations.
+mirror::Object* GetAnnotationDefaultValue(ArtMethod* method)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+mirror::Object* GetAnnotationForMethod(ArtMethod* method, Handle<mirror::Class> annotation_class)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+mirror::ObjectArray<mirror::Object>* GetAnnotationsForMethod(ArtMethod* method)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+mirror::ObjectArray<mirror::Class>* GetExceptionTypesForMethod(ArtMethod* method)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+mirror::ObjectArray<mirror::Object>* GetParameterAnnotations(ArtMethod* method)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+mirror::Object* GetAnnotationForMethodParameter(ArtMethod* method,
+ uint32_t parameter_idx,
+ Handle<mirror::Class> annotation_class)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForMethod(ArtMethod* method)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+bool IsMethodAnnotationPresent(ArtMethod* method, Handle<mirror::Class> annotation_class,
+ uint32_t visibility = DexFile::kDexVisibilityRuntime)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+
+// Class annotations.
+mirror::Object* GetAnnotationForClass(Handle<mirror::Class> klass,
+ Handle<mirror::Class> annotation_class)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+mirror::ObjectArray<mirror::Object>* GetAnnotationsForClass(Handle<mirror::Class> klass)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+mirror::ObjectArray<mirror::Class>* GetDeclaredClasses(Handle<mirror::Class> klass)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+mirror::Class* GetDeclaringClass(Handle<mirror::Class> klass)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+mirror::Class* GetEnclosingClass(Handle<mirror::Class> klass)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+mirror::Object* GetEnclosingMethod(Handle<mirror::Class> klass)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+bool GetInnerClass(Handle<mirror::Class> klass, mirror::String** name)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+bool GetInnerClassFlags(Handle<mirror::Class> klass, uint32_t* flags)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+mirror::ObjectArray<mirror::String>* GetSignatureAnnotationForClass(Handle<mirror::Class> klass)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+bool IsClassAnnotationPresent(Handle<mirror::Class> klass,
+ Handle<mirror::Class> annotation_class)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+
+// Map back from a PC to the line number in a method.
+int32_t GetLineNumFromPC(const DexFile* dex_file, ArtMethod* method, uint32_t rel_pc)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+
+// Annotations iterator.
+class RuntimeEncodedStaticFieldValueIterator : public EncodedStaticFieldValueIterator {
+ public:
+ // A constructor meant to be called from runtime code.
+ RuntimeEncodedStaticFieldValueIterator(const DexFile& dex_file,
+ Handle<mirror::DexCache>* dex_cache,
+ Handle<mirror::ClassLoader>* class_loader,
+ ClassLinker* linker,
+ const DexFile::ClassDef& class_def)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ : EncodedStaticFieldValueIterator(dex_file, class_def),
+ dex_cache_(dex_cache),
+ class_loader_(class_loader),
+ linker_(linker) {
+ }
+
+ template<bool kTransactionActive>
+ void ReadValueToField(ArtField* field) const REQUIRES_SHARED(Locks::mutator_lock_);
+
+ private:
+ Handle<mirror::DexCache>* const dex_cache_; // Dex cache to resolve literal objects.
+ Handle<mirror::ClassLoader>* const class_loader_; // ClassLoader to resolve types.
+ ClassLinker* linker_; // Linker to resolve literal objects.
+ DISALLOW_IMPLICIT_CONSTRUCTORS(RuntimeEncodedStaticFieldValueIterator);
+};
+
+} // namespace annotations
+
+} // namespace art
+
+#endif // ART_RUNTIME_DEX_FILE_ANNOTATIONS_H_
diff --git a/runtime/entrypoints/entrypoint_utils-inl.h b/runtime/entrypoints/entrypoint_utils-inl.h
index d03a9d8..1bf5c53 100644
--- a/runtime/entrypoints/entrypoint_utils-inl.h
+++ b/runtime/entrypoints/entrypoint_utils-inl.h
@@ -48,7 +48,7 @@
// This method is being used by artQuickResolutionTrampoline, before it sets up
// the passed parameters in a GC friendly way. Therefore we must never be
// suspended while executing it.
- ScopedAssertNoThreadSuspension sants(Thread::Current(), __FUNCTION__);
+ ScopedAssertNoThreadSuspension sants(__FUNCTION__);
uint32_t method_index = inline_info.GetMethodIndexAtDepth(encoding, inlining_depth);
InvokeType invoke_type = static_cast<InvokeType>(
diff --git a/runtime/entrypoints/quick/quick_default_externs.h b/runtime/entrypoints/quick/quick_default_externs.h
index 86fb881..cfa5325 100644
--- a/runtime/entrypoints/quick/quick_default_externs.h
+++ b/runtime/entrypoints/quick/quick_default_externs.h
@@ -118,7 +118,6 @@
extern "C" void art_quick_deliver_exception(art::mirror::Object*);
extern "C" void art_quick_throw_array_bounds(int32_t index, int32_t limit);
extern "C" void art_quick_throw_div_zero();
-extern "C" void art_quick_throw_no_such_method(int32_t method_idx);
extern "C" void art_quick_throw_null_pointer_exception();
extern "C" void art_quick_throw_null_pointer_exception_from_signal(uintptr_t address);
extern "C" void art_quick_throw_stack_overflow(void*);
diff --git a/runtime/entrypoints/quick/quick_default_init_entrypoints.h b/runtime/entrypoints/quick/quick_default_init_entrypoints.h
index 2a206c2..1ee1f81 100644
--- a/runtime/entrypoints/quick/quick_default_init_entrypoints.h
+++ b/runtime/entrypoints/quick/quick_default_init_entrypoints.h
@@ -113,7 +113,6 @@
qpoints->pDeliverException = art_quick_deliver_exception;
qpoints->pThrowArrayBounds = art_quick_throw_array_bounds;
qpoints->pThrowDivZero = art_quick_throw_div_zero;
- qpoints->pThrowNoSuchMethod = art_quick_throw_no_such_method;
qpoints->pThrowNullPointer = art_quick_throw_null_pointer_exception;
qpoints->pThrowStackOverflow = art_quick_throw_stack_overflow;
qpoints->pThrowStringBounds = art_quick_throw_string_bounds;
diff --git a/runtime/entrypoints/quick/quick_entrypoints_list.h b/runtime/entrypoints/quick/quick_entrypoints_list.h
index 74c928a..e402919 100644
--- a/runtime/entrypoints/quick/quick_entrypoints_list.h
+++ b/runtime/entrypoints/quick/quick_entrypoints_list.h
@@ -139,7 +139,6 @@
V(DeliverException, void, mirror::Object*) \
V(ThrowArrayBounds, void, int32_t, int32_t) \
V(ThrowDivZero, void, void) \
- V(ThrowNoSuchMethod, void, int32_t) \
V(ThrowNullPointer, void, void) \
V(ThrowStackOverflow, void, void*) \
V(ThrowStringBounds, void, int32_t, int32_t) \
diff --git a/runtime/entrypoints/quick/quick_throw_entrypoints.cc b/runtime/entrypoints/quick/quick_throw_entrypoints.cc
index 67cae8a..a205b17 100644
--- a/runtime/entrypoints/quick/quick_throw_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_throw_entrypoints.cc
@@ -101,13 +101,6 @@
self->QuickDeliverException();
}
-extern "C" NO_RETURN void artThrowNoSuchMethodFromCode(int32_t method_idx, Thread* self)
- REQUIRES_SHARED(Locks::mutator_lock_) {
- ScopedQuickEntrypointChecks sqec(self);
- ThrowNoSuchMethodError(method_idx);
- self->QuickDeliverException();
-}
-
extern "C" NO_RETURN void artThrowClassCastException(mirror::Class* dest_type,
mirror::Class* src_type,
Thread* self)
diff --git a/runtime/entrypoints_order_test.cc b/runtime/entrypoints_order_test.cc
index b102334..03254ab 100644
--- a/runtime/entrypoints_order_test.cc
+++ b/runtime/entrypoints_order_test.cc
@@ -122,10 +122,10 @@
// Skip across the entrypoints structures.
- EXPECT_OFFSET_DIFFP(Thread, tlsPtr_, thread_local_start, thread_local_objects, sizeof(void*));
- EXPECT_OFFSET_DIFFP(Thread, tlsPtr_, thread_local_objects, thread_local_pos, sizeof(size_t));
+ EXPECT_OFFSET_DIFFP(Thread, tlsPtr_, thread_local_start, thread_local_pos, sizeof(void*));
EXPECT_OFFSET_DIFFP(Thread, tlsPtr_, thread_local_pos, thread_local_end, sizeof(void*));
- EXPECT_OFFSET_DIFFP(Thread, tlsPtr_, thread_local_end, mterp_current_ibase, sizeof(void*));
+ EXPECT_OFFSET_DIFFP(Thread, tlsPtr_, thread_local_end, thread_local_objects, sizeof(void*));
+ EXPECT_OFFSET_DIFFP(Thread, tlsPtr_, thread_local_objects, mterp_current_ibase, sizeof(size_t));
EXPECT_OFFSET_DIFFP(Thread, tlsPtr_, mterp_current_ibase, mterp_default_ibase, sizeof(void*));
EXPECT_OFFSET_DIFFP(Thread, tlsPtr_, mterp_default_ibase, mterp_alt_ibase, sizeof(void*));
EXPECT_OFFSET_DIFFP(Thread, tlsPtr_, mterp_alt_ibase, rosalloc_runs, sizeof(void*));
@@ -288,8 +288,7 @@
EXPECT_OFFSET_DIFFNP(QuickEntryPoints, pDeliverException, pThrowArrayBounds, sizeof(void*));
EXPECT_OFFSET_DIFFNP(QuickEntryPoints, pThrowArrayBounds, pThrowDivZero, sizeof(void*));
- EXPECT_OFFSET_DIFFNP(QuickEntryPoints, pThrowDivZero, pThrowNoSuchMethod, sizeof(void*));
- EXPECT_OFFSET_DIFFNP(QuickEntryPoints, pThrowNoSuchMethod, pThrowNullPointer, sizeof(void*));
+ EXPECT_OFFSET_DIFFNP(QuickEntryPoints, pThrowDivZero, pThrowNullPointer, sizeof(void*));
EXPECT_OFFSET_DIFFNP(QuickEntryPoints, pThrowNullPointer, pThrowStackOverflow, sizeof(void*));
EXPECT_OFFSET_DIFFNP(QuickEntryPoints, pThrowStackOverflow, pThrowStringBounds, sizeof(void*));
EXPECT_OFFSET_DIFFNP(QuickEntryPoints, pThrowStringBounds, pDeoptimize, sizeof(void*));
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 600aff1..cb5226b 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -1011,7 +1011,7 @@
DecrementDisableMovingGC(self);
} else {
// GCs can move objects, so don't allow this.
- ScopedAssertNoThreadSuspension ants(self, "Visiting objects");
+ ScopedAssertNoThreadSuspension ants("Visiting objects");
DCHECK(region_space_ == nullptr);
VisitObjectsInternal(callback, arg);
}
diff --git a/runtime/instrumentation.cc b/runtime/instrumentation.cc
index 388561b..ff43389 100644
--- a/runtime/instrumentation.cc
+++ b/runtime/instrumentation.cc
@@ -966,7 +966,7 @@
ArtMethod* callee) const {
// We cannot have thread suspension since that would cause the this_object parameter to
// potentially become a dangling pointer. An alternative could be to put it in a handle instead.
- ScopedAssertNoThreadSuspension ants(thread, __FUNCTION__);
+ ScopedAssertNoThreadSuspension ants(__FUNCTION__);
for (InstrumentationListener* listener : invoke_virtual_or_interface_listeners_) {
if (listener != nullptr) {
listener->InvokeVirtualOrInterface(thread, this_object, caller, dex_pc, callee);
diff --git a/runtime/interpreter/interpreter_common.h b/runtime/interpreter/interpreter_common.h
index 9d76685..814adf7 100644
--- a/runtime/interpreter/interpreter_common.h
+++ b/runtime/interpreter/interpreter_common.h
@@ -147,8 +147,7 @@
jit::Jit* jit = Runtime::Current()->GetJit();
if (jit != nullptr) {
if (type == kVirtual || type == kInterface) {
- jit->InvokeVirtualOrInterface(
- self, receiver, sf_method, shadow_frame.GetDexPC(), called_method);
+ jit->InvokeVirtualOrInterface(receiver, sf_method, shadow_frame.GetDexPC(), called_method);
}
jit->AddSamples(self, sf_method, 1, /*with_backedges*/false);
}
@@ -195,7 +194,7 @@
jit::Jit* jit = Runtime::Current()->GetJit();
if (jit != nullptr) {
jit->InvokeVirtualOrInterface(
- self, receiver, shadow_frame.GetMethod(), shadow_frame.GetDexPC(), called_method);
+ receiver, shadow_frame.GetMethod(), shadow_frame.GetDexPC(), called_method);
jit->AddSamples(self, shadow_frame.GetMethod(), 1, /*with_backedges*/false);
}
instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
diff --git a/runtime/interpreter/unstarted_runtime.cc b/runtime/interpreter/unstarted_runtime.cc
index c614408..d505aea 100644
--- a/runtime/interpreter/unstarted_runtime.cc
+++ b/runtime/interpreter/unstarted_runtime.cc
@@ -402,7 +402,7 @@
if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) {
result->SetL(nullptr);
}
- result->SetL(klass->GetDexFile().GetEnclosingClass(klass));
+ result->SetL(annotations::GetEnclosingClass(klass));
}
void UnstartedRuntime::UnstartedClassGetInnerClassFlags(
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index cff2354..d984f45 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -431,7 +431,7 @@
const uint8_t* native_pc = nullptr;
{
- ScopedAssertNoThreadSuspension sts(thread, "Holding OSR method");
+ ScopedAssertNoThreadSuspension sts("Holding OSR method");
const OatQuickMethodHeader* osr_method = jit->GetCodeCache()->LookupOsrMethodHeader(method);
if (osr_method == nullptr) {
// No osr method yet, just return to the interpreter.
@@ -683,12 +683,11 @@
}
}
-void Jit::InvokeVirtualOrInterface(Thread* thread,
- mirror::Object* this_object,
+void Jit::InvokeVirtualOrInterface(mirror::Object* this_object,
ArtMethod* caller,
uint32_t dex_pc,
ArtMethod* callee ATTRIBUTE_UNUSED) {
- ScopedAssertNoThreadSuspension ants(thread, __FUNCTION__);
+ ScopedAssertNoThreadSuspension ants(__FUNCTION__);
DCHECK(this_object != nullptr);
ProfilingInfo* info = caller->GetProfilingInfo(kRuntimePointerSize);
if (info != nullptr) {
diff --git a/runtime/jit/jit.h b/runtime/jit/jit.h
index 417a185..35656cd 100644
--- a/runtime/jit/jit.h
+++ b/runtime/jit/jit.h
@@ -30,6 +30,7 @@
namespace art {
class ArtMethod;
+class ClassLinker;
struct RuntimeArgumentMap;
union JValue;
@@ -108,8 +109,7 @@
void AddSamples(Thread* self, ArtMethod* method, uint16_t samples, bool with_backedges)
REQUIRES_SHARED(Locks::mutator_lock_);
- void InvokeVirtualOrInterface(Thread* thread,
- mirror::Object* this_object,
+ void InvokeVirtualOrInterface(mirror::Object* this_object,
ArtMethod* caller,
uint32_t dex_pc,
ArtMethod* callee)
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc
index c979c28..f21baed 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -23,6 +23,7 @@
#include "class-inl.h"
#include "dex_cache.h"
#include "dex_file-inl.h"
+#include "dex_file_annotations.h"
#include "gc/accounting/card_table-inl.h"
#include "handle_scope-inl.h"
#include "method.h"
@@ -784,7 +785,7 @@
}
// Though GetDirectInterface() should not cause thread suspension when called
// from here, it takes a Handle as an argument, so we need to wrap `k`.
- ScopedAssertNoThreadSuspension ants(self, __FUNCTION__);
+ ScopedAssertNoThreadSuspension ants(__FUNCTION__);
StackHandleScope<1> hs(self);
Handle<mirror::Class> h_k(hs.NewHandle(k));
// Is this field in any of this class' interfaces?
@@ -1214,7 +1215,7 @@
return default_value;
}
uint32_t flags;
- if (!h_this->GetDexFile().GetInnerClassFlags(h_this, &flags)) {
+ if (!annotations::GetInnerClassFlags(h_this, &flags)) {
return default_value;
}
return flags;
diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc
index d89a334..af9b68f 100644
--- a/runtime/native/java_lang_Class.cc
+++ b/runtime/native/java_lang_Class.cc
@@ -23,6 +23,7 @@
#include "class_linker.h"
#include "common_throws.h"
#include "dex_file-inl.h"
+#include "dex_file_annotations.h"
#include "jni_internal.h"
#include "nth_caller_visitor.h"
#include "mirror/class-inl.h"
@@ -454,7 +455,7 @@
}
Handle<mirror::Class> annotation_class(hs.NewHandle(soa.Decode<mirror::Class*>(annotationClass)));
return soa.AddLocalReference<jobject>(
- klass->GetDexFile().GetAnnotationForClass(klass, annotation_class));
+ annotations::GetAnnotationForClass(klass, annotation_class));
}
static jobjectArray Class_getDeclaredAnnotations(JNIEnv* env, jobject javaThis) {
@@ -469,7 +470,7 @@
mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), annotation_array_class, 0);
return soa.AddLocalReference<jobjectArray>(empty_array);
}
- return soa.AddLocalReference<jobjectArray>(klass->GetDexFile().GetAnnotationsForClass(klass));
+ return soa.AddLocalReference<jobjectArray>(annotations::GetAnnotationsForClass(klass));
}
static jobjectArray Class_getDeclaredClasses(JNIEnv* env, jobject javaThis) {
@@ -478,7 +479,7 @@
Handle<mirror::Class> klass(hs.NewHandle(DecodeClass(soa, javaThis)));
mirror::ObjectArray<mirror::Class>* classes = nullptr;
if (!klass->IsProxyClass() && klass->GetDexCache() != nullptr) {
- classes = klass->GetDexFile().GetDeclaredClasses(klass);
+ classes = annotations::GetDeclaredClasses(klass);
}
if (classes == nullptr) {
// Return an empty array instead of a null pointer.
@@ -506,7 +507,7 @@
if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) {
return nullptr;
}
- return soa.AddLocalReference<jclass>(klass->GetDexFile().GetEnclosingClass(klass));
+ return soa.AddLocalReference<jclass>(annotations::GetEnclosingClass(klass));
}
static jobject Class_getEnclosingConstructorNative(JNIEnv* env, jobject javaThis) {
@@ -516,7 +517,7 @@
if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) {
return nullptr;
}
- mirror::Object* method = klass->GetDexFile().GetEnclosingMethod(klass);
+ mirror::Object* method = annotations::GetEnclosingMethod(klass);
if (method != nullptr) {
if (method->GetClass() ==
soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_reflect_Constructor)) {
@@ -533,7 +534,7 @@
if (klass->IsProxyClass() || klass->GetDexCache() == nullptr) {
return nullptr;
}
- mirror::Object* method = klass->GetDexFile().GetEnclosingMethod(klass);
+ mirror::Object* method = annotations::GetEnclosingMethod(klass);
if (method != nullptr) {
if (method->GetClass() ==
soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_reflect_Method)) {
@@ -558,7 +559,7 @@
return nullptr;
}
mirror::String* class_name = nullptr;
- if (!klass->GetDexFile().GetInnerClass(klass, &class_name)) {
+ if (!annotations::GetInnerClass(klass, &class_name)) {
return nullptr;
}
return soa.AddLocalReference<jstring>(class_name);
@@ -572,7 +573,7 @@
return nullptr;
}
return soa.AddLocalReference<jobjectArray>(
- klass->GetDexFile().GetSignatureAnnotationForClass(klass));
+ annotations::GetSignatureAnnotationForClass(klass));
}
static jboolean Class_isAnonymousClass(JNIEnv* env, jobject javaThis) {
@@ -583,7 +584,7 @@
return false;
}
mirror::String* class_name = nullptr;
- if (!klass->GetDexFile().GetInnerClass(klass, &class_name)) {
+ if (!annotations::GetInnerClass(klass, &class_name)) {
return false;
}
return class_name == nullptr;
@@ -598,7 +599,7 @@
return false;
}
Handle<mirror::Class> annotation_class(hs.NewHandle(soa.Decode<mirror::Class*>(annotationType)));
- return klass->GetDexFile().IsClassAnnotationPresent(klass, annotation_class);
+ return annotations::IsClassAnnotationPresent(klass, annotation_class);
}
static jclass Class_getDeclaringClass(JNIEnv* env, jobject javaThis) {
@@ -612,7 +613,7 @@
if (Class_isAnonymousClass(env, javaThis)) {
return nullptr;
}
- return soa.AddLocalReference<jclass>(klass->GetDexFile().GetDeclaringClass(klass));
+ return soa.AddLocalReference<jclass>(annotations::GetDeclaringClass(klass));
}
static jobject Class_newInstance(JNIEnv* env, jobject javaThis) {
@@ -668,8 +669,7 @@
caller.Assign(GetCallingClass(soa.Self(), 1));
}
if (UNLIKELY(caller.Get() != nullptr && !VerifyAccess(
- soa.Self(), receiver.Get(), declaring_class, constructor->GetAccessFlags(),
- caller.Get()))) {
+ receiver.Get(), declaring_class, constructor->GetAccessFlags(), caller.Get()))) {
soa.Self()->ThrowNewExceptionF(
"Ljava/lang/IllegalAccessException;", "%s is not accessible from %s",
PrettyMethod(constructor).c_str(), PrettyClass(caller.Get()).c_str());
diff --git a/runtime/native/java_lang_reflect_AbstractMethod.cc b/runtime/native/java_lang_reflect_AbstractMethod.cc
index 33e0dae..254f8db 100644
--- a/runtime/native/java_lang_reflect_AbstractMethod.cc
+++ b/runtime/native/java_lang_reflect_AbstractMethod.cc
@@ -17,6 +17,7 @@
#include "java_lang_reflect_AbstractMethod.h"
#include "art_method-inl.h"
+#include "dex_file_annotations.h"
#include "jni_internal.h"
#include "mirror/class-inl.h"
#include "mirror/object-inl.h"
@@ -38,7 +39,7 @@
mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), annotation_array_class, 0);
return soa.AddLocalReference<jobjectArray>(empty_array);
}
- return soa.AddLocalReference<jobjectArray>(method->GetDexFile()->GetAnnotationsForMethod(method));
+ return soa.AddLocalReference<jobjectArray>(annotations::GetAnnotationsForMethod(method));
}
static jobject AbstractMethod_getAnnotationNative(JNIEnv* env,
@@ -51,8 +52,7 @@
return nullptr;
} else {
Handle<mirror::Class> klass(hs.NewHandle(soa.Decode<mirror::Class*>(annotationType)));
- return soa.AddLocalReference<jobject>(
- method->GetDexFile()->GetAnnotationForMethod(method, klass));
+ return soa.AddLocalReference<jobject>(annotations::GetAnnotationForMethod(method, klass));
}
}
@@ -63,8 +63,7 @@
return nullptr;
}
StackHandleScope<1> hs(soa.Self());
- return soa.AddLocalReference<jobjectArray>(
- method->GetDexFile()->GetSignatureAnnotationForMethod(method));
+ return soa.AddLocalReference<jobjectArray>(annotations::GetSignatureAnnotationForMethod(method));
}
@@ -74,8 +73,7 @@
if (method->IsProxyMethod()) {
return nullptr;
} else {
- return soa.AddLocalReference<jobjectArray>(
- method->GetDexFile()->GetParameterAnnotations(method));
+ return soa.AddLocalReference<jobjectArray>(annotations::GetParameterAnnotations(method));
}
}
@@ -89,7 +87,7 @@
}
StackHandleScope<1> hs(soa.Self());
Handle<mirror::Class> klass(hs.NewHandle(soa.Decode<mirror::Class*>(annotationType)));
- return method->GetDexFile()->IsMethodAnnotationPresent(method, klass);
+ return annotations::IsMethodAnnotationPresent(method, klass);
}
static JNINativeMethod gMethods[] = {
diff --git a/runtime/native/java_lang_reflect_Constructor.cc b/runtime/native/java_lang_reflect_Constructor.cc
index f699d6b..d001d0c 100644
--- a/runtime/native/java_lang_reflect_Constructor.cc
+++ b/runtime/native/java_lang_reflect_Constructor.cc
@@ -20,6 +20,7 @@
#include "base/enums.h"
#include "class_linker.h"
#include "class_linker-inl.h"
+#include "dex_file_annotations.h"
#include "jni_internal.h"
#include "mirror/class-inl.h"
#include "mirror/method.h"
@@ -35,7 +36,7 @@
ArtMethod* method = ArtMethod::FromReflectedMethod(soa, javaMethod)
->GetInterfaceMethodIfProxy(kRuntimePointerSize);
mirror::ObjectArray<mirror::Class>* result_array =
- method->GetDexFile()->GetExceptionTypesForMethod(method);
+ annotations::GetExceptionTypesForMethod(method);
if (result_array == nullptr) {
// Return an empty array instead of a null pointer.
mirror::Class* class_class = mirror::Class::GetJavaLangClass();
diff --git a/runtime/native/java_lang_reflect_Field.cc b/runtime/native/java_lang_reflect_Field.cc
index 5a4ced2..412445f 100644
--- a/runtime/native/java_lang_reflect_Field.cc
+++ b/runtime/native/java_lang_reflect_Field.cc
@@ -20,6 +20,7 @@
#include "class_linker-inl.h"
#include "common_throws.h"
#include "dex_file-inl.h"
+#include "dex_file_annotations.h"
#include "jni_internal.h"
#include "mirror/class-inl.h"
#include "mirror/field.h"
@@ -423,7 +424,7 @@
return nullptr;
}
Handle<mirror::Class> klass(hs.NewHandle(soa.Decode<mirror::Class*>(annotationType)));
- return soa.AddLocalReference<jobject>(field->GetDexFile()->GetAnnotationForField(field, klass));
+ return soa.AddLocalReference<jobject>(annotations::GetAnnotationForField(field, klass));
}
static jobjectArray Field_getDeclaredAnnotations(JNIEnv* env, jobject javaField) {
@@ -437,7 +438,7 @@
mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), annotation_array_class, 0);
return soa.AddLocalReference<jobjectArray>(empty_array);
}
- return soa.AddLocalReference<jobjectArray>(field->GetDexFile()->GetAnnotationsForField(field));
+ return soa.AddLocalReference<jobjectArray>(annotations::GetAnnotationsForField(field));
}
static jobjectArray Field_getSignatureAnnotation(JNIEnv* env, jobject javaField) {
@@ -446,8 +447,7 @@
if (field->GetDeclaringClass()->IsProxyClass()) {
return nullptr;
}
- return soa.AddLocalReference<jobjectArray>(
- field->GetDexFile()->GetSignatureAnnotationForField(field));
+ return soa.AddLocalReference<jobjectArray>(annotations::GetSignatureAnnotationForField(field));
}
static jboolean Field_isAnnotationPresentNative(JNIEnv* env, jobject javaField,
@@ -459,7 +459,7 @@
return false;
}
Handle<mirror::Class> klass(hs.NewHandle(soa.Decode<mirror::Class*>(annotationType)));
- return field->GetDexFile()->IsFieldAnnotationPresent(field, klass);
+ return annotations::IsFieldAnnotationPresent(field, klass);
}
static JNINativeMethod gMethods[] = {
diff --git a/runtime/native/java_lang_reflect_Method.cc b/runtime/native/java_lang_reflect_Method.cc
index 3360f41..b8efb14 100644
--- a/runtime/native/java_lang_reflect_Method.cc
+++ b/runtime/native/java_lang_reflect_Method.cc
@@ -20,6 +20,7 @@
#include "base/enums.h"
#include "class_linker.h"
#include "class_linker-inl.h"
+#include "dex_file_annotations.h"
#include "jni_internal.h"
#include "mirror/class-inl.h"
#include "mirror/object-inl.h"
@@ -36,7 +37,7 @@
if (!method->GetDeclaringClass()->IsAnnotation()) {
return nullptr;
}
- return soa.AddLocalReference<jobject>(method->GetDexFile()->GetAnnotationDefaultValue(method));
+ return soa.AddLocalReference<jobject>(annotations::GetAnnotationDefaultValue(method));
}
static jobjectArray Method_getExceptionTypes(JNIEnv* env, jobject javaMethod) {
@@ -58,7 +59,7 @@
return soa.AddLocalReference<jobjectArray>(declared_exceptions->Clone(soa.Self()));
} else {
mirror::ObjectArray<mirror::Class>* result_array =
- method->GetDexFile()->GetExceptionTypesForMethod(method);
+ annotations::GetExceptionTypesForMethod(method);
if (result_array == nullptr) {
// Return an empty array instead of a null pointer
mirror::Class* class_class = mirror::Class::GetJavaLangClass();
diff --git a/runtime/native/java_lang_reflect_Parameter.cc b/runtime/native/java_lang_reflect_Parameter.cc
index 8fe3bb5..c2a803c 100644
--- a/runtime/native/java_lang_reflect_Parameter.cc
+++ b/runtime/native/java_lang_reflect_Parameter.cc
@@ -19,6 +19,7 @@
#include "art_method-inl.h"
#include "common_throws.h"
#include "dex_file-inl.h"
+#include "dex_file_annotations.h"
#include "jni_internal.h"
#include "scoped_fast_native_object_access.h"
#include "utils.h"
@@ -54,7 +55,7 @@
StackHandleScope<1> hs(soa.Self());
Handle<mirror::Class> klass(hs.NewHandle(soa.Decode<mirror::Class*>(annotationType)));
return soa.AddLocalReference<jobject>(
- method->GetDexFile()->GetAnnotationForMethodParameter(method, parameterIndex, klass));
+ annotations::GetAnnotationForMethodParameter(method, parameterIndex, klass));
}
static JNINativeMethod gMethods[] = {
diff --git a/runtime/quick/inline_method_analyser.h b/runtime/quick/inline_method_analyser.h
index 356e290..2df2ced 100644
--- a/runtime/quick/inline_method_analyser.h
+++ b/runtime/quick/inline_method_analyser.h
@@ -33,6 +33,7 @@
namespace verifier {
class MethodVerifier;
} // namespace verifier
+class ArtMethod;
enum InlineMethodOpcode : uint16_t {
kIntrinsicDoubleCvt,
diff --git a/runtime/quick_exception_handler.cc b/runtime/quick_exception_handler.cc
index 55aba2b..b3f29c2 100644
--- a/runtime/quick_exception_handler.cc
+++ b/runtime/quick_exception_handler.cc
@@ -160,8 +160,8 @@
LOG(INFO) << "Handler is upcall";
}
if (handler_method_ != nullptr) {
- const DexFile& dex_file = *handler_method_->GetDeclaringClass()->GetDexCache()->GetDexFile();
- int line_number = dex_file.GetLineNumFromPC(handler_method_, handler_dex_pc_);
+ const DexFile* dex_file = handler_method_->GetDeclaringClass()->GetDexCache()->GetDexFile();
+ int line_number = annotations::GetLineNumFromPC(dex_file, handler_method_, handler_dex_pc_);
LOG(INFO) << "Handler: " << PrettyMethod(handler_method_) << " (line: " << line_number << ")";
}
}
diff --git a/runtime/reflection.cc b/runtime/reflection.cc
index f2af3da..67e3fe8 100644
--- a/runtime/reflection.cc
+++ b/runtime/reflection.cc
@@ -625,8 +625,12 @@
// If method is not set to be accessible, verify it can be accessed by the caller.
mirror::Class* calling_class = nullptr;
- if (!accessible && !VerifyAccess(soa.Self(), receiver, declaring_class, m->GetAccessFlags(),
- &calling_class, num_frames)) {
+ if (!accessible && !VerifyAccess(soa.Self(),
+ receiver,
+ declaring_class,
+ m->GetAccessFlags(),
+ &calling_class,
+ num_frames)) {
ThrowIllegalAccessException(
StringPrintf("Class %s cannot access %s method %s of class %s",
calling_class == nullptr ? "null" : PrettyClass(calling_class).c_str(),
@@ -857,15 +861,17 @@
return false;
}
*calling_class = klass;
- return VerifyAccess(self, obj, declaring_class, access_flags, klass);
+ return VerifyAccess(obj, declaring_class, access_flags, klass);
}
-bool VerifyAccess(Thread* self, mirror::Object* obj, mirror::Class* declaring_class,
- uint32_t access_flags, mirror::Class* calling_class) {
+bool VerifyAccess(mirror::Object* obj,
+ mirror::Class* declaring_class,
+ uint32_t access_flags,
+ mirror::Class* calling_class) {
if (calling_class == declaring_class) {
return true;
}
- ScopedAssertNoThreadSuspension sants(self, "verify-access");
+ ScopedAssertNoThreadSuspension sants("verify-access");
if ((access_flags & kAccPrivate) != 0) {
return false;
}
diff --git a/runtime/reflection.h b/runtime/reflection.h
index 579c6b1..208b533 100644
--- a/runtime/reflection.h
+++ b/runtime/reflection.h
@@ -74,8 +74,10 @@
REQUIRES_SHARED(Locks::mutator_lock_);
// This version takes a known calling class.
-bool VerifyAccess(Thread* self, mirror::Object* obj, mirror::Class* declaring_class,
- uint32_t access_flags, mirror::Class* calling_class)
+bool VerifyAccess(mirror::Object* obj,
+ mirror::Class* declaring_class,
+ uint32_t access_flags,
+ mirror::Class* calling_class)
REQUIRES_SHARED(Locks::mutator_lock_);
// Get the calling class by using a stack visitor, may return null for unattached native threads.
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 43ef1cb..8940354 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -40,6 +40,7 @@
#include "class_linker-inl.h"
#include "debugger.h"
#include "dex_file-inl.h"
+#include "dex_file_annotations.h"
#include "entrypoints/entrypoint_utils.h"
#include "entrypoints/quick/quick_alloc_entrypoints.h"
#include "gc/accounting/card_table-inl.h"
@@ -1388,8 +1389,8 @@
mirror::DexCache* dex_cache = c->GetDexCache();
int line_number = -1;
if (dex_cache != nullptr) { // be tolerant of bad input
- const DexFile& dex_file = *dex_cache->GetDexFile();
- line_number = dex_file.GetLineNumFromPC(m, GetDexPc(false));
+ const DexFile* dex_file = dex_cache->GetDexFile();
+ line_number = annotations::GetLineNumFromPC(dex_file, m, GetDexPc(false));
}
if (line_number == last_line_number && last_method == m) {
++repetition_count;
@@ -2548,7 +2549,6 @@
QUICK_ENTRY_POINT_INFO(pDeliverException)
QUICK_ENTRY_POINT_INFO(pThrowArrayBounds)
QUICK_ENTRY_POINT_INFO(pThrowDivZero)
- QUICK_ENTRY_POINT_INFO(pThrowNoSuchMethod)
QUICK_ENTRY_POINT_INFO(pThrowNullPointer)
QUICK_ENTRY_POINT_INFO(pThrowStackOverflow)
QUICK_ENTRY_POINT_INFO(pDeoptimize)
diff --git a/runtime/thread.h b/runtime/thread.h
index d248123..016c2bc 100644
--- a/runtime/thread.h
+++ b/runtime/thread.h
@@ -1363,12 +1363,12 @@
instrumentation_stack(nullptr), debug_invoke_req(nullptr), single_step_control(nullptr),
stacked_shadow_frame_record(nullptr), deoptimization_context_stack(nullptr),
frame_id_to_shadow_frame(nullptr), name(nullptr), pthread_self(0),
- last_no_thread_suspension_cause(nullptr), thread_local_start(nullptr),
- thread_local_objects(0), thread_local_pos(nullptr), thread_local_end(nullptr),
- mterp_current_ibase(nullptr), mterp_default_ibase(nullptr), mterp_alt_ibase(nullptr),
- thread_local_alloc_stack_top(nullptr), thread_local_alloc_stack_end(nullptr),
- nested_signal_state(nullptr), flip_function(nullptr), method_verifier(nullptr),
- thread_local_mark_stack(nullptr) {
+ last_no_thread_suspension_cause(nullptr), checkpoint_function(nullptr),
+ thread_local_start(nullptr), thread_local_pos(nullptr), thread_local_end(nullptr),
+ thread_local_objects(0), mterp_current_ibase(nullptr), mterp_default_ibase(nullptr),
+ mterp_alt_ibase(nullptr), thread_local_alloc_stack_top(nullptr),
+ thread_local_alloc_stack_end(nullptr), nested_signal_state(nullptr),
+ flip_function(nullptr), method_verifier(nullptr), thread_local_mark_stack(nullptr) {
std::fill(held_mutexes, held_mutexes + kLockLevelCount, nullptr);
}
@@ -1480,11 +1480,11 @@
// Thread-local allocation pointer.
uint8_t* thread_local_start;
- size_t thread_local_objects;
// thread_local_pos and thread_local_end must be consecutive for ldrd and are 8 byte aligned for
// potentially better performance.
uint8_t* thread_local_pos;
uint8_t* thread_local_end;
+ size_t thread_local_objects;
// Mterp jump table bases.
void* mterp_current_ibase;
@@ -1546,19 +1546,25 @@
class SCOPED_CAPABILITY ScopedAssertNoThreadSuspension {
public:
- ScopedAssertNoThreadSuspension(Thread* self, const char* cause) ACQUIRE(Roles::uninterruptible_)
- : self_(self), old_cause_(self->StartAssertNoThreadSuspension(cause)) {
+ ALWAYS_INLINE ScopedAssertNoThreadSuspension(const char* cause) ACQUIRE(Roles::uninterruptible_) {
+ if (kIsDebugBuild) {
+ self_ = Thread::Current();
+ old_cause_ = self_->StartAssertNoThreadSuspension(cause);
+ } else {
+ Roles::uninterruptible_.Acquire(); // No-op.
+ }
}
- ~ScopedAssertNoThreadSuspension() RELEASE(Roles::uninterruptible_) {
- self_->EndAssertNoThreadSuspension(old_cause_);
- }
- Thread* Self() {
- return self_;
+ ALWAYS_INLINE ~ScopedAssertNoThreadSuspension() RELEASE(Roles::uninterruptible_) {
+ if (kIsDebugBuild) {
+ self_->EndAssertNoThreadSuspension(old_cause_);
+ } else {
+ Roles::uninterruptible_.Release(); // No-op.
+ }
}
private:
- Thread* const self_;
- const char* const old_cause_;
+ Thread* self_;
+ const char* old_cause_;
};
class ScopedStackedShadowFramePusher {