Merge "Oatdump: Smarter StackMap lookup to improve performance."
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index be149af..5294068 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -357,7 +357,7 @@
compiler_kind_(compiler_kind),
instruction_set_(instruction_set),
instruction_set_features_(instruction_set_features),
- freezing_constructor_lock_("freezing constructor lock"),
+ requires_constructor_barrier_lock_("constructor barrier lock"),
compiled_classes_lock_("compiled classes lock"),
compiled_methods_lock_("compiled method lock"),
compiled_methods_(MethodTable::key_compare()),
@@ -2006,6 +2006,28 @@
self->ClearException();
}
+bool CompilerDriver::RequiresConstructorBarrier(const DexFile& dex_file,
+ uint16_t class_def_idx) const {
+ const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_def_idx);
+ const uint8_t* class_data = dex_file.GetClassData(class_def);
+ if (class_data == nullptr) {
+ // Empty class such as a marker interface.
+ return false;
+ }
+ ClassDataItemIterator it(dex_file, class_data);
+ while (it.HasNextStaticField()) {
+ it.Next();
+ }
+ // We require a constructor barrier if there are final instance fields.
+ while (it.HasNextInstanceField()) {
+ if (it.MemberIsFinal()) {
+ return true;
+ }
+ it.Next();
+ }
+ return false;
+}
+
class ResolveClassFieldsAndMethodsVisitor : public CompilationVisitor {
public:
explicit ResolveClassFieldsAndMethodsVisitor(const ParallelCompilationManager* manager)
@@ -2110,9 +2132,10 @@
DCHECK(!it.HasNext());
}
}
- if (requires_constructor_barrier) {
- manager_->GetCompiler()->AddRequiresConstructorBarrier(self, &dex_file, class_def_index);
- }
+ manager_->GetCompiler()->SetRequiresConstructorBarrier(self,
+ &dex_file,
+ class_def_index,
+ requires_constructor_barrier);
}
private:
@@ -2769,16 +2792,29 @@
return non_relative_linker_patch_count_;
}
-void CompilerDriver::AddRequiresConstructorBarrier(Thread* self, const DexFile* dex_file,
- uint16_t class_def_index) {
- WriterMutexLock mu(self, freezing_constructor_lock_);
- freezing_constructor_classes_.insert(ClassReference(dex_file, class_def_index));
+void CompilerDriver::SetRequiresConstructorBarrier(Thread* self,
+ const DexFile* dex_file,
+ uint16_t class_def_index,
+ bool requires) {
+ WriterMutexLock mu(self, requires_constructor_barrier_lock_);
+ requires_constructor_barrier_.emplace(ClassReference(dex_file, class_def_index), requires);
}
-bool CompilerDriver::RequiresConstructorBarrier(Thread* self, const DexFile* dex_file,
- uint16_t class_def_index) const {
- ReaderMutexLock mu(self, freezing_constructor_lock_);
- return freezing_constructor_classes_.count(ClassReference(dex_file, class_def_index)) != 0;
+bool CompilerDriver::RequiresConstructorBarrier(Thread* self,
+ const DexFile* dex_file,
+ uint16_t class_def_index) {
+ ClassReference class_ref(dex_file, class_def_index);
+ {
+ ReaderMutexLock mu(self, requires_constructor_barrier_lock_);
+ auto it = requires_constructor_barrier_.find(class_ref);
+ if (it != requires_constructor_barrier_.end()) {
+ return it->second;
+ }
+ }
+ WriterMutexLock mu(self, requires_constructor_barrier_lock_);
+ const bool requires = RequiresConstructorBarrier(*dex_file, class_def_index);
+ requires_constructor_barrier_.emplace(class_ref, requires);
+ return requires;
}
std::string CompilerDriver::GetMemoryUsageString(bool extended) const {
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index 64a06a2..905f84d 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -183,12 +183,15 @@
// Remove and delete a compiled method.
void RemoveCompiledMethod(const MethodReference& method_ref) REQUIRES(!compiled_methods_lock_);
- void AddRequiresConstructorBarrier(Thread* self, const DexFile* dex_file,
- uint16_t class_def_index)
- REQUIRES(!freezing_constructor_lock_);
- bool RequiresConstructorBarrier(Thread* self, const DexFile* dex_file,
- uint16_t class_def_index) const
- REQUIRES(!freezing_constructor_lock_);
+ void SetRequiresConstructorBarrier(Thread* self,
+ const DexFile* dex_file,
+ uint16_t class_def_index,
+ bool requires)
+ REQUIRES(!requires_constructor_barrier_lock_);
+ bool RequiresConstructorBarrier(Thread* self,
+ const DexFile* dex_file,
+ uint16_t class_def_index)
+ REQUIRES(!requires_constructor_barrier_lock_);
// Callbacks from compiler to see what runtime checks must be generated.
@@ -619,6 +622,8 @@
void FreeThreadPools();
void CheckThreadPools();
+ bool RequiresConstructorBarrier(const DexFile& dex_file, uint16_t class_def_idx) const;
+
const CompilerOptions* const compiler_options_;
VerificationResults* const verification_results_;
DexFileToMethodInlinerMap* const method_inliner_map_;
@@ -629,9 +634,11 @@
const InstructionSet instruction_set_;
const InstructionSetFeatures* const instruction_set_features_;
- // All class references that require
- mutable ReaderWriterMutex freezing_constructor_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
- std::set<ClassReference> freezing_constructor_classes_ GUARDED_BY(freezing_constructor_lock_);
+ // All class references that require constructor barriers. If the class reference is not in the
+ // set then the result has not yet been computed.
+ mutable ReaderWriterMutex requires_constructor_barrier_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
+ std::map<ClassReference, bool> requires_constructor_barrier_
+ GUARDED_BY(requires_constructor_barrier_lock_);
typedef SafeMap<const ClassReference, CompiledClass*> ClassTable;
// All class references that this compiler has compiled.
diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc
index b0f0893..06b3968 100644
--- a/compiler/optimizing/instruction_builder.cc
+++ b/compiler/optimizing/instruction_builder.cc
@@ -567,10 +567,10 @@
UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
}
-static bool RequiresConstructorBarrier(const DexCompilationUnit* cu, const CompilerDriver& driver) {
+static bool RequiresConstructorBarrier(const DexCompilationUnit* cu, CompilerDriver* driver) {
Thread* self = Thread::Current();
return cu->IsConstructor()
- && driver.RequiresConstructorBarrier(self, cu->GetDexFile(), cu->GetClassDefIndex());
+ && driver->RequiresConstructorBarrier(self, cu->GetDexFile(), cu->GetClassDefIndex());
}
// Returns true if `block` has only one successor which starts at the next
@@ -616,7 +616,7 @@
if (graph_->ShouldGenerateConstructorBarrier()) {
// The compilation unit is null during testing.
if (dex_compilation_unit_ != nullptr) {
- DCHECK(RequiresConstructorBarrier(dex_compilation_unit_, *compiler_driver_))
+ DCHECK(RequiresConstructorBarrier(dex_compilation_unit_, compiler_driver_))
<< "Inconsistent use of ShouldGenerateConstructorBarrier. Should not generate a barrier.";
}
AppendInstruction(new (arena_) HMemoryBarrier(kStoreStore, dex_pc));
diff --git a/imgdiag/imgdiag.cc b/imgdiag/imgdiag.cc
index 811d9fd..c2a812e 100644
--- a/imgdiag/imgdiag.cc
+++ b/imgdiag/imgdiag.cc
@@ -18,6 +18,7 @@
#include <stdlib.h>
#include <fstream>
+#include <functional>
#include <iostream>
#include <string>
#include <vector>
@@ -189,6 +190,28 @@
return oss.str();
}
+ // Aggregate and detail class data from an image diff.
+ struct ClassData {
+ int dirty_object_count = 0;
+
+ // Track only the byte-per-byte dirtiness (in bytes)
+ int dirty_object_byte_count = 0;
+
+ // Track the object-by-object dirtiness (in bytes)
+ int dirty_object_size_in_bytes = 0;
+
+ int clean_object_count = 0;
+
+ std::string descriptor;
+
+ int false_dirty_byte_count = 0;
+ int false_dirty_object_count = 0;
+ std::vector<mirror::Object*> false_dirty_objects;
+
+ // Remote pointers to dirty objects
+ std::vector<mirror::Object*> dirty_objects;
+ };
+
// Look at /proc/$pid/mem and only diff the things from there
bool DumpImageDiffMap(pid_t image_diff_pid, const backtrace_map_t& boot_map)
SHARED_REQUIRES(Locks::mutator_lock_) {
@@ -373,16 +396,10 @@
}
}
+ std::map<mirror::Class*, ClassData> class_data;
+
// Walk each object in the remote image space and compare it against ours
size_t different_objects = 0;
- std::map<mirror::Class*, int /*count*/> dirty_object_class_map;
- // Track only the byte-per-byte dirtiness (in bytes)
- std::map<mirror::Class*, int /*byte_count*/> dirty_object_byte_count;
- // Track the object-by-object dirtiness (in bytes)
- std::map<mirror::Class*, int /*byte_count*/> dirty_object_size_in_bytes;
- std::map<mirror::Class*, int /*count*/> clean_object_class_map;
-
- std::map<mirror::Class*, std::string> class_to_descriptor_map;
std::map<off_t /* field offset */, int /* count */> art_method_field_dirty_count;
std::vector<ArtMethod*> art_method_dirty_objects;
@@ -392,13 +409,8 @@
// List of local objects that are clean, but located on dirty pages.
std::vector<mirror::Object*> false_dirty_objects;
- std::map<mirror::Class*, int /*byte_count*/> false_dirty_byte_count;
- std::map<mirror::Class*, int /*object_count*/> false_dirty_object_count;
- std::map<mirror::Class*, std::vector<mirror::Object*>> false_dirty_objects_map;
size_t false_dirty_object_bytes = 0;
- // Remote pointers to dirty objects
- std::map<mirror::Class*, std::vector<mirror::Object*>> dirty_objects_by_class;
// Look up remote classes by their descriptor
std::map<std::string, mirror::Class*> remote_class_map;
// Look up local classes by their descriptor
@@ -453,7 +465,7 @@
dirty_object_bytes += obj->SizeOf();
dirty_objects.insert(obj);
- ++dirty_object_class_map[klass];
+ ++class_data[klass].dirty_object_count;
// Go byte-by-byte and figure out what exactly got dirtied
size_t dirty_byte_count_per_object = 0;
@@ -462,14 +474,14 @@
dirty_byte_count_per_object++;
}
}
- dirty_object_byte_count[klass] += dirty_byte_count_per_object;
- dirty_object_size_in_bytes[klass] += obj->SizeOf();
+ class_data[klass].dirty_object_byte_count += dirty_byte_count_per_object;
+ class_data[klass].dirty_object_size_in_bytes += obj->SizeOf();
different_object = true;
- dirty_objects_by_class[klass].push_back(remote_obj);
+ class_data[klass].dirty_objects.push_back(remote_obj);
} else {
- ++clean_object_class_map[klass];
+ ++class_data[klass].clean_object_count;
}
std::string descriptor = GetClassDescriptor(klass);
@@ -503,10 +515,10 @@
// This object was either never mutated or got mutated back to the same value.
// TODO: Do I want to distinguish a "different" vs a "dirty" page here?
false_dirty_objects.push_back(obj);
- false_dirty_objects_map[klass].push_back(obj);
+ class_data[klass].false_dirty_objects.push_back(obj);
false_dirty_object_bytes += obj->SizeOf();
- false_dirty_byte_count[obj->GetClass()] += obj->SizeOf();
- false_dirty_object_count[obj->GetClass()] += 1;
+ class_data[obj->GetClass()].false_dirty_byte_count += obj->SizeOf();
+ class_data[obj->GetClass()].false_dirty_object_count += 1;
}
if (strcmp(descriptor.c_str(), "Ljava/lang/Class;") == 0) {
@@ -515,7 +527,7 @@
}
// Unconditionally store the class descriptor in case we need it later
- class_to_descriptor_map[klass] = descriptor;
+ class_data[klass].descriptor = descriptor;
current += RoundUp(obj->SizeOf(), kObjectAlignment);
}
@@ -540,8 +552,10 @@
<< "";
// vector of pairs (int count, Class*)
- auto dirty_object_class_values = SortByValueDesc(dirty_object_class_map);
- auto clean_object_class_values = SortByValueDesc(clean_object_class_map);
+ auto dirty_object_class_values = SortByValueDesc<mirror::Class*, int, ClassData>(
+ class_data, [](const ClassData& d) { return d.dirty_object_count; });
+ auto clean_object_class_values = SortByValueDesc<mirror::Class*, int, ClassData>(
+ class_data, [](const ClassData& d) { return d.clean_object_count; });
os << "\n" << " Dirty objects: " << dirty_objects.size() << "\n";
for (mirror::Object* obj : dirty_objects) {
@@ -612,10 +626,11 @@
for (const auto& vk_pair : dirty_object_class_values) {
int dirty_object_count = vk_pair.first;
mirror::Class* klass = vk_pair.second;
- int object_sizes = dirty_object_size_in_bytes[klass];
- float avg_dirty_bytes_per_class = dirty_object_byte_count[klass] * 1.0f / object_sizes;
+ int object_sizes = class_data[klass].dirty_object_size_in_bytes;
+ float avg_dirty_bytes_per_class =
+ class_data[klass].dirty_object_byte_count * 1.0f / object_sizes;
float avg_object_size = object_sizes * 1.0f / dirty_object_count;
- const std::string& descriptor = class_to_descriptor_map[klass];
+ const std::string& descriptor = class_data[klass].descriptor;
os << " " << PrettyClass(klass) << " ("
<< "objects: " << dirty_object_count << ", "
<< "avg dirty bytes: " << avg_dirty_bytes_per_class << ", "
@@ -634,7 +649,8 @@
os << "\n";
os << " dirty byte +offset:count list = ";
- auto art_method_field_dirty_count_sorted = SortByValueDesc(art_method_field_dirty_count);
+ auto art_method_field_dirty_count_sorted =
+ SortByValueDesc<off_t, int, int>(art_method_field_dirty_count);
for (auto pair : art_method_field_dirty_count_sorted) {
off_t offset = pair.second;
int count = pair.first;
@@ -645,7 +661,7 @@
os << "\n";
os << " field contents:\n";
- const auto& dirty_objects_list = dirty_objects_by_class[klass];
+ const auto& dirty_objects_list = class_data[klass].dirty_objects;
for (mirror::Object* obj : dirty_objects_list) {
// remote method
auto art_method = reinterpret_cast<ArtMethod*>(obj);
@@ -684,7 +700,8 @@
os << "\n";
os << " dirty byte +offset:count list = ";
- auto class_field_dirty_count_sorted = SortByValueDesc(class_field_dirty_count);
+ auto class_field_dirty_count_sorted =
+ SortByValueDesc<off_t, int, int>(class_field_dirty_count);
for (auto pair : class_field_dirty_count_sorted) {
off_t offset = pair.second;
int count = pair.first;
@@ -694,7 +711,7 @@
os << "\n";
os << " field contents:\n";
- const auto& dirty_objects_list = dirty_objects_by_class[klass];
+ const auto& dirty_objects_list = class_data[klass].dirty_objects;
for (mirror::Object* obj : dirty_objects_list) {
// remote class object
auto remote_klass = reinterpret_cast<mirror::Class*>(obj);
@@ -712,15 +729,16 @@
}
}
- auto false_dirty_object_class_values = SortByValueDesc(false_dirty_object_count);
+ auto false_dirty_object_class_values = SortByValueDesc<mirror::Class*, int, ClassData>(
+ class_data, [](const ClassData& d) { return d.false_dirty_object_count; });
os << "\n" << " False-dirty object count by class:\n";
for (const auto& vk_pair : false_dirty_object_class_values) {
int object_count = vk_pair.first;
mirror::Class* klass = vk_pair.second;
- int object_sizes = false_dirty_byte_count[klass];
+ int object_sizes = class_data[klass].false_dirty_byte_count;
float avg_object_size = object_sizes * 1.0f / object_count;
- const std::string& descriptor = class_to_descriptor_map[klass];
+ const std::string& descriptor = class_data[klass].descriptor;
os << " " << PrettyClass(klass) << " ("
<< "objects: " << object_count << ", "
<< "avg object size: " << avg_object_size << ", "
@@ -729,7 +747,7 @@
<< ")\n";
if (strcmp(descriptor.c_str(), "Ljava/lang/reflect/ArtMethod;") == 0) {
- auto& art_method_false_dirty_objects = false_dirty_objects_map[klass];
+ auto& art_method_false_dirty_objects = class_data[klass].false_dirty_objects;
os << " field contents:\n";
for (mirror::Object* obj : art_method_false_dirty_objects) {
@@ -808,14 +826,16 @@
return std::string(descriptor_str);
}
- template <typename K, typename V>
- static std::vector<std::pair<V, K>> SortByValueDesc(const std::map<K, V> map) {
+ template <typename K, typename V, typename D>
+ static std::vector<std::pair<V, K>> SortByValueDesc(
+ const std::map<K, D> map,
+ std::function<V(const D&)> value_mapper = [](const D& d) { return static_cast<V>(d); }) {
// Store value->key so that we can use the default sort from pair which
// sorts by value first and then key
std::vector<std::pair<V, K>> value_key_vector;
for (const auto& kv_pair : map) {
- value_key_vector.push_back(std::make_pair(kv_pair.second, kv_pair.first));
+ value_key_vector.push_back(std::make_pair(value_mapper(kv_pair.second), kv_pair.first));
}
// Sort in reverse (descending order)
diff --git a/runtime/arch/mips/quick_entrypoints_mips.S b/runtime/arch/mips/quick_entrypoints_mips.S
index fd1851f..3c0e452 100644
--- a/runtime/arch/mips/quick_entrypoints_mips.S
+++ b/runtime/arch/mips/quick_entrypoints_mips.S
@@ -319,6 +319,111 @@
.endm
/*
+ * On stack replacement stub.
+ * On entry:
+ * a0 = stack to copy
+ * a1 = size of stack
+ * a2 = pc to call
+ * a3 = JValue* result
+ * [sp + 16] = shorty
+ * [sp + 20] = thread
+ */
+ENTRY art_quick_osr_stub
+ // Save callee general purpose registers, RA and GP.
+ addiu $sp, $sp, -48
+ .cfi_adjust_cfa_offset 48
+ sw $ra, 44($sp)
+ .cfi_rel_offset 31, 44
+ sw $s8, 40($sp)
+ .cfi_rel_offset 30, 40
+ sw $gp, 36($sp)
+ .cfi_rel_offset 28, 36
+ sw $s7, 32($sp)
+ .cfi_rel_offset 23, 32
+ sw $s6, 28($sp)
+ .cfi_rel_offset 22, 28
+ sw $s5, 24($sp)
+ .cfi_rel_offset 21, 24
+ sw $s4, 20($sp)
+ .cfi_rel_offset 20, 20
+ sw $s3, 16($sp)
+ .cfi_rel_offset 19, 16
+ sw $s2, 12($sp)
+ .cfi_rel_offset 18, 12
+ sw $s1, 8($sp)
+ .cfi_rel_offset 17, 8
+ sw $s0, 4($sp)
+ .cfi_rel_offset 16, 4
+
+ move $s8, $sp # Save the stack pointer
+ move $s7, $a1 # Save size of stack
+ move $s6, $a2 # Save the pc to call
+ lw rSELF, 48+20($sp) # Save managed thread pointer into rSELF
+ addiu $t0, $sp, -12 # Reserve space for stack pointer,
+ # JValue* result, and ArtMethod* slot.
+ srl $t0, $t0, 4 # Align stack pointer to 16 bytes
+ sll $sp, $t0, 4 # Update stack pointer
+ sw $s8, 4($sp) # Save old stack pointer
+ sw $a3, 8($sp) # Save JValue* result
+ sw $zero, 0($sp) # Store null for ArtMethod* at bottom of frame
+ subu $sp, $a1 # Reserve space for callee stack
+ move $a2, $a1
+ move $a1, $a0
+ move $a0, $sp
+ la $t9, memcpy
+ jalr $t9 # memcpy (dest a0, src a1, bytes a2)
+ addiu $sp, $sp, -16 # make space for argument slots for memcpy
+ bal .Losr_entry # Call the method
+ addiu $sp, $sp, 16 # restore stack after memcpy
+ lw $a2, 8($sp) # Restore JValue* result
+ lw $sp, 4($sp) # Restore saved stack pointer
+ lw $a0, 48+16($sp) # load shorty
+ lbu $a0, 0($a0) # load return type
+ li $a1, 'D' # put char 'D' into a1
+ beq $a0, $a1, .Losr_fp_result # Test if result type char == 'D'
+ li $a1, 'F' # put char 'F' into a1
+ beq $a0, $a1, .Losr_fp_result # Test if result type char == 'F'
+ nop
+ sw $v0, 0($a2)
+ b .Losr_exit
+ sw $v1, 4($a2) # store v0/v1 into result
+.Losr_fp_result:
+ SDu $f0, $f1, 0, $a2, $t0 # store f0/f1 into result
+.Losr_exit:
+ lw $ra, 44($sp)
+ .cfi_restore 31
+ lw $s8, 40($sp)
+ .cfi_restore 30
+ lw $gp, 36($sp)
+ .cfi_restore 28
+ lw $s7, 32($sp)
+ .cfi_restore 23
+ lw $s6, 28($sp)
+ .cfi_restore 22
+ lw $s5, 24($sp)
+ .cfi_restore 21
+ lw $s4, 20($sp)
+ .cfi_restore 20
+ lw $s3, 16($sp)
+ .cfi_restore 19
+ lw $s2, 12($sp)
+ .cfi_restore 18
+ lw $s1, 8($sp)
+ .cfi_restore 17
+ lw $s0, 4($sp)
+ .cfi_restore 16
+ jalr $zero, $ra
+ addiu $sp, $sp, 48
+ .cfi_adjust_cfa_offset -48
+.Losr_entry:
+ addiu $s7, $s7, -4
+ addu $t0, $s7, $sp
+ move $t9, $s6
+ jalr $zero, $t9
+ sw $ra, 0($t0) # Store RA per the compiler ABI
+END art_quick_osr_stub
+
+ /*
* On entry $a0 is uint32_t* gprs_ and $a1 is uint32_t* fprs_
* FIXME: just guessing about the shape of the jmpbuf. Where will pc be?
*/
diff --git a/runtime/arch/mips64/quick_entrypoints_mips64.S b/runtime/arch/mips64/quick_entrypoints_mips64.S
index f1e605a..f31b92a 100644
--- a/runtime/arch/mips64/quick_entrypoints_mips64.S
+++ b/runtime/arch/mips64/quick_entrypoints_mips64.S
@@ -358,6 +358,138 @@
.endm
/*
+ * On stack replacement stub.
+ * On entry:
+ * a0 = stack to copy
+ * a1 = size of stack
+ * a2 = pc to call
+ * a3 = JValue* result
+ * a4 = shorty
+ * a5 = thread
+ */
+ENTRY art_quick_osr_stub
+ move $t0, $sp # save stack pointer
+ daddiu $t1, $sp, -112 # reserve stack space
+ dsrl $t1, $t1, 4 # enforce 16 byte stack alignment
+ dsll $sp, $t1, 4 # update stack pointer
+
+ // Save callee general purpose registers, SP, T8(GP), RA, A3, and A4 (8x14 bytes)
+ sd $ra, 104($sp)
+ .cfi_rel_offset 31, 104
+ sd $s8, 96($sp)
+ .cfi_rel_offset 30, 96
+ sd $t0, 88($sp) # save original stack pointer stored in t0
+ .cfi_rel_offset 29, 88
+ sd $t8, 80($sp) # t8 holds caller's gp, now save it to the stack.
+ .cfi_rel_offset 28, 80 # Value from gp is pushed, so set the cfi offset accordingly.
+ sd $s7, 72($sp)
+ .cfi_rel_offset 23, 72
+ sd $s6, 64($sp)
+ .cfi_rel_offset 22, 64
+ sd $s5, 56($sp)
+ .cfi_rel_offset 21, 56
+ sd $s4, 48($sp)
+ .cfi_rel_offset 20, 48
+ sd $s3, 40($sp)
+ .cfi_rel_offset 19, 40
+ sd $s2, 32($sp)
+ .cfi_rel_offset 18, 32
+ sd $s1, 24($sp)
+ .cfi_rel_offset 17, 24
+ sd $s0, 16($sp)
+ .cfi_rel_offset 16, 16
+ sd $a4, 8($sp)
+ .cfi_rel_offset 8, 8
+ sd $a3, 0($sp)
+ .cfi_rel_offset 7, 0
+ move rSELF, $a5 # Save managed thread pointer into rSELF
+
+ daddiu $sp, $sp, -16
+ jal .Losr_entry
+ sd $zero, 0($sp) # Store null for ArtMethod* at bottom of frame
+ daddiu $sp, $sp, 16
+
+ // Restore return value address and shorty address
+ ld $a4, 8($sp) # shorty address
+ .cfi_restore 8
+ ld $a3, 0($sp) # result value address
+ .cfi_restore 7
+
+ lbu $t1, 0($a4) # load return type
+ li $t2, 'D' # put char 'D' into t2
+ beq $t1, $t2, .Losr_fp_result # branch if result type char == 'D'
+ li $t2, 'F' # put char 'F' into t2
+ beq $t1, $t2, .Losr_fp_result # branch if result type char == 'F'
+ nop
+ b .Losr_exit
+ dsrl $v1, $v0, 32 # put high half of result in v1
+.Losr_fp_result:
+ mfc1 $v0, $f0
+ mfhc1 $v1, $f0 # put high half of FP result in v1
+.Losr_exit:
+ sw $v0, 0($a3) # store low half of result
+ sw $v1, 4($a3) # store high half of result
+
+ // Restore callee registers
+ ld $ra, 104($sp)
+ .cfi_restore 31
+ ld $s8, 96($sp)
+ .cfi_restore 30
+ ld $t0, 88($sp) # save SP into t0 for now
+ .cfi_restore 29
+ ld $t8, 80($sp) # Restore gp back to it's temp storage.
+ .cfi_restore 28
+ ld $s7, 72($sp)
+ .cfi_restore 23
+ ld $s6, 64($sp)
+ .cfi_restore 22
+ ld $s5, 56($sp)
+ .cfi_restore 21
+ ld $s4, 48($sp)
+ .cfi_restore 20
+ ld $s3, 40($sp)
+ .cfi_restore 19
+ ld $s2, 32($sp)
+ .cfi_restore 18
+ ld $s1, 24($sp)
+ .cfi_restore 17
+ ld $s0, 16($sp)
+ .cfi_restore 16
+ jalr $zero, $ra
+ move $sp, $t0
+
+.Losr_entry:
+ dsubu $sp, $sp, $a1 # Reserve space for callee stack
+ daddiu $a1, $a1, -8
+ daddu $t0, $a1, $sp
+ sw $ra, 0($t0) # Store low half of RA per compiler ABI
+ dsrl $t1, $ra, 32
+ sw $t1, 4($t0) # Store high half of RA per compiler ABI
+
+ // Copy arguments into callee stack
+ // Use simple copy routine for now.
+ // 4 bytes per slot.
+ // a0 = source address
+ // a1 = args length in bytes (does not include 8 bytes for RA)
+ // sp = destination address
+ beqz $a1, .Losr_loop_exit
+ daddiu $a1, $a1, -4
+ daddu $t1, $a0, $a1
+ daddu $t2, $sp, $a1
+.Losr_loop_entry:
+ lw $t0, 0($t1)
+ daddiu $t1, $t1, -4
+ sw $t0, 0($t2)
+ bne $sp, $t2, .Losr_loop_entry
+ daddiu $t2, $t2, -4
+
+.Losr_loop_exit:
+ move $t9, $a2
+ jalr $zero, $t9 # Jump to the OSR entry point.
+ nop
+END art_quick_osr_stub
+
+ /*
* On entry $a0 is uint32_t* gprs_ and $a1 is uint32_t* fprs_
* FIXME: just guessing about the shape of the jmpbuf. Where will pc be?
*/
diff --git a/runtime/art_method.h b/runtime/art_method.h
index 3dbcd58..d1ef019 100644
--- a/runtime/art_method.h
+++ b/runtime/art_method.h
@@ -545,6 +545,9 @@
ALWAYS_INLINE GcRoot<mirror::Class>* GetDexCacheResolvedTypes(size_t pointer_size)
SHARED_REQUIRES(Locks::mutator_lock_);
+ // Note, hotness_counter_ updates are non-atomic but it doesn't need to be precise. Also,
+ // given that the counter is only 16 bits wide we can expect wrap-around in some
+ // situations. Consumers of hotness_count_ must be able to deal with that.
uint16_t IncrementCounter() {
return ++hotness_count_;
}
@@ -553,6 +556,14 @@
hotness_count_ = 0;
}
+ void SetCounter(int16_t hotness_count) {
+ hotness_count_ = hotness_count;
+ }
+
+ uint16_t GetCounter() const {
+ return hotness_count_;
+ }
+
const uint8_t* GetQuickenedInfo() SHARED_REQUIRES(Locks::mutator_lock_);
// Returns the method header for the compiled code containing 'pc'. Note that runtime
@@ -597,7 +608,7 @@
// ifTable.
uint16_t method_index_;
- // The hotness we measure for this method. Incremented by the interpreter. Not atomic, as we allow
+ // The hotness we measure for this method. Managed by the interpreter. Not atomic, as we allow
// missing increments: if the method is hot, we will see it eventually.
uint16_t hotness_count_;
diff --git a/runtime/asm_support.h b/runtime/asm_support.h
index 942f9de..d27d2f6 100644
--- a/runtime/asm_support.h
+++ b/runtime/asm_support.h
@@ -20,6 +20,7 @@
#if defined(__cplusplus)
#include "art_method.h"
#include "gc/allocator/rosalloc.h"
+#include "jit/jit_instrumentation.h"
#include "lock_word.h"
#include "mirror/class.h"
#include "mirror/string.h"
@@ -188,7 +189,13 @@
#define SHADOWFRAME_DEX_PC_OFFSET (SHADOWFRAME_NUMBER_OF_VREGS_OFFSET + 4)
ADD_TEST_EQ(SHADOWFRAME_DEX_PC_OFFSET,
static_cast<int32_t>(art::ShadowFrame::DexPCOffset()))
-#define SHADOWFRAME_VREGS_OFFSET (SHADOWFRAME_NUMBER_OF_VREGS_OFFSET + 8)
+#define SHADOWFRAME_CACHED_HOTNESS_COUNTDOWN_OFFSET (SHADOWFRAME_NUMBER_OF_VREGS_OFFSET + 8)
+ADD_TEST_EQ(SHADOWFRAME_CACHED_HOTNESS_COUNTDOWN_OFFSET,
+ static_cast<int32_t>(art::ShadowFrame::CachedHotnessCountdownOffset()))
+#define SHADOWFRAME_HOTNESS_COUNTDOWN_OFFSET (SHADOWFRAME_NUMBER_OF_VREGS_OFFSET + 10)
+ADD_TEST_EQ(SHADOWFRAME_HOTNESS_COUNTDOWN_OFFSET,
+ static_cast<int32_t>(art::ShadowFrame::HotnessCountdownOffset()))
+#define SHADOWFRAME_VREGS_OFFSET (SHADOWFRAME_NUMBER_OF_VREGS_OFFSET + 12)
ADD_TEST_EQ(SHADOWFRAME_VREGS_OFFSET,
static_cast<int32_t>(art::ShadowFrame::VRegsOffset()))
@@ -389,6 +396,12 @@
#define THREAD_CHECKPOINT_REQUEST 2
ADD_TEST_EQ(THREAD_CHECKPOINT_REQUEST, static_cast<int32_t>(art::kCheckpointRequest))
+#define JIT_CHECK_OSR -1
+ADD_TEST_EQ(JIT_CHECK_OSR, static_cast<int32_t>(art::jit::kJitCheckForOSR))
+
+#define JIT_HOTNESS_DISABLE -2
+ADD_TEST_EQ(JIT_HOTNESS_DISABLE, static_cast<int32_t>(art::jit::kJitHotnessDisabled))
+
#if defined(__cplusplus)
} // End of CheckAsmSupportOffsets.
#endif
diff --git a/runtime/instrumentation.h b/runtime/instrumentation.h
index d07f47b..a4c3d41 100644
--- a/runtime/instrumentation.h
+++ b/runtime/instrumentation.h
@@ -303,7 +303,8 @@
bool NonJitProfilingActive() const SHARED_REQUIRES(Locks::mutator_lock_) {
return have_dex_pc_listeners_ || have_method_exit_listeners_ ||
have_field_read_listeners_ || have_field_write_listeners_ ||
- have_exception_caught_listeners_ || have_method_unwind_listeners_;
+ have_exception_caught_listeners_ || have_method_unwind_listeners_ ||
+ have_branch_listeners_;
}
// Inform listeners that a method has been entered. A dex PC is provided as we may install
diff --git a/runtime/interpreter/interpreter_goto_table_impl.cc b/runtime/interpreter/interpreter_goto_table_impl.cc
index 12d6fdc..ce698fb 100644
--- a/runtime/interpreter/interpreter_goto_table_impl.cc
+++ b/runtime/interpreter/interpreter_goto_table_impl.cc
@@ -22,6 +22,7 @@
#include "experimental_flags.h"
#include "interpreter_common.h"
#include "jit/jit.h"
+#include "jit/jit_instrumentation.h"
#include "safe_math.h"
#include <memory> // std::unique_ptr
@@ -64,15 +65,20 @@
currentHandlersTable = handlersTable[ \
Runtime::Current()->GetInstrumentation()->GetInterpreterHandlerTable()]
-#define BRANCH_INSTRUMENTATION(offset) \
- do { \
- ArtMethod* method = shadow_frame.GetMethod(); \
- instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); \
- instrumentation->Branch(self, method, dex_pc, offset); \
- JValue result; \
- if (jit::Jit::MaybeDoOnStackReplacement(self, method, dex_pc, offset, &result)) { \
- return result; \
- } \
+#define BRANCH_INSTRUMENTATION(offset) \
+ do { \
+ instrumentation->Branch(self, method, dex_pc, offset); \
+ JValue result; \
+ if (jit::Jit::MaybeDoOnStackReplacement(self, method, dex_pc, offset, &result)) { \
+ return result; \
+ } \
+ } while (false)
+
+#define HOTNESS_UPDATE() \
+ do { \
+ if (jit_instrumentation_cache != nullptr) { \
+ jit_instrumentation_cache->AddSamples(self, method, 1); \
+ } \
} while (false)
#define UNREACHABLE_CODE_CHECK() \
@@ -186,6 +192,13 @@
UPDATE_HANDLER_TABLE();
std::unique_ptr<lambda::ClosureBuilder> lambda_closure_builder;
size_t lambda_captured_variable_index = 0;
+ const auto* const instrumentation = Runtime::Current()->GetInstrumentation();
+ ArtMethod* method = shadow_frame.GetMethod();
+ jit::Jit* jit = Runtime::Current()->GetJit();
+ jit::JitInstrumentationCache* jit_instrumentation_cache = nullptr;
+ if (jit != nullptr) {
+ jit_instrumentation_cache = jit->GetInstrumentationCache();
+ }
// Jump to first instruction.
ADVANCE(0);
@@ -277,7 +290,6 @@
JValue result;
self->AllowThreadSuspension();
HANDLE_MONITOR_CHECKS();
- instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
if (UNLIKELY(instrumentation->HasMethodExitListeners())) {
instrumentation->MethodExitEvent(self, shadow_frame.GetThisObject(code_item->ins_size_),
shadow_frame.GetMethod(), dex_pc,
@@ -292,7 +304,6 @@
JValue result;
self->AllowThreadSuspension();
HANDLE_MONITOR_CHECKS();
- instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
if (UNLIKELY(instrumentation->HasMethodExitListeners())) {
instrumentation->MethodExitEvent(self, shadow_frame.GetThisObject(code_item->ins_size_),
shadow_frame.GetMethod(), dex_pc,
@@ -308,7 +319,6 @@
result.SetI(shadow_frame.GetVReg(inst->VRegA_11x(inst_data)));
self->AllowThreadSuspension();
HANDLE_MONITOR_CHECKS();
- instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
if (UNLIKELY(instrumentation->HasMethodExitListeners())) {
instrumentation->MethodExitEvent(self, shadow_frame.GetThisObject(code_item->ins_size_),
shadow_frame.GetMethod(), dex_pc,
@@ -323,7 +333,6 @@
result.SetJ(shadow_frame.GetVRegLong(inst->VRegA_11x(inst_data)));
self->AllowThreadSuspension();
HANDLE_MONITOR_CHECKS();
- instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
if (UNLIKELY(instrumentation->HasMethodExitListeners())) {
instrumentation->MethodExitEvent(self, shadow_frame.GetThisObject(code_item->ins_size_),
shadow_frame.GetMethod(), dex_pc,
@@ -359,7 +368,6 @@
}
}
result.SetL(obj_result);
- instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
if (UNLIKELY(instrumentation->HasMethodExitListeners())) {
instrumentation->MethodExitEvent(self, shadow_frame.GetThisObject(code_item->ins_size_),
shadow_frame.GetMethod(), dex_pc,
@@ -630,6 +638,7 @@
int8_t offset = inst->VRegA_10t(inst_data);
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -643,6 +652,7 @@
int16_t offset = inst->VRegA_20t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -656,6 +666,7 @@
int32_t offset = inst->VRegA_30t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -669,6 +680,7 @@
int32_t offset = DoPackedSwitch(inst, shadow_frame, inst_data);
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -682,6 +694,7 @@
int32_t offset = DoSparseSwitch(inst, shadow_frame, inst_data);
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -785,6 +798,7 @@
int16_t offset = inst->VRegC_22t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -804,6 +818,7 @@
int16_t offset = inst->VRegC_22t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -823,6 +838,7 @@
int16_t offset = inst->VRegC_22t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -842,6 +858,7 @@
int16_t offset = inst->VRegC_22t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -861,6 +878,7 @@
int16_t offset = inst->VRegC_22t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -880,6 +898,7 @@
int16_t offset = inst->VRegC_22t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -898,6 +917,7 @@
int16_t offset = inst->VRegB_21t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -916,6 +936,7 @@
int16_t offset = inst->VRegB_21t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -934,6 +955,7 @@
int16_t offset = inst->VRegB_21t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -952,6 +974,7 @@
int16_t offset = inst->VRegB_21t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -970,6 +993,7 @@
int16_t offset = inst->VRegB_21t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -988,6 +1012,7 @@
int16_t offset = inst->VRegB_21t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
if (UNLIKELY(self->TestAllFlags())) {
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
@@ -2558,7 +2583,6 @@
self->CheckSuspend();
UPDATE_HANDLER_TABLE();
}
- instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
uint32_t found_dex_pc = FindNextInstructionFollowingException(self, shadow_frame, dex_pc,
instrumentation);
if (found_dex_pc == DexFile::kDexNoIndex) {
@@ -2579,8 +2603,6 @@
// a constant condition that would remove the "if" statement so the test is free.
#define INSTRUMENTATION_INSTRUCTION_HANDLER(o, code, n, f, r, i, a, v) \
alt_op_##code: { \
- Runtime* const runtime = Runtime::Current(); \
- const instrumentation::Instrumentation* instrumentation = runtime->GetInstrumentation(); \
if (UNLIKELY(instrumentation->HasDexPcListeners())) { \
Object* this_object = shadow_frame.GetThisObject(code_item->ins_size_); \
instrumentation->DexPcMovedEvent(self, this_object, shadow_frame.GetMethod(), dex_pc); \
diff --git a/runtime/interpreter/interpreter_switch_impl.cc b/runtime/interpreter/interpreter_switch_impl.cc
index 43889c6..442e191 100644
--- a/runtime/interpreter/interpreter_switch_impl.cc
+++ b/runtime/interpreter/interpreter_switch_impl.cc
@@ -18,6 +18,7 @@
#include "experimental_flags.h"
#include "interpreter_common.h"
#include "jit/jit.h"
+#include "jit/jit_instrumentation.h"
#include "safe_math.h"
#include <memory> // std::unique_ptr
@@ -73,7 +74,6 @@
#define BRANCH_INSTRUMENTATION(offset) \
do { \
- ArtMethod* method = shadow_frame.GetMethod(); \
instrumentation->Branch(self, method, dex_pc, offset); \
JValue result; \
if (jit::Jit::MaybeDoOnStackReplacement(self, method, dex_pc, offset, &result)) { \
@@ -85,6 +85,13 @@
} \
} while (false)
+#define HOTNESS_UPDATE() \
+ do { \
+ if (jit_instrumentation_cache != nullptr) { \
+ jit_instrumentation_cache->AddSamples(self, method, 1); \
+ } \
+ } while (false)
+
static bool IsExperimentalInstructionEnabled(const Instruction *inst) {
DCHECK(inst->IsExperimental());
return Runtime::Current()->AreExperimentalFlagsEnabled(ExperimentalFlags::kLambdas);
@@ -106,6 +113,12 @@
const uint16_t* const insns = code_item->insns_;
const Instruction* inst = Instruction::At(insns + dex_pc);
uint16_t inst_data;
+ ArtMethod* method = shadow_frame.GetMethod();
+ jit::Jit* jit = Runtime::Current()->GetJit();
+ jit::JitInstrumentationCache* jit_instrumentation_cache = nullptr;
+ if (jit != nullptr) {
+ jit_instrumentation_cache = jit->GetInstrumentationCache();
+ }
// TODO: collapse capture-variable+create-lambda into one opcode, then we won't need
// to keep this live for the scope of the entire function call.
@@ -574,6 +587,7 @@
int8_t offset = inst->VRegA_10t(inst_data);
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
@@ -584,6 +598,7 @@
int16_t offset = inst->VRegA_20t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
@@ -594,6 +609,7 @@
int32_t offset = inst->VRegA_30t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
@@ -604,6 +620,7 @@
int32_t offset = DoPackedSwitch(inst, shadow_frame, inst_data);
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
@@ -614,6 +631,7 @@
int32_t offset = DoSparseSwitch(inst, shadow_frame, inst_data);
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
@@ -718,6 +736,7 @@
int16_t offset = inst->VRegC_22t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
@@ -734,6 +753,7 @@
int16_t offset = inst->VRegC_22t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
@@ -750,6 +770,7 @@
int16_t offset = inst->VRegC_22t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
@@ -766,6 +787,7 @@
int16_t offset = inst->VRegC_22t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
@@ -782,6 +804,7 @@
int16_t offset = inst->VRegC_22t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
@@ -798,6 +821,7 @@
int16_t offset = inst->VRegC_22t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
@@ -813,6 +837,7 @@
int16_t offset = inst->VRegB_21t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
@@ -828,6 +853,7 @@
int16_t offset = inst->VRegB_21t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
@@ -843,6 +869,7 @@
int16_t offset = inst->VRegB_21t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
@@ -858,6 +885,7 @@
int16_t offset = inst->VRegB_21t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
@@ -873,6 +901,7 @@
int16_t offset = inst->VRegB_21t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
@@ -888,6 +917,7 @@
int16_t offset = inst->VRegB_21t();
BRANCH_INSTRUMENTATION(offset);
if (IsBackwardBranch(offset)) {
+ HOTNESS_UPDATE();
self->AllowThreadSuspension();
}
inst = inst->RelativeAt(offset);
diff --git a/runtime/interpreter/mterp/arm/bincmp.S b/runtime/interpreter/mterp/arm/bincmp.S
index cfad714..8fad42f 100644
--- a/runtime/interpreter/mterp/arm/bincmp.S
+++ b/runtime/interpreter/mterp/arm/bincmp.S
@@ -1,7 +1,6 @@
/*
- * Generic two-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic two-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* For: if-eq, if-ne, if-lt, if-ge, if-gt, if-le
*/
@@ -9,23 +8,12 @@
mov r1, rINST, lsr #12 @ r1<- B
ubfx r0, rINST, #8, #4 @ r0<- A
GET_VREG r3, r1 @ r3<- vB
- GET_VREG r2, r0 @ r2<- vA
+ GET_VREG r0, r0 @ r0<- vA
FETCH_S rINST, 1 @ rINST<- branch offset, in code units
- cmp r2, r3 @ compare (vA, vB)
- mov${revcmp} rINST, #2
-#if MTERP_PROFILE_BRANCHES
- @ TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
-#endif
- adds r2, rINST, rINST @ convert to bytes, check sign
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- FETCH_ADVANCE_INST_RB r2 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
+ cmp r0, r3 @ compare (vA, vB)
+ b${condition} MterpCommonTakenBranchNoFlags
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ beq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
diff --git a/runtime/interpreter/mterp/arm/entry.S b/runtime/interpreter/mterp/arm/entry.S
index 981c036..a6b131d 100644
--- a/runtime/interpreter/mterp/arm/entry.S
+++ b/runtime/interpreter/mterp/arm/entry.S
@@ -33,10 +33,8 @@
ExecuteMterpImpl:
.fnstart
- .save {r4-r10,fp,lr}
- stmfd sp!, {r4-r10,fp,lr} @ save 9 regs
- .pad #4
- sub sp, sp, #4 @ align 64
+ .save {r3-r10,fp,lr}
+ stmfd sp!, {r3-r10,fp,lr} @ save 10 regs, (r3 just to align 64)
/* Remember the return register */
str r3, [r2, #SHADOWFRAME_RESULT_REGISTER_OFFSET]
@@ -57,6 +55,12 @@
/* Starting ibase */
ldr rIBASE, [rSELF, #THREAD_CURRENT_IBASE_OFFSET]
+ /* Set up for backwards branches & osr profiling */
+ ldr r0, [rFP, #OFF_FP_METHOD]
+ add r1, rFP, #OFF_FP_SHADOWFRAME
+ bl MterpSetUpHotnessCountdown
+ mov rPROFILE, r0 @ Starting hotness countdown to rPROFILE
+
/* start executing the instruction at rPC */
FETCH_INST @ load rINST from rPC
GET_INST_OPCODE ip @ extract opcode from rINST
diff --git a/runtime/interpreter/mterp/arm/footer.S b/runtime/interpreter/mterp/arm/footer.S
index 3456a75..62e573a 100644
--- a/runtime/interpreter/mterp/arm/footer.S
+++ b/runtime/interpreter/mterp/arm/footer.S
@@ -114,21 +114,117 @@
/* NOTE: no fallthrough */
/*
- * Check for suspend check request. Assumes rINST already loaded, rPC advanced and
- * still needs to get the opcode and branch to it, and flags are in lr.
+ * Common handling for branches with support for Jit profiling.
+ * On entry:
+ * rINST <= signed offset
+ * rPROFILE <= signed hotness countdown (expanded to 32 bits)
+ * condition bits <= set to establish sign of offset (use "NoFlags" entry if not)
+ *
+ * We have quite a few different cases for branch profiling, OSR detection and
+ * suspend check support here.
+ *
+ * Taken backward branches:
+ * If profiling active, do hotness countdown and report if we hit zero.
+ * If in osr check mode, see if our target is a compiled loop header entry and do OSR if so.
+ * Is there a pending suspend request? If so, suspend.
+ *
+ * Taken forward branches and not-taken backward branches:
+ * If in osr check mode, see if our target is a compiled loop header entry and do OSR if so.
+ *
+ * Our most common case is expected to be a taken backward branch with active jit profiling,
+ * but no full OSR check and no pending suspend request.
+ * Next most common case is not-taken branch with no full OSR check.
+ *
*/
-MterpCheckSuspendAndContinue:
- ldr rIBASE, [rSELF, #THREAD_CURRENT_IBASE_OFFSET] @ refresh rIBASE
+MterpCommonTakenBranchNoFlags:
+ cmp rINST, #0
+MterpCommonTakenBranch:
+ bgt .L_forward_branch @ don't add forward branches to hotness
+/*
+ * We need to subtract 1 from positive values and we should not see 0 here,
+ * so we may use the result of the comparison with -1.
+ */
+#if JIT_CHECK_OSR != -1
+# error "JIT_CHECK_OSR must be -1."
+#endif
+ cmp rPROFILE, #JIT_CHECK_OSR
+ beq .L_osr_check
+ subgts rPROFILE, #1
+ beq .L_add_batch @ counted down to zero - report
+.L_resume_backward_branch:
+ ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
+ REFRESH_IBASE
+ add r2, rINST, rINST @ r2<- byte offset
+ FETCH_ADVANCE_INST_RB r2 @ update rPC, load rINST
ands lr, #(THREAD_SUSPEND_REQUEST | THREAD_CHECKPOINT_REQUEST)
- bne 1f
+ bne .L_suspend_request_pending
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
-1:
+
+.L_suspend_request_pending:
EXPORT_PC
mov r0, rSELF
bl MterpSuspendCheck @ (self)
cmp r0, #0
bne MterpFallback
+ REFRESH_IBASE @ might have changed during suspend
+ GET_INST_OPCODE ip @ extract opcode from rINST
+ GOTO_OPCODE ip @ jump to next instruction
+
+.L_no_count_backwards:
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ bne .L_resume_backward_branch
+.L_osr_check:
+ mov r0, rSELF
+ add r1, rFP, #OFF_FP_SHADOWFRAME
+ mov r2, rINST
+ EXPORT_PC
+ bl MterpMaybeDoOnStackReplacement @ (self, shadow_frame, offset)
+ cmp r0, #0
+ bne MterpOnStackReplacement
+ b .L_resume_backward_branch
+
+.L_forward_branch:
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ beq .L_check_osr_forward
+.L_resume_forward_branch:
+ add r2, rINST, rINST @ r2<- byte offset
+ FETCH_ADVANCE_INST_RB r2 @ update rPC, load rINST
+ GET_INST_OPCODE ip @ extract opcode from rINST
+ GOTO_OPCODE ip @ jump to next instruction
+
+.L_check_osr_forward:
+ mov r0, rSELF
+ add r1, rFP, #OFF_FP_SHADOWFRAME
+ mov r2, rINST
+ EXPORT_PC
+ bl MterpMaybeDoOnStackReplacement @ (self, shadow_frame, offset)
+ cmp r0, #0
+ bne MterpOnStackReplacement
+ b .L_resume_forward_branch
+
+.L_add_batch:
+ add r1, rFP, #OFF_FP_SHADOWFRAME
+ strh rPROFILE, [r1, #SHADOWFRAME_HOTNESS_COUNTDOWN_OFFSET]
+ ldr r0, [rFP, #OFF_FP_METHOD]
+ mov r2, rSELF
+ bl MterpAddHotnessBatch @ (method, shadow_frame, self)
+ mov rPROFILE, r0 @ restore new hotness countdown to rPROFILE
+ b .L_no_count_backwards
+
+/*
+ * Entered from the conditional branch handlers when OSR check request active on
+ * not-taken path. All Dalvik not-taken conditional branch offsets are 2.
+ */
+.L_check_not_taken_osr:
+ mov r0, rSELF
+ add r1, rFP, #OFF_FP_SHADOWFRAME
+ mov r2, #2
+ EXPORT_PC
+ bl MterpMaybeDoOnStackReplacement @ (self, shadow_frame, offset)
+ cmp r0, #0
+ bne MterpOnStackReplacement
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
@@ -176,9 +272,27 @@
str r1, [r2, #4]
mov r0, #1 @ signal return to caller.
MterpDone:
- add sp, sp, #4 @ un-align 64
- ldmfd sp!, {r4-r10,fp,pc} @ restore 9 regs and return
+/*
+ * At this point, we expect rPROFILE to be non-zero. If negative, hotness is disabled or we're
+ * checking for OSR. If greater than zero, we might have unreported hotness to register
+ * (the difference between the ending rPROFILE and the cached hotness counter). rPROFILE
+ * should only reach zero immediately after a hotness decrement, and is then reset to either
+ * a negative special state or the new non-zero countdown value.
+ */
+ cmp rPROFILE, #0
+ bgt MterpProfileActive @ if > 0, we may have some counts to report.
+ ldmfd sp!, {r3-r10,fp,pc} @ restore 10 regs and return
+MterpProfileActive:
+ mov rINST, r0 @ stash return value
+ /* Report cached hotness counts */
+ ldr r0, [rFP, #OFF_FP_METHOD]
+ add r1, rFP, #OFF_FP_SHADOWFRAME
+ mov r2, rSELF
+ strh rPROFILE, [r1, #SHADOWFRAME_HOTNESS_COUNTDOWN_OFFSET]
+ bl MterpAddHotnessBatch @ (method, shadow_frame, self)
+ mov r0, rINST @ restore return value
+ ldmfd sp!, {r3-r10,fp,pc} @ restore 10 regs and return
.fnend
.size ExecuteMterpImpl, .-ExecuteMterpImpl
diff --git a/runtime/interpreter/mterp/arm/header.S b/runtime/interpreter/mterp/arm/header.S
index 298af8a..039bcbe 100644
--- a/runtime/interpreter/mterp/arm/header.S
+++ b/runtime/interpreter/mterp/arm/header.S
@@ -72,7 +72,8 @@
r6 rSELF self (Thread) pointer
r7 rINST first 16-bit code unit of current instruction
r8 rIBASE interpreted instruction base pointer, used for computed goto
- r11 rREFS base of object references in shadow frame (ideally, we'll get rid of this later).
+ r10 rPROFILE branch profiling countdown
+ r11 rREFS base of object references in shadow frame (ideally, we'll get rid of this later).
Macros are provided for common operations. Each macro MUST emit only
one instruction to make instruction-counting easier. They MUST NOT alter
@@ -90,12 +91,13 @@
/* During bringup, we'll use the shadow frame model instead of rFP */
/* single-purpose registers, given names for clarity */
-#define rPC r4
-#define rFP r5
-#define rSELF r6
-#define rINST r7
-#define rIBASE r8
-#define rREFS r11
+#define rPC r4
+#define rFP r5
+#define rSELF r6
+#define rINST r7
+#define rIBASE r8
+#define rPROFILE r10
+#define rREFS r11
/*
* Instead of holding a pointer to the shadow frame, we keep rFP at the base of the vregs. So,
@@ -109,7 +111,7 @@
#define OFF_FP_RESULT_REGISTER OFF_FP(SHADOWFRAME_RESULT_REGISTER_OFFSET)
#define OFF_FP_DEX_PC_PTR OFF_FP(SHADOWFRAME_DEX_PC_PTR_OFFSET)
#define OFF_FP_CODE_ITEM OFF_FP(SHADOWFRAME_CODE_ITEM_OFFSET)
-#define OFF_FP_SHADOWFRAME (-SHADOWFRAME_VREGS_OFFSET)
+#define OFF_FP_SHADOWFRAME OFF_FP(0)
/*
* "export" the PC to dex_pc field in the shadow frame, f/b/o future exception objects. Must
diff --git a/runtime/interpreter/mterp/arm/op_cmp_long.S b/runtime/interpreter/mterp/arm/op_cmp_long.S
index e57b19c..6626ff0 100644
--- a/runtime/interpreter/mterp/arm/op_cmp_long.S
+++ b/runtime/interpreter/mterp/arm/op_cmp_long.S
@@ -1,22 +1,6 @@
/*
* Compare two 64-bit values. Puts 0, 1, or -1 into the destination
* register based on the results of the comparison.
- *
- * We load the full values with LDM, but in practice many values could
- * be resolved by only looking at the high word. This could be made
- * faster or slower by splitting the LDM into a pair of LDRs.
- *
- * If we just wanted to set condition flags, we could do this:
- * subs ip, r0, r2
- * sbcs ip, r1, r3
- * subeqs ip, r0, r2
- * Leaving { <0, 0, >0 } in ip. However, we have to set it to a specific
- * integer value, which we can do with 2 conditional mov/mvn instructions
- * (set 1, set -1; if they're equal we already have 0 in ip), giving
- * us a constant 5-cycle path plus a branch at the end to the
- * instruction epilogue code. The multi-compare approach below needs
- * 2 or 3 cycles + branch if the high word doesn't match, 6 + branch
- * in the worst case (the 64-bit values are equal).
*/
/* cmp-long vAA, vBB, vCC */
FETCH r0, 1 @ r0<- CCBB
@@ -27,30 +11,13 @@
VREG_INDEX_TO_ADDR r3, r3 @ r3<- &fp[CC]
ldmia r2, {r0-r1} @ r0/r1<- vBB/vBB+1
ldmia r3, {r2-r3} @ r2/r3<- vCC/vCC+1
- cmp r1, r3 @ compare (vBB+1, vCC+1)
- blt .L${opcode}_less @ signed compare on high part
- bgt .L${opcode}_greater
- subs r1, r0, r2 @ r1<- r0 - r2
- bhi .L${opcode}_greater @ unsigned compare on low part
- bne .L${opcode}_less
- b .L${opcode}_finish @ equal; r1 already holds 0
-%break
-
-.L${opcode}_less:
- mvn r1, #0 @ r1<- -1
- @ Want to cond code the next mov so we can avoid branch, but don't see it;
- @ instead, we just replicate the tail end.
+ cmp r0, r2
+ sbcs ip, r1, r3 @ Sets correct CCs for checking LT (but not EQ/NE)
+ mov ip, #0
+ mvnlt ip, #0 @ -1
+ cmpeq r0, r2 @ For correct EQ/NE, we may need to repeat the first CMP
+ orrne ip, #1
FETCH_ADVANCE_INST 2 @ advance rPC, load rINST
- SET_VREG r1, r9 @ vAA<- r1
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-
-.L${opcode}_greater:
- mov r1, #1 @ r1<- 1
- @ fall through to _finish
-
-.L${opcode}_finish:
- FETCH_ADVANCE_INST 2 @ advance rPC, load rINST
- SET_VREG r1, r9 @ vAA<- r1
+ SET_VREG ip, r9 @ vAA<- ip
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
diff --git a/runtime/interpreter/mterp/arm/op_goto.S b/runtime/interpreter/mterp/arm/op_goto.S
index 6861950..aa42dfd 100644
--- a/runtime/interpreter/mterp/arm/op_goto.S
+++ b/runtime/interpreter/mterp/arm/op_goto.S
@@ -5,32 +5,5 @@
* double to get a byte offset.
*/
/* goto +AA */
- /* tuning: use sbfx for 6t2+ targets */
-#if MTERP_PROFILE_BRANCHES
- mov r0, rINST, lsl #16 @ r0<- AAxx0000
- movs rINST, r0, asr #24 @ rINST<- ssssssAA (sign-extended)
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r2, rINST, rINST @ r2<- byte offset, set flags
- FETCH_ADVANCE_INST_RB r2 @ update rPC, load rINST
- @ If backwards branch refresh rIBASE
- bmi MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#else
- mov r0, rINST, lsl #16 @ r0<- AAxx0000
- movs rINST, r0, asr #24 @ rINST<- ssssssAA (sign-extended)
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r2, rINST, rINST @ r2<- byte offset, set flags
- FETCH_ADVANCE_INST_RB r2 @ update rPC, load rINST
- @ If backwards branch refresh rIBASE
- bmi MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#endif
+ sbfx rINST, rINST, #8, #8 @ rINST<- ssssssAA (sign-extended)
+ b MterpCommonTakenBranchNoFlags
diff --git a/runtime/interpreter/mterp/arm/op_goto_16.S b/runtime/interpreter/mterp/arm/op_goto_16.S
index 91639ca..12a6bc0 100644
--- a/runtime/interpreter/mterp/arm/op_goto_16.S
+++ b/runtime/interpreter/mterp/arm/op_goto_16.S
@@ -5,27 +5,5 @@
* double to get a byte offset.
*/
/* goto/16 +AAAA */
-#if MTERP_PROFILE_BRANCHES
FETCH_S rINST, 1 @ rINST<- ssssAAAA (sign-extended)
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r1, rINST, rINST @ r1<- byte offset, flags set
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#else
- FETCH_S rINST, 1 @ rINST<- ssssAAAA (sign-extended)
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r1, rINST, rINST @ r1<- byte offset, flags set
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#endif
+ b MterpCommonTakenBranchNoFlags
diff --git a/runtime/interpreter/mterp/arm/op_goto_32.S b/runtime/interpreter/mterp/arm/op_goto_32.S
index e730b52..7325a1c 100644
--- a/runtime/interpreter/mterp/arm/op_goto_32.S
+++ b/runtime/interpreter/mterp/arm/op_goto_32.S
@@ -10,31 +10,7 @@
* offset to byte offset.
*/
/* goto/32 +AAAAAAAA */
-#if MTERP_PROFILE_BRANCHES
FETCH r0, 1 @ r0<- aaaa (lo)
- FETCH r1, 2 @ r1<- AAAA (hi)
- orr rINST, r0, r1, lsl #16 @ rINST<- AAAAaaaa
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r1, rINST, rINST @ r1<- byte offset
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- ble MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#else
- FETCH r0, 1 @ r0<- aaaa (lo)
- FETCH r1, 2 @ r1<- AAAA (hi)
- orr rINST, r0, r1, lsl #16 @ rINST<- AAAAaaaa
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r1, rINST, rINST @ r1<- byte offset
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- ble MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#endif
+ FETCH r3, 2 @ r1<- AAAA (hi)
+ orrs rINST, r0, r3, lsl #16 @ rINST<- AAAAaaaa
+ b MterpCommonTakenBranch
diff --git a/runtime/interpreter/mterp/arm/op_if_eq.S b/runtime/interpreter/mterp/arm/op_if_eq.S
index 5685686..b8b6a6e 100644
--- a/runtime/interpreter/mterp/arm/op_if_eq.S
+++ b/runtime/interpreter/mterp/arm/op_if_eq.S
@@ -1 +1 @@
-%include "arm/bincmp.S" { "revcmp":"ne" }
+%include "arm/bincmp.S" { "condition":"eq" }
diff --git a/runtime/interpreter/mterp/arm/op_if_eqz.S b/runtime/interpreter/mterp/arm/op_if_eqz.S
index 2a9c0f9..7012f61 100644
--- a/runtime/interpreter/mterp/arm/op_if_eqz.S
+++ b/runtime/interpreter/mterp/arm/op_if_eqz.S
@@ -1 +1 @@
-%include "arm/zcmp.S" { "revcmp":"ne" }
+%include "arm/zcmp.S" { "condition":"eq" }
diff --git a/runtime/interpreter/mterp/arm/op_if_ge.S b/runtime/interpreter/mterp/arm/op_if_ge.S
index 60a0307..eb29e63 100644
--- a/runtime/interpreter/mterp/arm/op_if_ge.S
+++ b/runtime/interpreter/mterp/arm/op_if_ge.S
@@ -1 +1 @@
-%include "arm/bincmp.S" { "revcmp":"lt" }
+%include "arm/bincmp.S" { "condition":"ge" }
diff --git a/runtime/interpreter/mterp/arm/op_if_gez.S b/runtime/interpreter/mterp/arm/op_if_gez.S
index 981cdec..d9da374 100644
--- a/runtime/interpreter/mterp/arm/op_if_gez.S
+++ b/runtime/interpreter/mterp/arm/op_if_gez.S
@@ -1 +1 @@
-%include "arm/zcmp.S" { "revcmp":"lt" }
+%include "arm/zcmp.S" { "condition":"ge" }
diff --git a/runtime/interpreter/mterp/arm/op_if_gt.S b/runtime/interpreter/mterp/arm/op_if_gt.S
index ca50cd7..a35eab8 100644
--- a/runtime/interpreter/mterp/arm/op_if_gt.S
+++ b/runtime/interpreter/mterp/arm/op_if_gt.S
@@ -1 +1 @@
-%include "arm/bincmp.S" { "revcmp":"le" }
+%include "arm/bincmp.S" { "condition":"gt" }
diff --git a/runtime/interpreter/mterp/arm/op_if_gtz.S b/runtime/interpreter/mterp/arm/op_if_gtz.S
index c621812..4ef4d8e 100644
--- a/runtime/interpreter/mterp/arm/op_if_gtz.S
+++ b/runtime/interpreter/mterp/arm/op_if_gtz.S
@@ -1 +1 @@
-%include "arm/zcmp.S" { "revcmp":"le" }
+%include "arm/zcmp.S" { "condition":"gt" }
diff --git a/runtime/interpreter/mterp/arm/op_if_le.S b/runtime/interpreter/mterp/arm/op_if_le.S
index 7e060f2..c7c31bc 100644
--- a/runtime/interpreter/mterp/arm/op_if_le.S
+++ b/runtime/interpreter/mterp/arm/op_if_le.S
@@ -1 +1 @@
-%include "arm/bincmp.S" { "revcmp":"gt" }
+%include "arm/bincmp.S" { "condition":"le" }
diff --git a/runtime/interpreter/mterp/arm/op_if_lez.S b/runtime/interpreter/mterp/arm/op_if_lez.S
index f92be23..9fbf6c9 100644
--- a/runtime/interpreter/mterp/arm/op_if_lez.S
+++ b/runtime/interpreter/mterp/arm/op_if_lez.S
@@ -1 +1 @@
-%include "arm/zcmp.S" { "revcmp":"gt" }
+%include "arm/zcmp.S" { "condition":"le" }
diff --git a/runtime/interpreter/mterp/arm/op_if_lt.S b/runtime/interpreter/mterp/arm/op_if_lt.S
index 213344d..9469fbb 100644
--- a/runtime/interpreter/mterp/arm/op_if_lt.S
+++ b/runtime/interpreter/mterp/arm/op_if_lt.S
@@ -1 +1 @@
-%include "arm/bincmp.S" { "revcmp":"ge" }
+%include "arm/bincmp.S" { "condition":"lt" }
diff --git a/runtime/interpreter/mterp/arm/op_if_ltz.S b/runtime/interpreter/mterp/arm/op_if_ltz.S
index dfd4e44..a4fc1b8 100644
--- a/runtime/interpreter/mterp/arm/op_if_ltz.S
+++ b/runtime/interpreter/mterp/arm/op_if_ltz.S
@@ -1 +1 @@
-%include "arm/zcmp.S" { "revcmp":"ge" }
+%include "arm/zcmp.S" { "condition":"lt" }
diff --git a/runtime/interpreter/mterp/arm/op_if_ne.S b/runtime/interpreter/mterp/arm/op_if_ne.S
index 4a58b4a..c945331 100644
--- a/runtime/interpreter/mterp/arm/op_if_ne.S
+++ b/runtime/interpreter/mterp/arm/op_if_ne.S
@@ -1 +1 @@
-%include "arm/bincmp.S" { "revcmp":"eq" }
+%include "arm/bincmp.S" { "condition":"ne" }
diff --git a/runtime/interpreter/mterp/arm/op_if_nez.S b/runtime/interpreter/mterp/arm/op_if_nez.S
index d864ef4..2d81fda 100644
--- a/runtime/interpreter/mterp/arm/op_if_nez.S
+++ b/runtime/interpreter/mterp/arm/op_if_nez.S
@@ -1 +1 @@
-%include "arm/zcmp.S" { "revcmp":"eq" }
+%include "arm/zcmp.S" { "condition":"ne" }
diff --git a/runtime/interpreter/mterp/arm/op_mul_long.S b/runtime/interpreter/mterp/arm/op_mul_long.S
index 8f40f19..a13c803 100644
--- a/runtime/interpreter/mterp/arm/op_mul_long.S
+++ b/runtime/interpreter/mterp/arm/op_mul_long.S
@@ -24,13 +24,13 @@
VREG_INDEX_TO_ADDR r3, r3 @ r3<- &fp[CC]
ldmia r2, {r0-r1} @ r0/r1<- vBB/vBB+1
ldmia r3, {r2-r3} @ r2/r3<- vCC/vCC+1
- mul ip, r2, r1 @ ip<- ZxW
- umull r9, r10, r2, r0 @ r9/r10 <- ZxX
- mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
+ mul ip, r2, r1 @ ip<- ZxW
+ umull r1, lr, r2, r0 @ r1/lr <- ZxX
+ mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
mov r0, rINST, lsr #8 @ r0<- AA
- add r10, r2, r10 @ r10<- r10 + low(ZxW + (YxX))
+ add r2, r2, lr @ r2<- lr + low(ZxW + (YxX))
VREG_INDEX_TO_ADDR r0, r0 @ r0<- &fp[AA]
FETCH_ADVANCE_INST 2 @ advance rPC, load rINST
GET_INST_OPCODE ip @ extract opcode from rINST
- stmia r0, {r9-r10} @ vAA/vAA+1<- r9/r10
+ stmia r0, {r1-r2 } @ vAA/vAA+1<- r1/r2
GOTO_OPCODE ip @ jump to next instruction
diff --git a/runtime/interpreter/mterp/arm/op_mul_long_2addr.S b/runtime/interpreter/mterp/arm/op_mul_long_2addr.S
index 7ef24c5..4c1f058 100644
--- a/runtime/interpreter/mterp/arm/op_mul_long_2addr.S
+++ b/runtime/interpreter/mterp/arm/op_mul_long_2addr.S
@@ -13,12 +13,12 @@
VREG_INDEX_TO_ADDR rINST, r9 @ rINST<- &fp[A]
ldmia r1, {r2-r3} @ r2/r3<- vBB/vBB+1
ldmia rINST, {r0-r1} @ r0/r1<- vAA/vAA+1
- mul ip, r2, r1 @ ip<- ZxW
- umull r9, r10, r2, r0 @ r9/r10 <- ZxX
- mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
+ mul ip, r2, r1 @ ip<- ZxW
+ umull r1, lr, r2, r0 @ r1/lr <- ZxX
+ mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
mov r0, rINST @ r0<- &fp[A] (free up rINST)
FETCH_ADVANCE_INST 1 @ advance rPC, load rINST
- add r10, r2, r10 @ r10<- r10 + low(ZxW + (YxX))
+ add r2, r2, lr @ r2<- r2 + low(ZxW + (YxX))
GET_INST_OPCODE ip @ extract opcode from rINST
- stmia r0, {r9-r10} @ vAA/vAA+1<- r9/r10
+ stmia r0, {r1-r2} @ vAA/vAA+1<- r1/r2
GOTO_OPCODE ip @ jump to next instruction
diff --git a/runtime/interpreter/mterp/arm/op_packed_switch.S b/runtime/interpreter/mterp/arm/op_packed_switch.S
index 4c369cb..412c58f 100644
--- a/runtime/interpreter/mterp/arm/op_packed_switch.S
+++ b/runtime/interpreter/mterp/arm/op_packed_switch.S
@@ -9,7 +9,6 @@
* for: packed-switch, sparse-switch
*/
/* op vAA, +BBBB */
-#if MTERP_PROFILE_BRANCHES
FETCH r0, 1 @ r0<- bbbb (lo)
FETCH r1, 2 @ r1<- BBBB (hi)
mov r3, rINST, lsr #8 @ r3<- AA
@@ -17,33 +16,5 @@
GET_VREG r1, r3 @ r1<- vAA
add r0, rPC, r0, lsl #1 @ r0<- PC + BBBBbbbb*2
bl $func @ r0<- code-unit branch offset
- mov rINST, r0
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r1, rINST, rINST @ r1<- byte offset; clear V
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- ble MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#else
- FETCH r0, 1 @ r0<- bbbb (lo)
- FETCH r1, 2 @ r1<- BBBB (hi)
- mov r3, rINST, lsr #8 @ r3<- AA
- orr r0, r0, r1, lsl #16 @ r0<- BBBBbbbb
- GET_VREG r1, r3 @ r1<- vAA
- add r0, rPC, r0, lsl #1 @ r0<- PC + BBBBbbbb*2
- bl $func @ r0<- code-unit branch offset
- mov rINST, r0
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r1, rINST, rINST @ r1<- byte offset; clear V
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- ble MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#endif
+ movs rINST, r0
+ b MterpCommonTakenBranch
diff --git a/runtime/interpreter/mterp/arm/zcmp.S b/runtime/interpreter/mterp/arm/zcmp.S
index 3d7dec0..5db8b6c 100644
--- a/runtime/interpreter/mterp/arm/zcmp.S
+++ b/runtime/interpreter/mterp/arm/zcmp.S
@@ -1,29 +1,17 @@
/*
- * Generic one-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic one-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* for: if-eqz, if-nez, if-ltz, if-gez, if-gtz, if-lez
*/
/* if-cmp vAA, +BBBB */
mov r0, rINST, lsr #8 @ r0<- AA
- GET_VREG r2, r0 @ r2<- vAA
+ GET_VREG r0, r0 @ r0<- vAA
FETCH_S rINST, 1 @ rINST<- branch offset, in code units
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- cmp r2, #0 @ compare (vA, 0)
- mov${revcmp} rINST, #2
-#if MTERP_PROFILE_BRANCHES
- @ TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
-#endif
- adds r1, rINST, rINST @ convert to bytes & set flags
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
+ cmp r0, #0 @ compare (vA, 0)
+ b${condition} MterpCommonTakenBranchNoFlags
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ beq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
diff --git a/runtime/interpreter/mterp/arm64/bincmp.S b/runtime/interpreter/mterp/arm64/bincmp.S
index 2356ecb..8dd4fed 100644
--- a/runtime/interpreter/mterp/arm64/bincmp.S
+++ b/runtime/interpreter/mterp/arm64/bincmp.S
@@ -1,7 +1,6 @@
/*
- * Generic two-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic two-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* For: if-eq, if-ne, if-lt, if-ge, if-gt, if-le
*/
@@ -10,22 +9,11 @@
ubfx w0, wINST, #8, #4 // w0<- A
GET_VREG w3, w1 // w3<- vB
GET_VREG w2, w0 // w2<- vA
- FETCH_S w1, 1 // w1<- branch offset, in code units
- mov w0, #2 // Offset if branch not taken
+ FETCH_S wINST, 1 // wINST<- branch offset, in code units
cmp w2, w3 // compare (vA, vB)
- csel wINST, w1, w0, ${condition} // Branch if true, stashing result in callee save reg.
-#if MTERP_PROFILE_BRANCHES
- // TUINING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31 // Sign extend branch offset
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in xINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w2, wINST, wINST // convert to bytes, check sign
- FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
- b.mi MterpCheckSuspendAndContinue
+ b.${condition} MterpCommonTakenBranchNoFlags
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.eq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip // extract opcode from wINST
GOTO_OPCODE ip // jump to next instruction
diff --git a/runtime/interpreter/mterp/arm64/entry.S b/runtime/interpreter/mterp/arm64/entry.S
index 23e656e..9fbbbd3 100644
--- a/runtime/interpreter/mterp/arm64/entry.S
+++ b/runtime/interpreter/mterp/arm64/entry.S
@@ -31,11 +31,12 @@
ExecuteMterpImpl:
.cfi_startproc
- stp xIBASE, xREFS, [sp, #-64]!
- stp xSELF, xINST, [sp, #16]
- stp xPC, xFP, [sp, #32]
- stp fp, lr, [sp, #48]
- add fp, sp, #48
+ stp xPROFILE, x27, [sp, #-80]!
+ stp xIBASE, xREFS, [sp, #16]
+ stp xSELF, xINST, [sp, #32]
+ stp xPC, xFP, [sp, #48]
+ stp fp, lr, [sp, #64]
+ add fp, sp, #64
/* Remember the return register */
str x3, [x2, #SHADOWFRAME_RESULT_REGISTER_OFFSET]
@@ -56,6 +57,12 @@
/* Starting ibase */
ldr xIBASE, [xSELF, #THREAD_CURRENT_IBASE_OFFSET]
+ /* Set up for backwards branches & osr profiling */
+ ldr x0, [xFP, #OFF_FP_METHOD]
+ add x1, xFP, #OFF_FP_SHADOWFRAME
+ bl MterpSetUpHotnessCountdown
+ mov wPROFILE, w0 // Starting hotness countdown to xPROFILE
+
/* start executing the instruction at rPC */
FETCH_INST // load wINST from rPC
GET_INST_OPCODE ip // extract opcode from wINST
diff --git a/runtime/interpreter/mterp/arm64/footer.S b/runtime/interpreter/mterp/arm64/footer.S
index aae78de..2d3a11e 100644
--- a/runtime/interpreter/mterp/arm64/footer.S
+++ b/runtime/interpreter/mterp/arm64/footer.S
@@ -107,6 +107,107 @@
GET_INST_OPCODE ip
GOTO_OPCODE ip
/* NOTE: no fallthrough */
+/*
+ * Common handling for branches with support for Jit profiling.
+ * On entry:
+ * wINST <= signed offset
+ * wPROFILE <= signed hotness countdown (expanded to 32 bits)
+ * condition bits <= set to establish sign of offset (use "NoFlags" entry if not)
+ *
+ * We have quite a few different cases for branch profiling, OSR detection and
+ * suspend check support here.
+ *
+ * Taken backward branches:
+ * If profiling active, do hotness countdown and report if we hit zero.
+ * If in osr check mode, see if our target is a compiled loop header entry and do OSR if so.
+ * Is there a pending suspend request? If so, suspend.
+ *
+ * Taken forward branches and not-taken backward branches:
+ * If in osr check mode, see if our target is a compiled loop header entry and do OSR if so.
+ *
+ * Our most common case is expected to be a taken backward branch with active jit profiling,
+ * but no full OSR check and no pending suspend request.
+ * Next most common case is not-taken branch with no full OSR check.
+ *
+ */
+MterpCommonTakenBranchNoFlags:
+ cmp wINST, #0
+ b.gt .L_forward_branch // don't add forward branches to hotness
+ tbnz wPROFILE, #31, .L_no_count_backwards // go if negative
+ subs wPROFILE, wPROFILE, #1 // countdown
+ b.eq .L_add_batch // counted down to zero - report
+.L_resume_backward_branch:
+ ldr lr, [xSELF, #THREAD_FLAGS_OFFSET]
+ add w2, wINST, wINST // w2<- byte offset
+ FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
+ REFRESH_IBASE
+ ands lr, lr, #(THREAD_SUSPEND_REQUEST | THREAD_CHECKPOINT_REQUEST)
+ b.ne .L_suspend_request_pending
+ GET_INST_OPCODE ip // extract opcode from wINST
+ GOTO_OPCODE ip // jump to next instruction
+
+.L_suspend_request_pending:
+ EXPORT_PC
+ mov x0, xSELF
+ bl MterpSuspendCheck // (self)
+ cbnz x0, MterpFallback
+ REFRESH_IBASE // might have changed during suspend
+ GET_INST_OPCODE ip // extract opcode from wINST
+ GOTO_OPCODE ip // jump to next instruction
+
+.L_no_count_backwards:
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.ne .L_resume_backward_branch
+ mov x0, xSELF
+ add x1, xFP, #OFF_FP_SHADOWFRAME
+ mov x2, xINST
+ EXPORT_PC
+ bl MterpMaybeDoOnStackReplacement // (self, shadow_frame, offset)
+ cbnz x0, MterpOnStackReplacement
+ b .L_resume_backward_branch
+
+.L_forward_branch:
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.eq .L_check_osr_forward
+.L_resume_forward_branch:
+ add w2, wINST, wINST // w2<- byte offset
+ FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
+ GET_INST_OPCODE ip // extract opcode from wINST
+ GOTO_OPCODE ip // jump to next instruction
+
+.L_check_osr_forward:
+ mov x0, xSELF
+ add x1, xFP, #OFF_FP_SHADOWFRAME
+ mov x2, xINST
+ EXPORT_PC
+ bl MterpMaybeDoOnStackReplacement // (self, shadow_frame, offset)
+ cbnz x0, MterpOnStackReplacement
+ b .L_resume_forward_branch
+
+.L_add_batch:
+ add x1, xFP, #OFF_FP_SHADOWFRAME
+ strh wPROFILE, [x1, #SHADOWFRAME_HOTNESS_COUNTDOWN_OFFSET]
+ ldr x0, [xFP, #OFF_FP_METHOD]
+ mov x2, xSELF
+ bl MterpAddHotnessBatch // (method, shadow_frame, self)
+ mov wPROFILE, w0 // restore new hotness countdown to wPROFILE
+ b .L_no_count_backwards
+
+/*
+ * Entered from the conditional branch handlers when OSR check request active on
+ * not-taken path. All Dalvik not-taken conditional branch offsets are 2.
+ */
+.L_check_not_taken_osr:
+ mov x0, xSELF
+ add x1, xFP, #OFF_FP_SHADOWFRAME
+ mov x2, #2
+ EXPORT_PC
+ bl MterpMaybeDoOnStackReplacement // (self, shadow_frame, offset)
+ cbnz x0, MterpOnStackReplacement
+ FETCH_ADVANCE_INST 2
+ GET_INST_OPCODE ip // extract opcode from wINST
+ GOTO_OPCODE ip // jump to next instruction
+
/*
* Check for suspend check request. Assumes wINST already loaded, xPC advanced and
@@ -175,10 +276,36 @@
check2:
mov x0, #1 // signal return to caller.
MterpDone:
- ldp fp, lr, [sp, #48]
- ldp xPC, xFP, [sp, #32]
- ldp xSELF, xINST, [sp, #16]
- ldp xIBASE, xREFS, [sp], #64
+/*
+ * At this point, we expect wPROFILE to be non-zero. If negative, hotness is disabled or we're
+ * checking for OSR. If greater than zero, we might have unreported hotness to register
+ * (the difference between the ending wPROFILE and the cached hotness counter). wPROFILE
+ * should only reach zero immediately after a hotness decrement, and is then reset to either
+ * a negative special state or the new non-zero countdown value.
+ */
+ cmp wPROFILE, #0
+ bgt MterpProfileActive // if > 0, we may have some counts to report.
+ ldp fp, lr, [sp, #64]
+ ldp xPC, xFP, [sp, #48]
+ ldp xSELF, xINST, [sp, #32]
+ ldp xIBASE, xREFS, [sp, #16]
+ ldp xPROFILE, x27, [sp], #80
+ ret
+
+MterpProfileActive:
+ mov xINST, x0 // stash return value
+ /* Report cached hotness counts */
+ ldr x0, [xFP, #OFF_FP_METHOD]
+ add x1, xFP, #OFF_FP_SHADOWFRAME
+ mov x2, xSELF
+ strh wPROFILE, [x1, #SHADOWFRAME_HOTNESS_COUNTDOWN_OFFSET]
+ bl MterpAddHotnessBatch // (method, shadow_frame, self)
+ mov x0, xINST // restore return value
+ ldp fp, lr, [sp, #64]
+ ldp xPC, xFP, [sp, #48]
+ ldp xSELF, xINST, [sp, #32]
+ ldp xIBASE, xREFS, [sp, #16]
+ ldp xPROFILE, x27, [sp], #80
ret
.cfi_endproc
diff --git a/runtime/interpreter/mterp/arm64/header.S b/runtime/interpreter/mterp/arm64/header.S
index 7101ba9..4257200 100644
--- a/runtime/interpreter/mterp/arm64/header.S
+++ b/runtime/interpreter/mterp/arm64/header.S
@@ -74,6 +74,7 @@
x23 xINST first 16-bit code unit of current instruction
x24 xIBASE interpreted instruction base pointer, used for computed goto
x25 xREFS base of object references in shadow frame (ideally, we'll get rid of this later).
+ x26 wPROFILE jit profile hotness countdown
x16 ip scratch reg
x17 ip2 scratch reg (used by macros)
@@ -92,15 +93,17 @@
/* During bringup, we'll use the shadow frame model instead of xFP */
/* single-purpose registers, given names for clarity */
-#define xPC x20
-#define xFP x21
-#define xSELF x22
-#define xINST x23
-#define wINST w23
-#define xIBASE x24
-#define xREFS x25
-#define ip x16
-#define ip2 x17
+#define xPC x20
+#define xFP x21
+#define xSELF x22
+#define xINST x23
+#define wINST w23
+#define xIBASE x24
+#define xREFS x25
+#define wPROFILE w26
+#define xPROFILE x26
+#define ip x16
+#define ip2 x17
/*
* Instead of holding a pointer to the shadow frame, we keep xFP at the base of the vregs. So,
@@ -114,7 +117,7 @@
#define OFF_FP_RESULT_REGISTER OFF_FP(SHADOWFRAME_RESULT_REGISTER_OFFSET)
#define OFF_FP_DEX_PC_PTR OFF_FP(SHADOWFRAME_DEX_PC_PTR_OFFSET)
#define OFF_FP_CODE_ITEM OFF_FP(SHADOWFRAME_CODE_ITEM_OFFSET)
-#define OFF_FP_SHADOWFRAME (-SHADOWFRAME_VREGS_OFFSET)
+#define OFF_FP_SHADOWFRAME OFF_FP(0)
/*
* "export" the PC to dex_pc field in the shadow frame, f/b/o future exception objects. Must
diff --git a/runtime/interpreter/mterp/arm64/op_goto.S b/runtime/interpreter/mterp/arm64/op_goto.S
index 7e2f6a9..6381e94 100644
--- a/runtime/interpreter/mterp/arm64/op_goto.S
+++ b/runtime/interpreter/mterp/arm64/op_goto.S
@@ -5,21 +5,5 @@
* double to get a byte offset.
*/
/* goto +AA */
- /* tuning: use sbfx for 6t2+ targets */
- lsl w0, wINST, #16 // w0<- AAxx0000
- asr wINST, w0, #24 // wINST<- ssssssAA (sign-extended)
-#if MTERP_PROFILE_BRANCHES
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in wINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET] // Preload flags for MterpCheckSuspendAndContinue
- adds w1, wINST, wINST // Convert dalvik offset to byte offset, setting flags
- FETCH_ADVANCE_INST_RB w1 // load wINST and advance xPC
- // If backwards branch refresh rIBASE
- b.mi MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip // extract opcode from wINST
- GOTO_OPCODE ip // jump to next instruction
+ sbfx wINST, wINST, #8, #8 // wINST<- ssssssAA (sign-extended)
+ b MterpCommonTakenBranchNoFlags
diff --git a/runtime/interpreter/mterp/arm64/op_goto_16.S b/runtime/interpreter/mterp/arm64/op_goto_16.S
index b2b9924..fb9a80a 100644
--- a/runtime/interpreter/mterp/arm64/op_goto_16.S
+++ b/runtime/interpreter/mterp/arm64/op_goto_16.S
@@ -6,17 +6,4 @@
*/
/* goto/16 +AAAA */
FETCH_S wINST, 1 // wINST<- ssssAAAA (sign-extended)
-#if MTERP_PROFILE_BRANCHES
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in xINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w1, wINST, wINST // w1<- byte offset, flags set
- FETCH_ADVANCE_INST_RB w1 // update rPC, load rINST
- b.mi MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip // extract opcode from rINST
- GOTO_OPCODE ip // jump to next instruction
+ b MterpCommonTakenBranchNoFlags
diff --git a/runtime/interpreter/mterp/arm64/op_goto_32.S b/runtime/interpreter/mterp/arm64/op_goto_32.S
index b785857..b13cb41 100644
--- a/runtime/interpreter/mterp/arm64/op_goto_32.S
+++ b/runtime/interpreter/mterp/arm64/op_goto_32.S
@@ -13,17 +13,4 @@
FETCH w0, 1 // w0<- aaaa (lo)
FETCH w1, 2 // w1<- AAAA (hi)
orr wINST, w0, w1, lsl #16 // wINST<- AAAAaaaa
-#if MTERP_PROFILE_BRANCHES
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in xINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w1, wINST, wINST // w1<- byte offset
- FETCH_ADVANCE_INST_RB w1 // update rPC, load xINST
- b.le MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip // extract opcode from xINST
- GOTO_OPCODE ip // jump to next instruction
+ b MterpCommonTakenBranchNoFlags
diff --git a/runtime/interpreter/mterp/arm64/op_packed_switch.S b/runtime/interpreter/mterp/arm64/op_packed_switch.S
index e8b4f04..1456f1a 100644
--- a/runtime/interpreter/mterp/arm64/op_packed_switch.S
+++ b/runtime/interpreter/mterp/arm64/op_packed_switch.S
@@ -17,17 +17,4 @@
add x0, xPC, w0, lsl #1 // w0<- PC + BBBBbbbb*2
bl $func // w0<- code-unit branch offset
sbfm xINST, x0, 0, 31
-#if MTERP_PROFILE_BRANCHES
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- mov x2, xINST
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w1, wINST, wINST // w1<- byte offset; clear V
- FETCH_ADVANCE_INST_RB w1 // update rPC, load wINST
- b.le MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip // extract opcode from wINST
- GOTO_OPCODE ip // jump to next instruction
+ b MterpCommonTakenBranchNoFlags
diff --git a/runtime/interpreter/mterp/arm64/zcmp.S b/runtime/interpreter/mterp/arm64/zcmp.S
index 3f1e1b1..b303e6a 100644
--- a/runtime/interpreter/mterp/arm64/zcmp.S
+++ b/runtime/interpreter/mterp/arm64/zcmp.S
@@ -1,29 +1,17 @@
/*
- * Generic one-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic one-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* for: if-eqz, if-nez, if-ltz, if-gez, if-gtz, if-lez
*/
/* if-cmp vAA, +BBBB */
lsr w0, wINST, #8 // w0<- AA
GET_VREG w2, w0 // w2<- vAA
- FETCH_S w1, 1 // w1<- branch offset, in code units
- mov w0, #2 // Branch offset if not taken
+ FETCH_S wINST, 1 // w1<- branch offset, in code units
cmp w2, #0 // compare (vA, 0)
- csel wINST, w1, w0, ${condition} // Branch if true, stashing result in callee save reg
-#if MTERP_PROFILE_BRANCHES
- // TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in wINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w2, wINST, wINST // convert to bytes & set flags
- FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
- b.mi MterpCheckSuspendAndContinue
+ b.${condition} MterpCommonTakenBranchNoFlags
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.eq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip // extract opcode from wINST
GOTO_OPCODE ip // jump to next instruction
diff --git a/runtime/interpreter/mterp/mterp.cc b/runtime/interpreter/mterp/mterp.cc
index 10b19c5..de9041b 100644
--- a/runtime/interpreter/mterp/mterp.cc
+++ b/runtime/interpreter/mterp/mterp.cc
@@ -21,6 +21,7 @@
#include "entrypoints/entrypoint_utils-inl.h"
#include "mterp.h"
#include "jit/jit.h"
+#include "jit/jit_instrumentation.h"
#include "debugger.h"
namespace art {
@@ -432,7 +433,7 @@
}
extern "C" void MterpCheckBefore(Thread* self, ShadowFrame* shadow_frame)
- SHARED_REQUIRES(Locks::mutator_lock_) {
+ SHARED_REQUIRES(Locks::mutator_lock_) {
const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr());
uint16_t inst_data = inst->Fetch16(0);
if (inst->Opcode(inst_data) == Instruction::MOVE_EXCEPTION) {
@@ -444,7 +445,7 @@
}
extern "C" void MterpLogDivideByZeroException(Thread* self, ShadowFrame* shadow_frame)
- SHARED_REQUIRES(Locks::mutator_lock_) {
+ SHARED_REQUIRES(Locks::mutator_lock_) {
UNUSED(self);
const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr());
uint16_t inst_data = inst->Fetch16(0);
@@ -452,7 +453,7 @@
}
extern "C" void MterpLogArrayIndexException(Thread* self, ShadowFrame* shadow_frame)
- SHARED_REQUIRES(Locks::mutator_lock_) {
+ SHARED_REQUIRES(Locks::mutator_lock_) {
UNUSED(self);
const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr());
uint16_t inst_data = inst->Fetch16(0);
@@ -460,7 +461,7 @@
}
extern "C" void MterpLogNegativeArraySizeException(Thread* self, ShadowFrame* shadow_frame)
- SHARED_REQUIRES(Locks::mutator_lock_) {
+ SHARED_REQUIRES(Locks::mutator_lock_) {
UNUSED(self);
const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr());
uint16_t inst_data = inst->Fetch16(0);
@@ -468,7 +469,7 @@
}
extern "C" void MterpLogNoSuchMethodException(Thread* self, ShadowFrame* shadow_frame)
- SHARED_REQUIRES(Locks::mutator_lock_) {
+ SHARED_REQUIRES(Locks::mutator_lock_) {
UNUSED(self);
const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr());
uint16_t inst_data = inst->Fetch16(0);
@@ -476,7 +477,7 @@
}
extern "C" void MterpLogExceptionThrownException(Thread* self, ShadowFrame* shadow_frame)
- SHARED_REQUIRES(Locks::mutator_lock_) {
+ SHARED_REQUIRES(Locks::mutator_lock_) {
UNUSED(self);
const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr());
uint16_t inst_data = inst->Fetch16(0);
@@ -484,7 +485,7 @@
}
extern "C" void MterpLogNullObjectException(Thread* self, ShadowFrame* shadow_frame)
- SHARED_REQUIRES(Locks::mutator_lock_) {
+ SHARED_REQUIRES(Locks::mutator_lock_) {
UNUSED(self);
const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr());
uint16_t inst_data = inst->Fetch16(0);
@@ -492,7 +493,7 @@
}
extern "C" void MterpLogFallback(Thread* self, ShadowFrame* shadow_frame)
- SHARED_REQUIRES(Locks::mutator_lock_) {
+ SHARED_REQUIRES(Locks::mutator_lock_) {
UNUSED(self);
const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr());
uint16_t inst_data = inst->Fetch16(0);
@@ -501,7 +502,7 @@
}
extern "C" void MterpLogOSR(Thread* self, ShadowFrame* shadow_frame, int32_t offset)
- SHARED_REQUIRES(Locks::mutator_lock_) {
+ SHARED_REQUIRES(Locks::mutator_lock_) {
UNUSED(self);
const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr());
uint16_t inst_data = inst->Fetch16(0);
@@ -509,7 +510,7 @@
}
extern "C" void MterpLogSuspendFallback(Thread* self, ShadowFrame* shadow_frame, uint32_t flags)
- SHARED_REQUIRES(Locks::mutator_lock_) {
+ SHARED_REQUIRES(Locks::mutator_lock_) {
UNUSED(self);
const Instruction* inst = Instruction::At(shadow_frame->GetDexPCPtr());
uint16_t inst_data = inst->Fetch16(0);
@@ -521,7 +522,7 @@
}
extern "C" bool MterpSuspendCheck(Thread* self)
- SHARED_REQUIRES(Locks::mutator_lock_) {
+ SHARED_REQUIRES(Locks::mutator_lock_) {
self->AllowThreadSuspension();
return MterpShouldSwitchInterpreters();
}
@@ -617,7 +618,7 @@
}
extern "C" mirror::Object* artAGetObjectFromMterp(mirror::Object* arr, int32_t index)
- SHARED_REQUIRES(Locks::mutator_lock_) {
+ SHARED_REQUIRES(Locks::mutator_lock_) {
if (UNLIKELY(arr == nullptr)) {
ThrowNullPointerExceptionFromInterpreter();
return nullptr;
@@ -631,7 +632,7 @@
}
extern "C" mirror::Object* artIGetObjectFromMterp(mirror::Object* obj, uint32_t field_offset)
- SHARED_REQUIRES(Locks::mutator_lock_) {
+ SHARED_REQUIRES(Locks::mutator_lock_) {
if (UNLIKELY(obj == nullptr)) {
ThrowNullPointerExceptionFromInterpreter();
return nullptr;
@@ -639,13 +640,85 @@
return obj->GetFieldObject<mirror::Object>(MemberOffset(field_offset));
}
+/*
+ * Create a hotness_countdown based on the current method hotness_count and profiling
+ * mode. In short, determine how many hotness events we hit before reporting back
+ * to the full instrumentation via MterpAddHotnessBatch. Called once on entry to the method,
+ * and regenerated following batch updates.
+ */
+extern "C" int MterpSetUpHotnessCountdown(ArtMethod* method, ShadowFrame* shadow_frame)
+ SHARED_REQUIRES(Locks::mutator_lock_) {
+ uint16_t hotness_count = method->GetCounter();
+ int32_t countdown_value = jit::kJitHotnessDisabled;
+ jit::Jit* jit = Runtime::Current()->GetJit();
+ if (jit != nullptr) {
+ jit::JitInstrumentationCache* cache = jit->GetInstrumentationCache();
+ int32_t warm_threshold = cache->WarmMethodThreshold();
+ int32_t hot_threshold = cache->HotMethodThreshold();
+ int32_t osr_threshold = cache->OSRMethodThreshold();
+ if (hotness_count < warm_threshold) {
+ countdown_value = warm_threshold - hotness_count;
+ } else if (hotness_count < hot_threshold) {
+ countdown_value = hot_threshold - hotness_count;
+ } else if (hotness_count < osr_threshold) {
+ countdown_value = osr_threshold - hotness_count;
+ } else {
+ countdown_value = jit::kJitCheckForOSR;
+ }
+ }
+ /*
+ * The actual hotness threshold may exceed the range of our int16_t countdown value. This is
+ * not a problem, though. We can just break it down into smaller chunks.
+ */
+ countdown_value = std::min(countdown_value,
+ static_cast<int32_t>(std::numeric_limits<int16_t>::max()));
+ shadow_frame->SetCachedHotnessCountdown(countdown_value);
+ shadow_frame->SetHotnessCountdown(countdown_value);
+ return countdown_value;
+}
+
+/*
+ * Report a batch of hotness events to the instrumentation and then return the new
+ * countdown value to the next time we should report.
+ */
+extern "C" int16_t MterpAddHotnessBatch(ArtMethod* method,
+ ShadowFrame* shadow_frame,
+ Thread* self)
+ SHARED_REQUIRES(Locks::mutator_lock_) {
+ jit::Jit* jit = Runtime::Current()->GetJit();
+ if (jit != nullptr) {
+ int16_t count = shadow_frame->GetCachedHotnessCountdown() - shadow_frame->GetHotnessCountdown();
+ jit->GetInstrumentationCache()->AddSamples(self, method, count);
+ }
+ return MterpSetUpHotnessCountdown(method, shadow_frame);
+}
+
+// TUNING: Unused by arm/arm64. Remove when x86/x86_64/mips/mips64 mterps support batch updates.
extern "C" bool MterpProfileBranch(Thread* self, ShadowFrame* shadow_frame, int32_t offset)
- SHARED_REQUIRES(Locks::mutator_lock_) {
+ SHARED_REQUIRES(Locks::mutator_lock_) {
ArtMethod* method = shadow_frame->GetMethod();
JValue* result = shadow_frame->GetResultRegister();
uint32_t dex_pc = shadow_frame->GetDexPC();
- const auto* const instrumentation = Runtime::Current()->GetInstrumentation();
- instrumentation->Branch(self, method, dex_pc, offset);
+ jit::Jit* jit = Runtime::Current()->GetJit();
+ if ((jit != nullptr) && (offset <= 0)) {
+ jit->GetInstrumentationCache()->AddSamples(self, method, 1);
+ }
+ int16_t countdown_value = MterpSetUpHotnessCountdown(method, shadow_frame);
+ if (countdown_value == jit::kJitCheckForOSR) {
+ return jit::Jit::MaybeDoOnStackReplacement(self, method, dex_pc, offset, result);
+ } else {
+ return false;
+ }
+}
+
+extern "C" bool MterpMaybeDoOnStackReplacement(Thread* self,
+ ShadowFrame* shadow_frame,
+ int32_t offset)
+ SHARED_REQUIRES(Locks::mutator_lock_) {
+ ArtMethod* method = shadow_frame->GetMethod();
+ JValue* result = shadow_frame->GetResultRegister();
+ uint32_t dex_pc = shadow_frame->GetDexPC();
+ // Assumes caller has already determined that an OSR check is appropriate.
return jit::Jit::MaybeDoOnStackReplacement(self, method, dex_pc, offset, result);
}
diff --git a/runtime/interpreter/mterp/out/mterp_arm.S b/runtime/interpreter/mterp/out/mterp_arm.S
index 092474d..a38a87b 100644
--- a/runtime/interpreter/mterp/out/mterp_arm.S
+++ b/runtime/interpreter/mterp/out/mterp_arm.S
@@ -79,7 +79,8 @@
r6 rSELF self (Thread) pointer
r7 rINST first 16-bit code unit of current instruction
r8 rIBASE interpreted instruction base pointer, used for computed goto
- r11 rREFS base of object references in shadow frame (ideally, we'll get rid of this later).
+ r10 rPROFILE branch profiling countdown
+ r11 rREFS base of object references in shadow frame (ideally, we'll get rid of this later).
Macros are provided for common operations. Each macro MUST emit only
one instruction to make instruction-counting easier. They MUST NOT alter
@@ -97,12 +98,13 @@
/* During bringup, we'll use the shadow frame model instead of rFP */
/* single-purpose registers, given names for clarity */
-#define rPC r4
-#define rFP r5
-#define rSELF r6
-#define rINST r7
-#define rIBASE r8
-#define rREFS r11
+#define rPC r4
+#define rFP r5
+#define rSELF r6
+#define rINST r7
+#define rIBASE r8
+#define rPROFILE r10
+#define rREFS r11
/*
* Instead of holding a pointer to the shadow frame, we keep rFP at the base of the vregs. So,
@@ -116,7 +118,7 @@
#define OFF_FP_RESULT_REGISTER OFF_FP(SHADOWFRAME_RESULT_REGISTER_OFFSET)
#define OFF_FP_DEX_PC_PTR OFF_FP(SHADOWFRAME_DEX_PC_PTR_OFFSET)
#define OFF_FP_CODE_ITEM OFF_FP(SHADOWFRAME_CODE_ITEM_OFFSET)
-#define OFF_FP_SHADOWFRAME (-SHADOWFRAME_VREGS_OFFSET)
+#define OFF_FP_SHADOWFRAME OFF_FP(0)
/*
* "export" the PC to dex_pc field in the shadow frame, f/b/o future exception objects. Must
@@ -329,10 +331,8 @@
ExecuteMterpImpl:
.fnstart
- .save {r4-r10,fp,lr}
- stmfd sp!, {r4-r10,fp,lr} @ save 9 regs
- .pad #4
- sub sp, sp, #4 @ align 64
+ .save {r3-r10,fp,lr}
+ stmfd sp!, {r3-r10,fp,lr} @ save 10 regs, (r3 just to align 64)
/* Remember the return register */
str r3, [r2, #SHADOWFRAME_RESULT_REGISTER_OFFSET]
@@ -353,6 +353,12 @@
/* Starting ibase */
ldr rIBASE, [rSELF, #THREAD_CURRENT_IBASE_OFFSET]
+ /* Set up for backwards branches & osr profiling */
+ ldr r0, [rFP, #OFF_FP_METHOD]
+ add r1, rFP, #OFF_FP_SHADOWFRAME
+ bl MterpSetUpHotnessCountdown
+ mov rPROFILE, r0 @ Starting hotness countdown to rPROFILE
+
/* start executing the instruction at rPC */
FETCH_INST @ load rINST from rPC
GET_INST_OPCODE ip @ extract opcode from rINST
@@ -1103,35 +1109,8 @@
* double to get a byte offset.
*/
/* goto +AA */
- /* tuning: use sbfx for 6t2+ targets */
-#if MTERP_PROFILE_BRANCHES
- mov r0, rINST, lsl #16 @ r0<- AAxx0000
- movs rINST, r0, asr #24 @ rINST<- ssssssAA (sign-extended)
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r2, rINST, rINST @ r2<- byte offset, set flags
- FETCH_ADVANCE_INST_RB r2 @ update rPC, load rINST
- @ If backwards branch refresh rIBASE
- bmi MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#else
- mov r0, rINST, lsl #16 @ r0<- AAxx0000
- movs rINST, r0, asr #24 @ rINST<- ssssssAA (sign-extended)
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r2, rINST, rINST @ r2<- byte offset, set flags
- FETCH_ADVANCE_INST_RB r2 @ update rPC, load rINST
- @ If backwards branch refresh rIBASE
- bmi MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#endif
+ sbfx rINST, rINST, #8, #8 @ rINST<- ssssssAA (sign-extended)
+ b MterpCommonTakenBranchNoFlags
/* ------------------------------ */
.balign 128
@@ -1144,30 +1123,8 @@
* double to get a byte offset.
*/
/* goto/16 +AAAA */
-#if MTERP_PROFILE_BRANCHES
FETCH_S rINST, 1 @ rINST<- ssssAAAA (sign-extended)
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r1, rINST, rINST @ r1<- byte offset, flags set
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#else
- FETCH_S rINST, 1 @ rINST<- ssssAAAA (sign-extended)
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r1, rINST, rINST @ r1<- byte offset, flags set
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#endif
+ b MterpCommonTakenBranchNoFlags
/* ------------------------------ */
.balign 128
@@ -1185,34 +1142,10 @@
* offset to byte offset.
*/
/* goto/32 +AAAAAAAA */
-#if MTERP_PROFILE_BRANCHES
FETCH r0, 1 @ r0<- aaaa (lo)
- FETCH r1, 2 @ r1<- AAAA (hi)
- orr rINST, r0, r1, lsl #16 @ rINST<- AAAAaaaa
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r1, rINST, rINST @ r1<- byte offset
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- ble MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#else
- FETCH r0, 1 @ r0<- aaaa (lo)
- FETCH r1, 2 @ r1<- AAAA (hi)
- orr rINST, r0, r1, lsl #16 @ rINST<- AAAAaaaa
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r1, rINST, rINST @ r1<- byte offset
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- ble MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#endif
+ FETCH r3, 2 @ r1<- AAAA (hi)
+ orrs rINST, r0, r3, lsl #16 @ rINST<- AAAAaaaa
+ b MterpCommonTakenBranch
/* ------------------------------ */
.balign 128
@@ -1228,7 +1161,6 @@
* for: packed-switch, sparse-switch
*/
/* op vAA, +BBBB */
-#if MTERP_PROFILE_BRANCHES
FETCH r0, 1 @ r0<- bbbb (lo)
FETCH r1, 2 @ r1<- BBBB (hi)
mov r3, rINST, lsr #8 @ r3<- AA
@@ -1236,36 +1168,8 @@
GET_VREG r1, r3 @ r1<- vAA
add r0, rPC, r0, lsl #1 @ r0<- PC + BBBBbbbb*2
bl MterpDoPackedSwitch @ r0<- code-unit branch offset
- mov rINST, r0
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r1, rINST, rINST @ r1<- byte offset; clear V
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- ble MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#else
- FETCH r0, 1 @ r0<- bbbb (lo)
- FETCH r1, 2 @ r1<- BBBB (hi)
- mov r3, rINST, lsr #8 @ r3<- AA
- orr r0, r0, r1, lsl #16 @ r0<- BBBBbbbb
- GET_VREG r1, r3 @ r1<- vAA
- add r0, rPC, r0, lsl #1 @ r0<- PC + BBBBbbbb*2
- bl MterpDoPackedSwitch @ r0<- code-unit branch offset
- mov rINST, r0
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r1, rINST, rINST @ r1<- byte offset; clear V
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- ble MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#endif
+ movs rINST, r0
+ b MterpCommonTakenBranch
/* ------------------------------ */
.balign 128
@@ -1282,7 +1186,6 @@
* for: packed-switch, sparse-switch
*/
/* op vAA, +BBBB */
-#if MTERP_PROFILE_BRANCHES
FETCH r0, 1 @ r0<- bbbb (lo)
FETCH r1, 2 @ r1<- BBBB (hi)
mov r3, rINST, lsr #8 @ r3<- AA
@@ -1290,36 +1193,8 @@
GET_VREG r1, r3 @ r1<- vAA
add r0, rPC, r0, lsl #1 @ r0<- PC + BBBBbbbb*2
bl MterpDoSparseSwitch @ r0<- code-unit branch offset
- mov rINST, r0
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r1, rINST, rINST @ r1<- byte offset; clear V
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- ble MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#else
- FETCH r0, 1 @ r0<- bbbb (lo)
- FETCH r1, 2 @ r1<- BBBB (hi)
- mov r3, rINST, lsr #8 @ r3<- AA
- orr r0, r0, r1, lsl #16 @ r0<- BBBBbbbb
- GET_VREG r1, r3 @ r1<- vAA
- add r0, rPC, r0, lsl #1 @ r0<- PC + BBBBbbbb*2
- bl MterpDoSparseSwitch @ r0<- code-unit branch offset
- mov rINST, r0
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- adds r1, rINST, rINST @ r1<- byte offset; clear V
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- ble MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-#endif
+ movs rINST, r0
+ b MterpCommonTakenBranch
/* ------------------------------ */
@@ -1485,22 +1360,6 @@
/*
* Compare two 64-bit values. Puts 0, 1, or -1 into the destination
* register based on the results of the comparison.
- *
- * We load the full values with LDM, but in practice many values could
- * be resolved by only looking at the high word. This could be made
- * faster or slower by splitting the LDM into a pair of LDRs.
- *
- * If we just wanted to set condition flags, we could do this:
- * subs ip, r0, r2
- * sbcs ip, r1, r3
- * subeqs ip, r0, r2
- * Leaving { <0, 0, >0 } in ip. However, we have to set it to a specific
- * integer value, which we can do with 2 conditional mov/mvn instructions
- * (set 1, set -1; if they're equal we already have 0 in ip), giving
- * us a constant 5-cycle path plus a branch at the end to the
- * instruction epilogue code. The multi-compare approach below needs
- * 2 or 3 cycles + branch if the high word doesn't match, 6 + branch
- * in the worst case (the 64-bit values are equal).
*/
/* cmp-long vAA, vBB, vCC */
FETCH r0, 1 @ r0<- CCBB
@@ -1511,13 +1370,16 @@
VREG_INDEX_TO_ADDR r3, r3 @ r3<- &fp[CC]
ldmia r2, {r0-r1} @ r0/r1<- vBB/vBB+1
ldmia r3, {r2-r3} @ r2/r3<- vCC/vCC+1
- cmp r1, r3 @ compare (vBB+1, vCC+1)
- blt .Lop_cmp_long_less @ signed compare on high part
- bgt .Lop_cmp_long_greater
- subs r1, r0, r2 @ r1<- r0 - r2
- bhi .Lop_cmp_long_greater @ unsigned compare on low part
- bne .Lop_cmp_long_less
- b .Lop_cmp_long_finish @ equal; r1 already holds 0
+ cmp r0, r2
+ sbcs ip, r1, r3 @ Sets correct CCs for checking LT (but not EQ/NE)
+ mov ip, #0
+ mvnlt ip, #0 @ -1
+ cmpeq r0, r2 @ For correct EQ/NE, we may need to repeat the first CMP
+ orrne ip, #1
+ FETCH_ADVANCE_INST 2 @ advance rPC, load rINST
+ SET_VREG ip, r9 @ vAA<- ip
+ GET_INST_OPCODE ip @ extract opcode from rINST
+ GOTO_OPCODE ip @ jump to next instruction
/* ------------------------------ */
.balign 128
@@ -1525,9 +1387,8 @@
/* File: arm/op_if_eq.S */
/* File: arm/bincmp.S */
/*
- * Generic two-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic two-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* For: if-eq, if-ne, if-lt, if-ge, if-gt, if-le
*/
@@ -1535,24 +1396,13 @@
mov r1, rINST, lsr #12 @ r1<- B
ubfx r0, rINST, #8, #4 @ r0<- A
GET_VREG r3, r1 @ r3<- vB
- GET_VREG r2, r0 @ r2<- vA
+ GET_VREG r0, r0 @ r0<- vA
FETCH_S rINST, 1 @ rINST<- branch offset, in code units
- cmp r2, r3 @ compare (vA, vB)
- movne rINST, #2
-#if MTERP_PROFILE_BRANCHES
- @ TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
-#endif
- adds r2, rINST, rINST @ convert to bytes, check sign
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- FETCH_ADVANCE_INST_RB r2 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
+ cmp r0, r3 @ compare (vA, vB)
+ beq MterpCommonTakenBranchNoFlags
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ beq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
@@ -1563,9 +1413,8 @@
/* File: arm/op_if_ne.S */
/* File: arm/bincmp.S */
/*
- * Generic two-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic two-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* For: if-eq, if-ne, if-lt, if-ge, if-gt, if-le
*/
@@ -1573,24 +1422,13 @@
mov r1, rINST, lsr #12 @ r1<- B
ubfx r0, rINST, #8, #4 @ r0<- A
GET_VREG r3, r1 @ r3<- vB
- GET_VREG r2, r0 @ r2<- vA
+ GET_VREG r0, r0 @ r0<- vA
FETCH_S rINST, 1 @ rINST<- branch offset, in code units
- cmp r2, r3 @ compare (vA, vB)
- moveq rINST, #2
-#if MTERP_PROFILE_BRANCHES
- @ TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
-#endif
- adds r2, rINST, rINST @ convert to bytes, check sign
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- FETCH_ADVANCE_INST_RB r2 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
+ cmp r0, r3 @ compare (vA, vB)
+ bne MterpCommonTakenBranchNoFlags
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ beq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
@@ -1601,9 +1439,8 @@
/* File: arm/op_if_lt.S */
/* File: arm/bincmp.S */
/*
- * Generic two-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic two-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* For: if-eq, if-ne, if-lt, if-ge, if-gt, if-le
*/
@@ -1611,24 +1448,13 @@
mov r1, rINST, lsr #12 @ r1<- B
ubfx r0, rINST, #8, #4 @ r0<- A
GET_VREG r3, r1 @ r3<- vB
- GET_VREG r2, r0 @ r2<- vA
+ GET_VREG r0, r0 @ r0<- vA
FETCH_S rINST, 1 @ rINST<- branch offset, in code units
- cmp r2, r3 @ compare (vA, vB)
- movge rINST, #2
-#if MTERP_PROFILE_BRANCHES
- @ TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
-#endif
- adds r2, rINST, rINST @ convert to bytes, check sign
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- FETCH_ADVANCE_INST_RB r2 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
+ cmp r0, r3 @ compare (vA, vB)
+ blt MterpCommonTakenBranchNoFlags
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ beq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
@@ -1639,9 +1465,8 @@
/* File: arm/op_if_ge.S */
/* File: arm/bincmp.S */
/*
- * Generic two-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic two-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* For: if-eq, if-ne, if-lt, if-ge, if-gt, if-le
*/
@@ -1649,24 +1474,13 @@
mov r1, rINST, lsr #12 @ r1<- B
ubfx r0, rINST, #8, #4 @ r0<- A
GET_VREG r3, r1 @ r3<- vB
- GET_VREG r2, r0 @ r2<- vA
+ GET_VREG r0, r0 @ r0<- vA
FETCH_S rINST, 1 @ rINST<- branch offset, in code units
- cmp r2, r3 @ compare (vA, vB)
- movlt rINST, #2
-#if MTERP_PROFILE_BRANCHES
- @ TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
-#endif
- adds r2, rINST, rINST @ convert to bytes, check sign
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- FETCH_ADVANCE_INST_RB r2 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
+ cmp r0, r3 @ compare (vA, vB)
+ bge MterpCommonTakenBranchNoFlags
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ beq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
@@ -1677,9 +1491,8 @@
/* File: arm/op_if_gt.S */
/* File: arm/bincmp.S */
/*
- * Generic two-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic two-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* For: if-eq, if-ne, if-lt, if-ge, if-gt, if-le
*/
@@ -1687,24 +1500,13 @@
mov r1, rINST, lsr #12 @ r1<- B
ubfx r0, rINST, #8, #4 @ r0<- A
GET_VREG r3, r1 @ r3<- vB
- GET_VREG r2, r0 @ r2<- vA
+ GET_VREG r0, r0 @ r0<- vA
FETCH_S rINST, 1 @ rINST<- branch offset, in code units
- cmp r2, r3 @ compare (vA, vB)
- movle rINST, #2
-#if MTERP_PROFILE_BRANCHES
- @ TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
-#endif
- adds r2, rINST, rINST @ convert to bytes, check sign
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- FETCH_ADVANCE_INST_RB r2 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
+ cmp r0, r3 @ compare (vA, vB)
+ bgt MterpCommonTakenBranchNoFlags
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ beq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
@@ -1715,9 +1517,8 @@
/* File: arm/op_if_le.S */
/* File: arm/bincmp.S */
/*
- * Generic two-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic two-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* For: if-eq, if-ne, if-lt, if-ge, if-gt, if-le
*/
@@ -1725,24 +1526,13 @@
mov r1, rINST, lsr #12 @ r1<- B
ubfx r0, rINST, #8, #4 @ r0<- A
GET_VREG r3, r1 @ r3<- vB
- GET_VREG r2, r0 @ r2<- vA
+ GET_VREG r0, r0 @ r0<- vA
FETCH_S rINST, 1 @ rINST<- branch offset, in code units
- cmp r2, r3 @ compare (vA, vB)
- movgt rINST, #2
-#if MTERP_PROFILE_BRANCHES
- @ TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
-#endif
- adds r2, rINST, rINST @ convert to bytes, check sign
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- FETCH_ADVANCE_INST_RB r2 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
+ cmp r0, r3 @ compare (vA, vB)
+ ble MterpCommonTakenBranchNoFlags
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ beq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
@@ -1753,32 +1543,20 @@
/* File: arm/op_if_eqz.S */
/* File: arm/zcmp.S */
/*
- * Generic one-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic one-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* for: if-eqz, if-nez, if-ltz, if-gez, if-gtz, if-lez
*/
/* if-cmp vAA, +BBBB */
mov r0, rINST, lsr #8 @ r0<- AA
- GET_VREG r2, r0 @ r2<- vAA
+ GET_VREG r0, r0 @ r0<- vAA
FETCH_S rINST, 1 @ rINST<- branch offset, in code units
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- cmp r2, #0 @ compare (vA, 0)
- movne rINST, #2
-#if MTERP_PROFILE_BRANCHES
- @ TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
-#endif
- adds r1, rINST, rINST @ convert to bytes & set flags
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
+ cmp r0, #0 @ compare (vA, 0)
+ beq MterpCommonTakenBranchNoFlags
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ beq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
@@ -1789,32 +1567,20 @@
/* File: arm/op_if_nez.S */
/* File: arm/zcmp.S */
/*
- * Generic one-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic one-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* for: if-eqz, if-nez, if-ltz, if-gez, if-gtz, if-lez
*/
/* if-cmp vAA, +BBBB */
mov r0, rINST, lsr #8 @ r0<- AA
- GET_VREG r2, r0 @ r2<- vAA
+ GET_VREG r0, r0 @ r0<- vAA
FETCH_S rINST, 1 @ rINST<- branch offset, in code units
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- cmp r2, #0 @ compare (vA, 0)
- moveq rINST, #2
-#if MTERP_PROFILE_BRANCHES
- @ TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
-#endif
- adds r1, rINST, rINST @ convert to bytes & set flags
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
+ cmp r0, #0 @ compare (vA, 0)
+ bne MterpCommonTakenBranchNoFlags
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ beq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
@@ -1825,32 +1591,20 @@
/* File: arm/op_if_ltz.S */
/* File: arm/zcmp.S */
/*
- * Generic one-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic one-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* for: if-eqz, if-nez, if-ltz, if-gez, if-gtz, if-lez
*/
/* if-cmp vAA, +BBBB */
mov r0, rINST, lsr #8 @ r0<- AA
- GET_VREG r2, r0 @ r2<- vAA
+ GET_VREG r0, r0 @ r0<- vAA
FETCH_S rINST, 1 @ rINST<- branch offset, in code units
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- cmp r2, #0 @ compare (vA, 0)
- movge rINST, #2
-#if MTERP_PROFILE_BRANCHES
- @ TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
-#endif
- adds r1, rINST, rINST @ convert to bytes & set flags
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
+ cmp r0, #0 @ compare (vA, 0)
+ blt MterpCommonTakenBranchNoFlags
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ beq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
@@ -1861,32 +1615,20 @@
/* File: arm/op_if_gez.S */
/* File: arm/zcmp.S */
/*
- * Generic one-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic one-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* for: if-eqz, if-nez, if-ltz, if-gez, if-gtz, if-lez
*/
/* if-cmp vAA, +BBBB */
mov r0, rINST, lsr #8 @ r0<- AA
- GET_VREG r2, r0 @ r2<- vAA
+ GET_VREG r0, r0 @ r0<- vAA
FETCH_S rINST, 1 @ rINST<- branch offset, in code units
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- cmp r2, #0 @ compare (vA, 0)
- movlt rINST, #2
-#if MTERP_PROFILE_BRANCHES
- @ TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
-#endif
- adds r1, rINST, rINST @ convert to bytes & set flags
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
+ cmp r0, #0 @ compare (vA, 0)
+ bge MterpCommonTakenBranchNoFlags
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ beq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
@@ -1897,32 +1639,20 @@
/* File: arm/op_if_gtz.S */
/* File: arm/zcmp.S */
/*
- * Generic one-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic one-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* for: if-eqz, if-nez, if-ltz, if-gez, if-gtz, if-lez
*/
/* if-cmp vAA, +BBBB */
mov r0, rINST, lsr #8 @ r0<- AA
- GET_VREG r2, r0 @ r2<- vAA
+ GET_VREG r0, r0 @ r0<- vAA
FETCH_S rINST, 1 @ rINST<- branch offset, in code units
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- cmp r2, #0 @ compare (vA, 0)
- movle rINST, #2
-#if MTERP_PROFILE_BRANCHES
- @ TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
-#endif
- adds r1, rINST, rINST @ convert to bytes & set flags
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
+ cmp r0, #0 @ compare (vA, 0)
+ bgt MterpCommonTakenBranchNoFlags
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ beq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
@@ -1933,32 +1663,20 @@
/* File: arm/op_if_lez.S */
/* File: arm/zcmp.S */
/*
- * Generic one-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic one-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* for: if-eqz, if-nez, if-ltz, if-gez, if-gtz, if-lez
*/
/* if-cmp vAA, +BBBB */
mov r0, rINST, lsr #8 @ r0<- AA
- GET_VREG r2, r0 @ r2<- vAA
+ GET_VREG r0, r0 @ r0<- vAA
FETCH_S rINST, 1 @ rINST<- branch offset, in code units
- ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
- cmp r2, #0 @ compare (vA, 0)
- movgt rINST, #2
-#if MTERP_PROFILE_BRANCHES
- @ TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov r0, rSELF
- add r1, rFP, #OFF_FP_SHADOWFRAME
- mov r2, rINST
- bl MterpProfileBranch @ (self, shadow_frame, offset)
- cmp r0, #0
- bne MterpOnStackReplacement @ Note: offset must be in rINST
-#endif
- adds r1, rINST, rINST @ convert to bytes & set flags
- FETCH_ADVANCE_INST_RB r1 @ update rPC, load rINST
- bmi MterpCheckSuspendAndContinue
+ cmp r0, #0 @ compare (vA, 0)
+ ble MterpCommonTakenBranchNoFlags
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ beq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
@@ -4711,15 +4429,15 @@
VREG_INDEX_TO_ADDR r3, r3 @ r3<- &fp[CC]
ldmia r2, {r0-r1} @ r0/r1<- vBB/vBB+1
ldmia r3, {r2-r3} @ r2/r3<- vCC/vCC+1
- mul ip, r2, r1 @ ip<- ZxW
- umull r9, r10, r2, r0 @ r9/r10 <- ZxX
- mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
+ mul ip, r2, r1 @ ip<- ZxW
+ umull r1, lr, r2, r0 @ r1/lr <- ZxX
+ mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
mov r0, rINST, lsr #8 @ r0<- AA
- add r10, r2, r10 @ r10<- r10 + low(ZxW + (YxX))
+ add r2, r2, lr @ r2<- lr + low(ZxW + (YxX))
VREG_INDEX_TO_ADDR r0, r0 @ r0<- &fp[AA]
FETCH_ADVANCE_INST 2 @ advance rPC, load rINST
GET_INST_OPCODE ip @ extract opcode from rINST
- stmia r0, {r9-r10} @ vAA/vAA+1<- r9/r10
+ stmia r0, {r1-r2 } @ vAA/vAA+1<- r1/r2
GOTO_OPCODE ip @ jump to next instruction
/* ------------------------------ */
@@ -5877,14 +5595,14 @@
VREG_INDEX_TO_ADDR rINST, r9 @ rINST<- &fp[A]
ldmia r1, {r2-r3} @ r2/r3<- vBB/vBB+1
ldmia rINST, {r0-r1} @ r0/r1<- vAA/vAA+1
- mul ip, r2, r1 @ ip<- ZxW
- umull r9, r10, r2, r0 @ r9/r10 <- ZxX
- mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
+ mul ip, r2, r1 @ ip<- ZxW
+ umull r1, lr, r2, r0 @ r1/lr <- ZxX
+ mla r2, r0, r3, ip @ r2<- YxX + (ZxW)
mov r0, rINST @ r0<- &fp[A] (free up rINST)
FETCH_ADVANCE_INST 1 @ advance rPC, load rINST
- add r10, r2, r10 @ r10<- r10 + low(ZxW + (YxX))
+ add r2, r2, lr @ r2<- r2 + low(ZxW + (YxX))
GET_INST_OPCODE ip @ extract opcode from rINST
- stmia r0, {r9-r10} @ vAA/vAA+1<- r9/r10
+ stmia r0, {r1-r2} @ vAA/vAA+1<- r1/r2
GOTO_OPCODE ip @ jump to next instruction
/* ------------------------------ */
@@ -7616,27 +7334,6 @@
.balign 4
artMterpAsmSisterStart:
-/* continuation for op_cmp_long */
-
-.Lop_cmp_long_less:
- mvn r1, #0 @ r1<- -1
- @ Want to cond code the next mov so we can avoid branch, but don't see it;
- @ instead, we just replicate the tail end.
- FETCH_ADVANCE_INST 2 @ advance rPC, load rINST
- SET_VREG r1, r9 @ vAA<- r1
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-
-.Lop_cmp_long_greater:
- mov r1, #1 @ r1<- 1
- @ fall through to _finish
-
-.Lop_cmp_long_finish:
- FETCH_ADVANCE_INST 2 @ advance rPC, load rINST
- SET_VREG r1, r9 @ vAA<- r1
- GET_INST_OPCODE ip @ extract opcode from rINST
- GOTO_OPCODE ip @ jump to next instruction
-
/* continuation for op_float_to_long */
/*
* Convert the float in r0 to a long in r0/r1.
@@ -12207,21 +11904,117 @@
/* NOTE: no fallthrough */
/*
- * Check for suspend check request. Assumes rINST already loaded, rPC advanced and
- * still needs to get the opcode and branch to it, and flags are in lr.
+ * Common handling for branches with support for Jit profiling.
+ * On entry:
+ * rINST <= signed offset
+ * rPROFILE <= signed hotness countdown (expanded to 32 bits)
+ * condition bits <= set to establish sign of offset (use "NoFlags" entry if not)
+ *
+ * We have quite a few different cases for branch profiling, OSR detection and
+ * suspend check support here.
+ *
+ * Taken backward branches:
+ * If profiling active, do hotness countdown and report if we hit zero.
+ * If in osr check mode, see if our target is a compiled loop header entry and do OSR if so.
+ * Is there a pending suspend request? If so, suspend.
+ *
+ * Taken forward branches and not-taken backward branches:
+ * If in osr check mode, see if our target is a compiled loop header entry and do OSR if so.
+ *
+ * Our most common case is expected to be a taken backward branch with active jit profiling,
+ * but no full OSR check and no pending suspend request.
+ * Next most common case is not-taken branch with no full OSR check.
+ *
*/
-MterpCheckSuspendAndContinue:
- ldr rIBASE, [rSELF, #THREAD_CURRENT_IBASE_OFFSET] @ refresh rIBASE
+MterpCommonTakenBranchNoFlags:
+ cmp rINST, #0
+MterpCommonTakenBranch:
+ bgt .L_forward_branch @ don't add forward branches to hotness
+/*
+ * We need to subtract 1 from positive values and we should not see 0 here,
+ * so we may use the result of the comparison with -1.
+ */
+#if JIT_CHECK_OSR != -1
+# error "JIT_CHECK_OSR must be -1."
+#endif
+ cmp rPROFILE, #JIT_CHECK_OSR
+ beq .L_osr_check
+ subgts rPROFILE, #1
+ beq .L_add_batch @ counted down to zero - report
+.L_resume_backward_branch:
+ ldr lr, [rSELF, #THREAD_FLAGS_OFFSET]
+ REFRESH_IBASE
+ add r2, rINST, rINST @ r2<- byte offset
+ FETCH_ADVANCE_INST_RB r2 @ update rPC, load rINST
ands lr, #(THREAD_SUSPEND_REQUEST | THREAD_CHECKPOINT_REQUEST)
- bne 1f
+ bne .L_suspend_request_pending
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
-1:
+
+.L_suspend_request_pending:
EXPORT_PC
mov r0, rSELF
bl MterpSuspendCheck @ (self)
cmp r0, #0
bne MterpFallback
+ REFRESH_IBASE @ might have changed during suspend
+ GET_INST_OPCODE ip @ extract opcode from rINST
+ GOTO_OPCODE ip @ jump to next instruction
+
+.L_no_count_backwards:
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ bne .L_resume_backward_branch
+.L_osr_check:
+ mov r0, rSELF
+ add r1, rFP, #OFF_FP_SHADOWFRAME
+ mov r2, rINST
+ EXPORT_PC
+ bl MterpMaybeDoOnStackReplacement @ (self, shadow_frame, offset)
+ cmp r0, #0
+ bne MterpOnStackReplacement
+ b .L_resume_backward_branch
+
+.L_forward_branch:
+ cmp rPROFILE, #JIT_CHECK_OSR @ possible OSR re-entry?
+ beq .L_check_osr_forward
+.L_resume_forward_branch:
+ add r2, rINST, rINST @ r2<- byte offset
+ FETCH_ADVANCE_INST_RB r2 @ update rPC, load rINST
+ GET_INST_OPCODE ip @ extract opcode from rINST
+ GOTO_OPCODE ip @ jump to next instruction
+
+.L_check_osr_forward:
+ mov r0, rSELF
+ add r1, rFP, #OFF_FP_SHADOWFRAME
+ mov r2, rINST
+ EXPORT_PC
+ bl MterpMaybeDoOnStackReplacement @ (self, shadow_frame, offset)
+ cmp r0, #0
+ bne MterpOnStackReplacement
+ b .L_resume_forward_branch
+
+.L_add_batch:
+ add r1, rFP, #OFF_FP_SHADOWFRAME
+ strh rPROFILE, [r1, #SHADOWFRAME_HOTNESS_COUNTDOWN_OFFSET]
+ ldr r0, [rFP, #OFF_FP_METHOD]
+ mov r2, rSELF
+ bl MterpAddHotnessBatch @ (method, shadow_frame, self)
+ mov rPROFILE, r0 @ restore new hotness countdown to rPROFILE
+ b .L_no_count_backwards
+
+/*
+ * Entered from the conditional branch handlers when OSR check request active on
+ * not-taken path. All Dalvik not-taken conditional branch offsets are 2.
+ */
+.L_check_not_taken_osr:
+ mov r0, rSELF
+ add r1, rFP, #OFF_FP_SHADOWFRAME
+ mov r2, #2
+ EXPORT_PC
+ bl MterpMaybeDoOnStackReplacement @ (self, shadow_frame, offset)
+ cmp r0, #0
+ bne MterpOnStackReplacement
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip @ extract opcode from rINST
GOTO_OPCODE ip @ jump to next instruction
@@ -12269,9 +12062,27 @@
str r1, [r2, #4]
mov r0, #1 @ signal return to caller.
MterpDone:
- add sp, sp, #4 @ un-align 64
- ldmfd sp!, {r4-r10,fp,pc} @ restore 9 regs and return
+/*
+ * At this point, we expect rPROFILE to be non-zero. If negative, hotness is disabled or we're
+ * checking for OSR. If greater than zero, we might have unreported hotness to register
+ * (the difference between the ending rPROFILE and the cached hotness counter). rPROFILE
+ * should only reach zero immediately after a hotness decrement, and is then reset to either
+ * a negative special state or the new non-zero countdown value.
+ */
+ cmp rPROFILE, #0
+ bgt MterpProfileActive @ if > 0, we may have some counts to report.
+ ldmfd sp!, {r3-r10,fp,pc} @ restore 10 regs and return
+MterpProfileActive:
+ mov rINST, r0 @ stash return value
+ /* Report cached hotness counts */
+ ldr r0, [rFP, #OFF_FP_METHOD]
+ add r1, rFP, #OFF_FP_SHADOWFRAME
+ mov r2, rSELF
+ strh rPROFILE, [r1, #SHADOWFRAME_HOTNESS_COUNTDOWN_OFFSET]
+ bl MterpAddHotnessBatch @ (method, shadow_frame, self)
+ mov r0, rINST @ restore return value
+ ldmfd sp!, {r3-r10,fp,pc} @ restore 10 regs and return
.fnend
.size ExecuteMterpImpl, .-ExecuteMterpImpl
diff --git a/runtime/interpreter/mterp/out/mterp_arm64.S b/runtime/interpreter/mterp/out/mterp_arm64.S
index 6ae59d8..55797e6 100644
--- a/runtime/interpreter/mterp/out/mterp_arm64.S
+++ b/runtime/interpreter/mterp/out/mterp_arm64.S
@@ -81,6 +81,7 @@
x23 xINST first 16-bit code unit of current instruction
x24 xIBASE interpreted instruction base pointer, used for computed goto
x25 xREFS base of object references in shadow frame (ideally, we'll get rid of this later).
+ x26 wPROFILE jit profile hotness countdown
x16 ip scratch reg
x17 ip2 scratch reg (used by macros)
@@ -99,15 +100,17 @@
/* During bringup, we'll use the shadow frame model instead of xFP */
/* single-purpose registers, given names for clarity */
-#define xPC x20
-#define xFP x21
-#define xSELF x22
-#define xINST x23
-#define wINST w23
-#define xIBASE x24
-#define xREFS x25
-#define ip x16
-#define ip2 x17
+#define xPC x20
+#define xFP x21
+#define xSELF x22
+#define xINST x23
+#define wINST w23
+#define xIBASE x24
+#define xREFS x25
+#define wPROFILE w26
+#define xPROFILE x26
+#define ip x16
+#define ip2 x17
/*
* Instead of holding a pointer to the shadow frame, we keep xFP at the base of the vregs. So,
@@ -121,7 +124,7 @@
#define OFF_FP_RESULT_REGISTER OFF_FP(SHADOWFRAME_RESULT_REGISTER_OFFSET)
#define OFF_FP_DEX_PC_PTR OFF_FP(SHADOWFRAME_DEX_PC_PTR_OFFSET)
#define OFF_FP_CODE_ITEM OFF_FP(SHADOWFRAME_CODE_ITEM_OFFSET)
-#define OFF_FP_SHADOWFRAME (-SHADOWFRAME_VREGS_OFFSET)
+#define OFF_FP_SHADOWFRAME OFF_FP(0)
/*
* "export" the PC to dex_pc field in the shadow frame, f/b/o future exception objects. Must
@@ -323,11 +326,12 @@
ExecuteMterpImpl:
.cfi_startproc
- stp xIBASE, xREFS, [sp, #-64]!
- stp xSELF, xINST, [sp, #16]
- stp xPC, xFP, [sp, #32]
- stp fp, lr, [sp, #48]
- add fp, sp, #48
+ stp xPROFILE, x27, [sp, #-80]!
+ stp xIBASE, xREFS, [sp, #16]
+ stp xSELF, xINST, [sp, #32]
+ stp xPC, xFP, [sp, #48]
+ stp fp, lr, [sp, #64]
+ add fp, sp, #64
/* Remember the return register */
str x3, [x2, #SHADOWFRAME_RESULT_REGISTER_OFFSET]
@@ -348,6 +352,12 @@
/* Starting ibase */
ldr xIBASE, [xSELF, #THREAD_CURRENT_IBASE_OFFSET]
+ /* Set up for backwards branches & osr profiling */
+ ldr x0, [xFP, #OFF_FP_METHOD]
+ add x1, xFP, #OFF_FP_SHADOWFRAME
+ bl MterpSetUpHotnessCountdown
+ mov wPROFILE, w0 // Starting hotness countdown to xPROFILE
+
/* start executing the instruction at rPC */
FETCH_INST // load wINST from rPC
GET_INST_OPCODE ip // extract opcode from wINST
@@ -1081,24 +1091,8 @@
* double to get a byte offset.
*/
/* goto +AA */
- /* tuning: use sbfx for 6t2+ targets */
- lsl w0, wINST, #16 // w0<- AAxx0000
- asr wINST, w0, #24 // wINST<- ssssssAA (sign-extended)
-#if MTERP_PROFILE_BRANCHES
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in wINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET] // Preload flags for MterpCheckSuspendAndContinue
- adds w1, wINST, wINST // Convert dalvik offset to byte offset, setting flags
- FETCH_ADVANCE_INST_RB w1 // load wINST and advance xPC
- // If backwards branch refresh rIBASE
- b.mi MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip // extract opcode from wINST
- GOTO_OPCODE ip // jump to next instruction
+ sbfx wINST, wINST, #8, #8 // wINST<- ssssssAA (sign-extended)
+ b MterpCommonTakenBranchNoFlags
/* ------------------------------ */
.balign 128
@@ -1112,20 +1106,7 @@
*/
/* goto/16 +AAAA */
FETCH_S wINST, 1 // wINST<- ssssAAAA (sign-extended)
-#if MTERP_PROFILE_BRANCHES
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in xINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w1, wINST, wINST // w1<- byte offset, flags set
- FETCH_ADVANCE_INST_RB w1 // update rPC, load rINST
- b.mi MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip // extract opcode from rINST
- GOTO_OPCODE ip // jump to next instruction
+ b MterpCommonTakenBranchNoFlags
/* ------------------------------ */
.balign 128
@@ -1146,20 +1127,7 @@
FETCH w0, 1 // w0<- aaaa (lo)
FETCH w1, 2 // w1<- AAAA (hi)
orr wINST, w0, w1, lsl #16 // wINST<- AAAAaaaa
-#if MTERP_PROFILE_BRANCHES
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in xINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w1, wINST, wINST // w1<- byte offset
- FETCH_ADVANCE_INST_RB w1 // update rPC, load xINST
- b.le MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip // extract opcode from xINST
- GOTO_OPCODE ip // jump to next instruction
+ b MterpCommonTakenBranchNoFlags
/* ------------------------------ */
.balign 128
@@ -1183,20 +1151,7 @@
add x0, xPC, w0, lsl #1 // w0<- PC + BBBBbbbb*2
bl MterpDoPackedSwitch // w0<- code-unit branch offset
sbfm xINST, x0, 0, 31
-#if MTERP_PROFILE_BRANCHES
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- mov x2, xINST
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w1, wINST, wINST // w1<- byte offset; clear V
- FETCH_ADVANCE_INST_RB w1 // update rPC, load wINST
- b.le MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip // extract opcode from wINST
- GOTO_OPCODE ip // jump to next instruction
+ b MterpCommonTakenBranchNoFlags
/* ------------------------------ */
.balign 128
@@ -1221,20 +1176,7 @@
add x0, xPC, w0, lsl #1 // w0<- PC + BBBBbbbb*2
bl MterpDoSparseSwitch // w0<- code-unit branch offset
sbfm xINST, x0, 0, 31
-#if MTERP_PROFILE_BRANCHES
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- mov x2, xINST
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w1, wINST, wINST // w1<- byte offset; clear V
- FETCH_ADVANCE_INST_RB w1 // update rPC, load wINST
- b.le MterpCheckSuspendAndContinue
- GET_INST_OPCODE ip // extract opcode from wINST
- GOTO_OPCODE ip // jump to next instruction
+ b MterpCommonTakenBranchNoFlags
/* ------------------------------ */
@@ -1365,9 +1307,8 @@
/* File: arm64/op_if_eq.S */
/* File: arm64/bincmp.S */
/*
- * Generic two-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic two-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* For: if-eq, if-ne, if-lt, if-ge, if-gt, if-le
*/
@@ -1376,23 +1317,12 @@
ubfx w0, wINST, #8, #4 // w0<- A
GET_VREG w3, w1 // w3<- vB
GET_VREG w2, w0 // w2<- vA
- FETCH_S w1, 1 // w1<- branch offset, in code units
- mov w0, #2 // Offset if branch not taken
+ FETCH_S wINST, 1 // wINST<- branch offset, in code units
cmp w2, w3 // compare (vA, vB)
- csel wINST, w1, w0, eq // Branch if true, stashing result in callee save reg.
-#if MTERP_PROFILE_BRANCHES
- // TUINING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31 // Sign extend branch offset
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in xINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w2, wINST, wINST // convert to bytes, check sign
- FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
- b.mi MterpCheckSuspendAndContinue
+ b.eq MterpCommonTakenBranchNoFlags
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.eq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip // extract opcode from wINST
GOTO_OPCODE ip // jump to next instruction
@@ -1403,9 +1333,8 @@
/* File: arm64/op_if_ne.S */
/* File: arm64/bincmp.S */
/*
- * Generic two-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic two-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* For: if-eq, if-ne, if-lt, if-ge, if-gt, if-le
*/
@@ -1414,23 +1343,12 @@
ubfx w0, wINST, #8, #4 // w0<- A
GET_VREG w3, w1 // w3<- vB
GET_VREG w2, w0 // w2<- vA
- FETCH_S w1, 1 // w1<- branch offset, in code units
- mov w0, #2 // Offset if branch not taken
+ FETCH_S wINST, 1 // wINST<- branch offset, in code units
cmp w2, w3 // compare (vA, vB)
- csel wINST, w1, w0, ne // Branch if true, stashing result in callee save reg.
-#if MTERP_PROFILE_BRANCHES
- // TUINING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31 // Sign extend branch offset
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in xINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w2, wINST, wINST // convert to bytes, check sign
- FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
- b.mi MterpCheckSuspendAndContinue
+ b.ne MterpCommonTakenBranchNoFlags
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.eq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip // extract opcode from wINST
GOTO_OPCODE ip // jump to next instruction
@@ -1441,9 +1359,8 @@
/* File: arm64/op_if_lt.S */
/* File: arm64/bincmp.S */
/*
- * Generic two-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic two-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* For: if-eq, if-ne, if-lt, if-ge, if-gt, if-le
*/
@@ -1452,23 +1369,12 @@
ubfx w0, wINST, #8, #4 // w0<- A
GET_VREG w3, w1 // w3<- vB
GET_VREG w2, w0 // w2<- vA
- FETCH_S w1, 1 // w1<- branch offset, in code units
- mov w0, #2 // Offset if branch not taken
+ FETCH_S wINST, 1 // wINST<- branch offset, in code units
cmp w2, w3 // compare (vA, vB)
- csel wINST, w1, w0, lt // Branch if true, stashing result in callee save reg.
-#if MTERP_PROFILE_BRANCHES
- // TUINING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31 // Sign extend branch offset
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in xINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w2, wINST, wINST // convert to bytes, check sign
- FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
- b.mi MterpCheckSuspendAndContinue
+ b.lt MterpCommonTakenBranchNoFlags
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.eq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip // extract opcode from wINST
GOTO_OPCODE ip // jump to next instruction
@@ -1479,9 +1385,8 @@
/* File: arm64/op_if_ge.S */
/* File: arm64/bincmp.S */
/*
- * Generic two-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic two-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* For: if-eq, if-ne, if-lt, if-ge, if-gt, if-le
*/
@@ -1490,23 +1395,12 @@
ubfx w0, wINST, #8, #4 // w0<- A
GET_VREG w3, w1 // w3<- vB
GET_VREG w2, w0 // w2<- vA
- FETCH_S w1, 1 // w1<- branch offset, in code units
- mov w0, #2 // Offset if branch not taken
+ FETCH_S wINST, 1 // wINST<- branch offset, in code units
cmp w2, w3 // compare (vA, vB)
- csel wINST, w1, w0, ge // Branch if true, stashing result in callee save reg.
-#if MTERP_PROFILE_BRANCHES
- // TUINING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31 // Sign extend branch offset
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in xINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w2, wINST, wINST // convert to bytes, check sign
- FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
- b.mi MterpCheckSuspendAndContinue
+ b.ge MterpCommonTakenBranchNoFlags
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.eq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip // extract opcode from wINST
GOTO_OPCODE ip // jump to next instruction
@@ -1517,9 +1411,8 @@
/* File: arm64/op_if_gt.S */
/* File: arm64/bincmp.S */
/*
- * Generic two-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic two-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* For: if-eq, if-ne, if-lt, if-ge, if-gt, if-le
*/
@@ -1528,23 +1421,12 @@
ubfx w0, wINST, #8, #4 // w0<- A
GET_VREG w3, w1 // w3<- vB
GET_VREG w2, w0 // w2<- vA
- FETCH_S w1, 1 // w1<- branch offset, in code units
- mov w0, #2 // Offset if branch not taken
+ FETCH_S wINST, 1 // wINST<- branch offset, in code units
cmp w2, w3 // compare (vA, vB)
- csel wINST, w1, w0, gt // Branch if true, stashing result in callee save reg.
-#if MTERP_PROFILE_BRANCHES
- // TUINING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31 // Sign extend branch offset
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in xINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w2, wINST, wINST // convert to bytes, check sign
- FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
- b.mi MterpCheckSuspendAndContinue
+ b.gt MterpCommonTakenBranchNoFlags
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.eq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip // extract opcode from wINST
GOTO_OPCODE ip // jump to next instruction
@@ -1555,9 +1437,8 @@
/* File: arm64/op_if_le.S */
/* File: arm64/bincmp.S */
/*
- * Generic two-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic two-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* For: if-eq, if-ne, if-lt, if-ge, if-gt, if-le
*/
@@ -1566,23 +1447,12 @@
ubfx w0, wINST, #8, #4 // w0<- A
GET_VREG w3, w1 // w3<- vB
GET_VREG w2, w0 // w2<- vA
- FETCH_S w1, 1 // w1<- branch offset, in code units
- mov w0, #2 // Offset if branch not taken
+ FETCH_S wINST, 1 // wINST<- branch offset, in code units
cmp w2, w3 // compare (vA, vB)
- csel wINST, w1, w0, le // Branch if true, stashing result in callee save reg.
-#if MTERP_PROFILE_BRANCHES
- // TUINING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31 // Sign extend branch offset
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in xINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w2, wINST, wINST // convert to bytes, check sign
- FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
- b.mi MterpCheckSuspendAndContinue
+ b.le MterpCommonTakenBranchNoFlags
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.eq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip // extract opcode from wINST
GOTO_OPCODE ip // jump to next instruction
@@ -1593,32 +1463,20 @@
/* File: arm64/op_if_eqz.S */
/* File: arm64/zcmp.S */
/*
- * Generic one-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic one-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* for: if-eqz, if-nez, if-ltz, if-gez, if-gtz, if-lez
*/
/* if-cmp vAA, +BBBB */
lsr w0, wINST, #8 // w0<- AA
GET_VREG w2, w0 // w2<- vAA
- FETCH_S w1, 1 // w1<- branch offset, in code units
- mov w0, #2 // Branch offset if not taken
+ FETCH_S wINST, 1 // w1<- branch offset, in code units
cmp w2, #0 // compare (vA, 0)
- csel wINST, w1, w0, eq // Branch if true, stashing result in callee save reg
-#if MTERP_PROFILE_BRANCHES
- // TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in wINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w2, wINST, wINST // convert to bytes & set flags
- FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
- b.mi MterpCheckSuspendAndContinue
+ b.eq MterpCommonTakenBranchNoFlags
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.eq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip // extract opcode from wINST
GOTO_OPCODE ip // jump to next instruction
@@ -1629,32 +1487,20 @@
/* File: arm64/op_if_nez.S */
/* File: arm64/zcmp.S */
/*
- * Generic one-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic one-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* for: if-eqz, if-nez, if-ltz, if-gez, if-gtz, if-lez
*/
/* if-cmp vAA, +BBBB */
lsr w0, wINST, #8 // w0<- AA
GET_VREG w2, w0 // w2<- vAA
- FETCH_S w1, 1 // w1<- branch offset, in code units
- mov w0, #2 // Branch offset if not taken
+ FETCH_S wINST, 1 // w1<- branch offset, in code units
cmp w2, #0 // compare (vA, 0)
- csel wINST, w1, w0, ne // Branch if true, stashing result in callee save reg
-#if MTERP_PROFILE_BRANCHES
- // TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in wINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w2, wINST, wINST // convert to bytes & set flags
- FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
- b.mi MterpCheckSuspendAndContinue
+ b.ne MterpCommonTakenBranchNoFlags
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.eq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip // extract opcode from wINST
GOTO_OPCODE ip // jump to next instruction
@@ -1665,32 +1511,20 @@
/* File: arm64/op_if_ltz.S */
/* File: arm64/zcmp.S */
/*
- * Generic one-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic one-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* for: if-eqz, if-nez, if-ltz, if-gez, if-gtz, if-lez
*/
/* if-cmp vAA, +BBBB */
lsr w0, wINST, #8 // w0<- AA
GET_VREG w2, w0 // w2<- vAA
- FETCH_S w1, 1 // w1<- branch offset, in code units
- mov w0, #2 // Branch offset if not taken
+ FETCH_S wINST, 1 // w1<- branch offset, in code units
cmp w2, #0 // compare (vA, 0)
- csel wINST, w1, w0, lt // Branch if true, stashing result in callee save reg
-#if MTERP_PROFILE_BRANCHES
- // TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in wINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w2, wINST, wINST // convert to bytes & set flags
- FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
- b.mi MterpCheckSuspendAndContinue
+ b.lt MterpCommonTakenBranchNoFlags
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.eq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip // extract opcode from wINST
GOTO_OPCODE ip // jump to next instruction
@@ -1701,32 +1535,20 @@
/* File: arm64/op_if_gez.S */
/* File: arm64/zcmp.S */
/*
- * Generic one-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic one-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* for: if-eqz, if-nez, if-ltz, if-gez, if-gtz, if-lez
*/
/* if-cmp vAA, +BBBB */
lsr w0, wINST, #8 // w0<- AA
GET_VREG w2, w0 // w2<- vAA
- FETCH_S w1, 1 // w1<- branch offset, in code units
- mov w0, #2 // Branch offset if not taken
+ FETCH_S wINST, 1 // w1<- branch offset, in code units
cmp w2, #0 // compare (vA, 0)
- csel wINST, w1, w0, ge // Branch if true, stashing result in callee save reg
-#if MTERP_PROFILE_BRANCHES
- // TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in wINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w2, wINST, wINST // convert to bytes & set flags
- FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
- b.mi MterpCheckSuspendAndContinue
+ b.ge MterpCommonTakenBranchNoFlags
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.eq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip // extract opcode from wINST
GOTO_OPCODE ip // jump to next instruction
@@ -1737,32 +1559,20 @@
/* File: arm64/op_if_gtz.S */
/* File: arm64/zcmp.S */
/*
- * Generic one-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic one-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* for: if-eqz, if-nez, if-ltz, if-gez, if-gtz, if-lez
*/
/* if-cmp vAA, +BBBB */
lsr w0, wINST, #8 // w0<- AA
GET_VREG w2, w0 // w2<- vAA
- FETCH_S w1, 1 // w1<- branch offset, in code units
- mov w0, #2 // Branch offset if not taken
+ FETCH_S wINST, 1 // w1<- branch offset, in code units
cmp w2, #0 // compare (vA, 0)
- csel wINST, w1, w0, gt // Branch if true, stashing result in callee save reg
-#if MTERP_PROFILE_BRANCHES
- // TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in wINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w2, wINST, wINST // convert to bytes & set flags
- FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
- b.mi MterpCheckSuspendAndContinue
+ b.gt MterpCommonTakenBranchNoFlags
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.eq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip // extract opcode from wINST
GOTO_OPCODE ip // jump to next instruction
@@ -1773,32 +1583,20 @@
/* File: arm64/op_if_lez.S */
/* File: arm64/zcmp.S */
/*
- * Generic one-operand compare-and-branch operation. Provide a "revcmp"
- * fragment that specifies the *reverse* comparison to perform, e.g.
- * for "if-le" you would use "gt".
+ * Generic one-operand compare-and-branch operation. Provide a "condition"
+ * fragment that specifies the comparison to perform.
*
* for: if-eqz, if-nez, if-ltz, if-gez, if-gtz, if-lez
*/
/* if-cmp vAA, +BBBB */
lsr w0, wINST, #8 // w0<- AA
GET_VREG w2, w0 // w2<- vAA
- FETCH_S w1, 1 // w1<- branch offset, in code units
- mov w0, #2 // Branch offset if not taken
+ FETCH_S wINST, 1 // w1<- branch offset, in code units
cmp w2, #0 // compare (vA, 0)
- csel wINST, w1, w0, le // Branch if true, stashing result in callee save reg
-#if MTERP_PROFILE_BRANCHES
- // TUNING: once measurements are complete, remove #if and hand-schedule.
- EXPORT_PC
- mov x0, xSELF
- add x1, xFP, #OFF_FP_SHADOWFRAME
- sbfm x2, xINST, 0, 31
- bl MterpProfileBranch // (self, shadow_frame, offset)
- cbnz w0, MterpOnStackReplacement // Note: offset must be in wINST
-#endif
- ldr w7, [xSELF, #THREAD_FLAGS_OFFSET]
- adds w2, wINST, wINST // convert to bytes & set flags
- FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
- b.mi MterpCheckSuspendAndContinue
+ b.le MterpCommonTakenBranchNoFlags
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.eq .L_check_not_taken_osr
+ FETCH_ADVANCE_INST 2
GET_INST_OPCODE ip // extract opcode from wINST
GOTO_OPCODE ip // jump to next instruction
@@ -11596,6 +11394,107 @@
GET_INST_OPCODE ip
GOTO_OPCODE ip
/* NOTE: no fallthrough */
+/*
+ * Common handling for branches with support for Jit profiling.
+ * On entry:
+ * wINST <= signed offset
+ * wPROFILE <= signed hotness countdown (expanded to 32 bits)
+ * condition bits <= set to establish sign of offset (use "NoFlags" entry if not)
+ *
+ * We have quite a few different cases for branch profiling, OSR detection and
+ * suspend check support here.
+ *
+ * Taken backward branches:
+ * If profiling active, do hotness countdown and report if we hit zero.
+ * If in osr check mode, see if our target is a compiled loop header entry and do OSR if so.
+ * Is there a pending suspend request? If so, suspend.
+ *
+ * Taken forward branches and not-taken backward branches:
+ * If in osr check mode, see if our target is a compiled loop header entry and do OSR if so.
+ *
+ * Our most common case is expected to be a taken backward branch with active jit profiling,
+ * but no full OSR check and no pending suspend request.
+ * Next most common case is not-taken branch with no full OSR check.
+ *
+ */
+MterpCommonTakenBranchNoFlags:
+ cmp wINST, #0
+ b.gt .L_forward_branch // don't add forward branches to hotness
+ tbnz wPROFILE, #31, .L_no_count_backwards // go if negative
+ subs wPROFILE, wPROFILE, #1 // countdown
+ b.eq .L_add_batch // counted down to zero - report
+.L_resume_backward_branch:
+ ldr lr, [xSELF, #THREAD_FLAGS_OFFSET]
+ add w2, wINST, wINST // w2<- byte offset
+ FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
+ REFRESH_IBASE
+ ands lr, lr, #(THREAD_SUSPEND_REQUEST | THREAD_CHECKPOINT_REQUEST)
+ b.ne .L_suspend_request_pending
+ GET_INST_OPCODE ip // extract opcode from wINST
+ GOTO_OPCODE ip // jump to next instruction
+
+.L_suspend_request_pending:
+ EXPORT_PC
+ mov x0, xSELF
+ bl MterpSuspendCheck // (self)
+ cbnz x0, MterpFallback
+ REFRESH_IBASE // might have changed during suspend
+ GET_INST_OPCODE ip // extract opcode from wINST
+ GOTO_OPCODE ip // jump to next instruction
+
+.L_no_count_backwards:
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.ne .L_resume_backward_branch
+ mov x0, xSELF
+ add x1, xFP, #OFF_FP_SHADOWFRAME
+ mov x2, xINST
+ EXPORT_PC
+ bl MterpMaybeDoOnStackReplacement // (self, shadow_frame, offset)
+ cbnz x0, MterpOnStackReplacement
+ b .L_resume_backward_branch
+
+.L_forward_branch:
+ cmp wPROFILE, #JIT_CHECK_OSR // possible OSR re-entry?
+ b.eq .L_check_osr_forward
+.L_resume_forward_branch:
+ add w2, wINST, wINST // w2<- byte offset
+ FETCH_ADVANCE_INST_RB w2 // update rPC, load wINST
+ GET_INST_OPCODE ip // extract opcode from wINST
+ GOTO_OPCODE ip // jump to next instruction
+
+.L_check_osr_forward:
+ mov x0, xSELF
+ add x1, xFP, #OFF_FP_SHADOWFRAME
+ mov x2, xINST
+ EXPORT_PC
+ bl MterpMaybeDoOnStackReplacement // (self, shadow_frame, offset)
+ cbnz x0, MterpOnStackReplacement
+ b .L_resume_forward_branch
+
+.L_add_batch:
+ add x1, xFP, #OFF_FP_SHADOWFRAME
+ strh wPROFILE, [x1, #SHADOWFRAME_HOTNESS_COUNTDOWN_OFFSET]
+ ldr x0, [xFP, #OFF_FP_METHOD]
+ mov x2, xSELF
+ bl MterpAddHotnessBatch // (method, shadow_frame, self)
+ mov wPROFILE, w0 // restore new hotness countdown to wPROFILE
+ b .L_no_count_backwards
+
+/*
+ * Entered from the conditional branch handlers when OSR check request active on
+ * not-taken path. All Dalvik not-taken conditional branch offsets are 2.
+ */
+.L_check_not_taken_osr:
+ mov x0, xSELF
+ add x1, xFP, #OFF_FP_SHADOWFRAME
+ mov x2, #2
+ EXPORT_PC
+ bl MterpMaybeDoOnStackReplacement // (self, shadow_frame, offset)
+ cbnz x0, MterpOnStackReplacement
+ FETCH_ADVANCE_INST 2
+ GET_INST_OPCODE ip // extract opcode from wINST
+ GOTO_OPCODE ip // jump to next instruction
+
/*
* Check for suspend check request. Assumes wINST already loaded, xPC advanced and
@@ -11664,10 +11563,36 @@
check2:
mov x0, #1 // signal return to caller.
MterpDone:
- ldp fp, lr, [sp, #48]
- ldp xPC, xFP, [sp, #32]
- ldp xSELF, xINST, [sp, #16]
- ldp xIBASE, xREFS, [sp], #64
+/*
+ * At this point, we expect wPROFILE to be non-zero. If negative, hotness is disabled or we're
+ * checking for OSR. If greater than zero, we might have unreported hotness to register
+ * (the difference between the ending wPROFILE and the cached hotness counter). wPROFILE
+ * should only reach zero immediately after a hotness decrement, and is then reset to either
+ * a negative special state or the new non-zero countdown value.
+ */
+ cmp wPROFILE, #0
+ bgt MterpProfileActive // if > 0, we may have some counts to report.
+ ldp fp, lr, [sp, #64]
+ ldp xPC, xFP, [sp, #48]
+ ldp xSELF, xINST, [sp, #32]
+ ldp xIBASE, xREFS, [sp, #16]
+ ldp xPROFILE, x27, [sp], #80
+ ret
+
+MterpProfileActive:
+ mov xINST, x0 // stash return value
+ /* Report cached hotness counts */
+ ldr x0, [xFP, #OFF_FP_METHOD]
+ add x1, xFP, #OFF_FP_SHADOWFRAME
+ mov x2, xSELF
+ strh wPROFILE, [x1, #SHADOWFRAME_HOTNESS_COUNTDOWN_OFFSET]
+ bl MterpAddHotnessBatch // (method, shadow_frame, self)
+ mov x0, xINST // restore return value
+ ldp fp, lr, [sp, #64]
+ ldp xPC, xFP, [sp, #48]
+ ldp xSELF, xINST, [sp, #32]
+ ldp xIBASE, xREFS, [sp, #16]
+ ldp xPROFILE, x27, [sp], #80
ret
.cfi_endproc
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index 73aaf04..4db9f71 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -208,7 +208,7 @@
return false;
}
bool success = jit_compile_method_(jit_compiler_handle_, method_to_compile, self, osr);
- code_cache_->DoneCompiling(method_to_compile, self);
+ code_cache_->DoneCompiling(method_to_compile, self, osr);
return success;
}
@@ -319,11 +319,6 @@
return false;
}
- if (kRuntimeISA == kMips || kRuntimeISA == kMips64) {
- VLOG(jit) << "OSR not supported on this platform: " << kRuntimeISA;
- return false;
- }
-
if (UNLIKELY(__builtin_frame_address(0) < thread->GetStackEnd())) {
// Don't attempt to do an OSR if we are close to the stack limit. Since
// the interpreter frames are still on stack, OSR has the potential
diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc
index 37ff6a5..820ae6a 100644
--- a/runtime/jit/jit_code_cache.cc
+++ b/runtime/jit/jit_code_cache.cc
@@ -927,12 +927,12 @@
return false;
}
- if (info->IsMethodBeingCompiled()) {
+ if (info->IsMethodBeingCompiled(osr)) {
VLOG(jit) << PrettyMethod(method) << " is already being compiled";
return false;
}
- info->SetIsMethodBeingCompiled(true);
+ info->SetIsMethodBeingCompiled(true, osr);
return true;
}
@@ -952,10 +952,10 @@
info->DecrementInlineUse();
}
-void JitCodeCache::DoneCompiling(ArtMethod* method, Thread* self ATTRIBUTE_UNUSED) {
+void JitCodeCache::DoneCompiling(ArtMethod* method, Thread* self ATTRIBUTE_UNUSED, bool osr) {
ProfilingInfo* info = method->GetProfilingInfo(sizeof(void*));
- DCHECK(info->IsMethodBeingCompiled());
- info->SetIsMethodBeingCompiled(false);
+ DCHECK(info->IsMethodBeingCompiled(osr));
+ info->SetIsMethodBeingCompiled(false, osr);
}
size_t JitCodeCache::GetMemorySizeOfCodePointer(const void* ptr) {
diff --git a/runtime/jit/jit_code_cache.h b/runtime/jit/jit_code_cache.h
index 6faa8f1..9f18c70 100644
--- a/runtime/jit/jit_code_cache.h
+++ b/runtime/jit/jit_code_cache.h
@@ -80,7 +80,7 @@
SHARED_REQUIRES(Locks::mutator_lock_)
REQUIRES(!lock_);
- void DoneCompiling(ArtMethod* method, Thread* self)
+ void DoneCompiling(ArtMethod* method, Thread* self, bool osr)
SHARED_REQUIRES(Locks::mutator_lock_)
REQUIRES(!lock_);
diff --git a/runtime/jit/jit_instrumentation.cc b/runtime/jit/jit_instrumentation.cc
index d751e5a..b18d6a2 100644
--- a/runtime/jit/jit_instrumentation.cc
+++ b/runtime/jit/jit_instrumentation.cc
@@ -80,9 +80,9 @@
DISALLOW_IMPLICIT_CONSTRUCTORS(JitCompileTask);
};
-JitInstrumentationCache::JitInstrumentationCache(size_t hot_method_threshold,
- size_t warm_method_threshold,
- size_t osr_method_threshold)
+JitInstrumentationCache::JitInstrumentationCache(uint16_t hot_method_threshold,
+ uint16_t warm_method_threshold,
+ uint16_t osr_method_threshold)
: hot_method_threshold_(hot_method_threshold),
warm_method_threshold_(warm_method_threshold),
osr_method_threshold_(osr_method_threshold),
@@ -130,44 +130,62 @@
}
}
-void JitInstrumentationCache::AddSamples(Thread* self, ArtMethod* method, size_t) {
+void JitInstrumentationCache::AddSamples(Thread* self, ArtMethod* method, uint16_t count) {
// Since we don't have on-stack replacement, some methods can remain in the interpreter longer
- // than we want resulting in samples even after the method is compiled.
- if (method->IsClassInitializer() || method->IsNative()) {
+ // than we want resulting in samples even after the method is compiled. Also, if the
+ // jit is no longer interested in hotness samples because we're shutting down, just return.
+ if (method->IsClassInitializer() || method->IsNative() || (thread_pool_ == nullptr)) {
+ if (thread_pool_ == nullptr) {
+ // Should only see this when shutting down.
+ DCHECK(Runtime::Current()->IsShuttingDown(self));
+ }
return;
}
DCHECK(thread_pool_ != nullptr);
+ DCHECK_GT(warm_method_threshold_, 0);
+ DCHECK_GT(hot_method_threshold_, warm_method_threshold_);
+ DCHECK_GT(osr_method_threshold_, hot_method_threshold_);
- uint16_t sample_count = method->IncrementCounter();
- if (sample_count == warm_method_threshold_) {
- bool success = ProfilingInfo::Create(self, method, /* retry_allocation */ false);
- if (success) {
- VLOG(jit) << "Start profiling " << PrettyMethod(method);
+ int32_t starting_count = method->GetCounter();
+ int32_t new_count = starting_count + count; // int32 here to avoid wrap-around;
+ if (starting_count < warm_method_threshold_) {
+ if (new_count >= warm_method_threshold_) {
+ bool success = ProfilingInfo::Create(self, method, /* retry_allocation */ false);
+ if (success) {
+ VLOG(jit) << "Start profiling " << PrettyMethod(method);
+ }
+
+ if (thread_pool_ == nullptr) {
+ // Calling ProfilingInfo::Create might put us in a suspended state, which could
+ // lead to the thread pool being deleted when we are shutting down.
+ DCHECK(Runtime::Current()->IsShuttingDown(self));
+ return;
+ }
+
+ if (!success) {
+ // We failed allocating. Instead of doing the collection on the Java thread, we push
+ // an allocation to a compiler thread, that will do the collection.
+ thread_pool_->AddTask(self, new JitCompileTask(method, JitCompileTask::kAllocateProfile));
+ }
}
-
- if (thread_pool_ == nullptr) {
- // Calling ProfilingInfo::Create might put us in a suspended state, which could
- // lead to the thread pool being deleted when we are shutting down.
- DCHECK(Runtime::Current()->IsShuttingDown(self));
- return;
+ // Avoid jumping more than one state at a time.
+ new_count = std::min(new_count, hot_method_threshold_ - 1);
+ } else if (starting_count < hot_method_threshold_) {
+ if (new_count >= hot_method_threshold_) {
+ DCHECK(thread_pool_ != nullptr);
+ thread_pool_->AddTask(self, new JitCompileTask(method, JitCompileTask::kCompile));
}
-
- if (!success) {
- // We failed allocating. Instead of doing the collection on the Java thread, we push
- // an allocation to a compiler thread, that will do the collection.
- thread_pool_->AddTask(self, new JitCompileTask(method, JitCompileTask::kAllocateProfile));
+ // Avoid jumping more than one state at a time.
+ new_count = std::min(new_count, osr_method_threshold_ - 1);
+ } else if (starting_count < osr_method_threshold_) {
+ if (new_count >= osr_method_threshold_) {
+ DCHECK(thread_pool_ != nullptr);
+ thread_pool_->AddTask(self, new JitCompileTask(method, JitCompileTask::kCompileOsr));
}
}
-
- if (sample_count == hot_method_threshold_) {
- DCHECK(thread_pool_ != nullptr);
- thread_pool_->AddTask(self, new JitCompileTask(method, JitCompileTask::kCompile));
- }
-
- if (sample_count == osr_method_threshold_) {
- DCHECK(thread_pool_ != nullptr);
- thread_pool_->AddTask(self, new JitCompileTask(method, JitCompileTask::kCompileOsr));
- }
+ // Update hotness counter, but avoid wrap around.
+ method->SetCounter(
+ std::min(new_count, static_cast<int32_t>(std::numeric_limits<uint16_t>::max())));
}
JitInstrumentationListener::JitInstrumentationListener(JitInstrumentationCache* cache)
diff --git a/runtime/jit/jit_instrumentation.h b/runtime/jit/jit_instrumentation.h
index d1c5c44..7ffd4eb 100644
--- a/runtime/jit/jit_instrumentation.h
+++ b/runtime/jit/jit_instrumentation.h
@@ -40,6 +40,8 @@
class Thread;
namespace jit {
+static constexpr int16_t kJitCheckForOSR = -1;
+static constexpr int16_t kJitHotnessDisabled = -2;
class JitInstrumentationCache;
@@ -84,7 +86,6 @@
static constexpr uint32_t kJitEvents =
instrumentation::Instrumentation::kMethodEntered |
- instrumentation::Instrumentation::kBranch |
instrumentation::Instrumentation::kInvokeVirtualOrInterface;
private:
@@ -96,25 +97,33 @@
// Keeps track of which methods are hot.
class JitInstrumentationCache {
public:
- JitInstrumentationCache(size_t hot_method_threshold,
- size_t warm_method_threshold,
- size_t osr_method_threshold);
- void AddSamples(Thread* self, ArtMethod* method, size_t samples)
+ JitInstrumentationCache(uint16_t hot_method_threshold,
+ uint16_t warm_method_threshold,
+ uint16_t osr_method_threshold);
+ void AddSamples(Thread* self, ArtMethod* method, uint16_t samples)
SHARED_REQUIRES(Locks::mutator_lock_);
void CreateThreadPool();
void DeleteThreadPool(Thread* self);
+ size_t OSRMethodThreshold() const {
+ return osr_method_threshold_;
+ }
+
size_t HotMethodThreshold() const {
return hot_method_threshold_;
}
+ size_t WarmMethodThreshold() const {
+ return warm_method_threshold_;
+ }
+
// Wait until there is no more pending compilation tasks.
void WaitForCompilationToFinish(Thread* self);
private:
- size_t hot_method_threshold_;
- size_t warm_method_threshold_;
- size_t osr_method_threshold_;
+ uint16_t hot_method_threshold_;
+ uint16_t warm_method_threshold_;
+ uint16_t osr_method_threshold_;
JitInstrumentationListener listener_;
std::unique_ptr<ThreadPool> thread_pool_;
diff --git a/runtime/jit/profiling_info.h b/runtime/jit/profiling_info.h
index 55d627a..3a71bba 100644
--- a/runtime/jit/profiling_info.h
+++ b/runtime/jit/profiling_info.h
@@ -119,12 +119,18 @@
InlineCache* GetInlineCache(uint32_t dex_pc);
- bool IsMethodBeingCompiled() const {
- return is_method_being_compiled_;
+ bool IsMethodBeingCompiled(bool osr) const {
+ return osr
+ ? is_osr_method_being_compiled_
+ : is_method_being_compiled_;
}
- void SetIsMethodBeingCompiled(bool value) {
- is_method_being_compiled_ = value;
+ void SetIsMethodBeingCompiled(bool value, bool osr) {
+ if (osr) {
+ is_osr_method_being_compiled_ = value;
+ } else {
+ is_method_being_compiled_ = value;
+ }
}
void SetSavedEntryPoint(const void* entry_point) {
@@ -155,7 +161,8 @@
}
bool IsInUseByCompiler() const {
- return IsMethodBeingCompiled() || (current_inline_uses_ > 0);
+ return IsMethodBeingCompiled(/*osr*/ true) || IsMethodBeingCompiled(/*osr*/ false) ||
+ (current_inline_uses_ > 0);
}
private:
@@ -181,6 +188,7 @@
// is implicitly guarded by the JIT code cache lock.
// TODO: Make the JIT code cache lock global.
bool is_method_being_compiled_;
+ bool is_osr_method_being_compiled_;
// When the compiler inlines the method associated to this ProfilingInfo,
// it updates this counter so that the GC does not try to clear the inline caches.
diff --git a/runtime/stack.h b/runtime/stack.h
index 51f7d63..7301184 100644
--- a/runtime/stack.h
+++ b/runtime/stack.h
@@ -187,6 +187,22 @@
return (dex_pc_ptr_ == nullptr) ? dex_pc_ : dex_pc_ptr_ - code_item_->insns_;
}
+ int16_t GetCachedHotnessCountdown() const {
+ return cached_hotness_countdown_;
+ }
+
+ void SetCachedHotnessCountdown(int16_t cached_hotness_countdown) {
+ cached_hotness_countdown_ = cached_hotness_countdown;
+ }
+
+ int16_t GetHotnessCountdown() const {
+ return hotness_countdown_;
+ }
+
+ void SetHotnessCountdown(int16_t hotness_countdown) {
+ hotness_countdown_ = hotness_countdown;
+ }
+
void SetDexPC(uint32_t dex_pc) {
dex_pc_ = dex_pc;
dex_pc_ptr_ = nullptr;
@@ -397,6 +413,14 @@
return OFFSETOF_MEMBER(ShadowFrame, code_item_);
}
+ static size_t CachedHotnessCountdownOffset() {
+ return OFFSETOF_MEMBER(ShadowFrame, cached_hotness_countdown_);
+ }
+
+ static size_t HotnessCountdownOffset() {
+ return OFFSETOF_MEMBER(ShadowFrame, hotness_countdown_);
+ }
+
// Create ShadowFrame for interpreter using provided memory.
static ShadowFrame* CreateShadowFrameImpl(uint32_t num_vregs,
ShadowFrame* link,
@@ -406,7 +430,7 @@
return new (memory) ShadowFrame(num_vregs, link, method, dex_pc, true);
}
- uint16_t* GetDexPCPtr() {
+ const uint16_t* GetDexPCPtr() {
return dex_pc_ptr_;
}
@@ -443,11 +467,13 @@
ShadowFrame* link_;
ArtMethod* method_;
JValue* result_register_;
- uint16_t* dex_pc_ptr_;
+ const uint16_t* dex_pc_ptr_;
const DexFile::CodeItem* code_item_;
LockCountData lock_count_data_; // This may contain GC roots when lock counting is active.
const uint32_t number_of_vregs_;
uint32_t dex_pc_;
+ int16_t cached_hotness_countdown_;
+ int16_t hotness_countdown_;
// This is a two-part array:
// - [0..number_of_vregs) holds the raw virtual registers, and each element here is always 4
diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar
index d13d990..ac6ef8c 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -358,7 +358,7 @@
# in 512 byte blocks and set it as the ulimit. This should be more than enough
# room.
if [ ! `uname` = "Darwin" ]; then # TODO: Darwin doesn't support "du -B..."
- ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework | tail -1 | cut -f1) || exit 1
+ ulimit -S $(du -c -B512 ${ANDROID_HOST_OUT}/framework 2>/dev/null | tail -1 | cut -f1) || exit 1
fi
fi
else
diff --git a/tools/libcore_failures.txt b/tools/libcore_failures.txt
index 2533ce2..38b6ea6 100644
--- a/tools/libcore_failures.txt
+++ b/tools/libcore_failures.txt
@@ -267,6 +267,24 @@
"libcore.util.NativeAllocationRegistryTest#testNullArguments"]
},
{
+ description: "libnativehelper_compat_libc++.so not found by dlopen on ARM64",
+ result: EXEC_FAILED,
+ modes: [device],
+ bug: 28082914,
+ names: ["libcore.java.lang.ThreadTest#testContextClassLoaderIsInherited",
+ "libcore.java.lang.ThreadTest#testContextClassLoaderIsNotNull",
+ "libcore.java.lang.ThreadTest#testGetAllStackTracesIncludesAllGroups",
+ "libcore.java.lang.ThreadTest#testGetStackTrace",
+ "libcore.java.lang.ThreadTest#testJavaContextClassLoader",
+ "libcore.java.lang.ThreadTest#testLeakingStartedThreads",
+ "libcore.java.lang.ThreadTest#testLeakingUnstartedThreads",
+ "libcore.java.lang.ThreadTest#testNativeThreadNames",
+ "libcore.java.lang.ThreadTest#testThreadInterrupted",
+ "libcore.java.lang.ThreadTest#testThreadSleep",
+ "libcore.java.lang.ThreadTest#testThreadSleepIllegalArguments",
+ "libcore.java.lang.ThreadTest#testThreadWakeup"]
+},
+{
description: "Only work with --mode=activity",
result: EXEC_FAILED,
names: [ "libcore.java.io.FileTest#testJavaIoTmpdirMutable" ]