Index: runtime/vm/assembler_x64.cc |
diff --git a/runtime/vm/assembler_x64.cc b/runtime/vm/assembler_x64.cc |
index 9058c747381e8ee6dd20affd0847d8e4790adc22..2b46d9bb4fca07400f6e293bc058845e8188352f 100644 |
--- a/runtime/vm/assembler_x64.cc |
+++ b/runtime/vm/assembler_x64.cc |
@@ -3470,6 +3470,46 @@ void Assembler::ComputeCounterAddressesForCid(intptr_t cid, |
} |
+void Assembler::ComputeHeapStatsStateAddressForCid(intptr_t cid, |
+ Address* state_address) { |
+ ASSERT(cid < kNumPredefinedCids); |
+ Register temp_reg = TMP; |
+ Isolate* isolate = Isolate::Current(); |
+ ClassTable* class_table = isolate->class_table(); |
+ const uword class_heap_stats_table_address = |
+ class_table->PredefinedClassHeapStatsTableAddress(); |
+ const uword class_offset = cid * sizeof(ClassHeapStats); // NOLINT |
+ const uword state_offset = ClassHeapStats::state_offset(); |
+ movq(temp_reg, Immediate(class_heap_stats_table_address + |
+ class_offset + |
+ state_offset)); |
+ *state_address = Address(temp_reg, 0); |
+} |
+ |
+ |
+void Assembler::MaybeTraceAllocation(intptr_t cid, |
+ Label* trace, |
+ bool near_jump) { |
+ ASSERT(cid > 0); |
+ Address state_address(kNoRegister, 0); |
+ if (cid < kNumPredefinedCids) { |
+ ComputeHeapStatsStateAddressForCid(cid, &state_address); |
+ } else { |
+ Register temp_reg = TMP; |
+ const uword class_offset = cid * sizeof(ClassHeapStats); // NOLINT |
+ const uword state_offset = ClassHeapStats::state_offset(); |
+ // temp_reg gets address of class table pointer. |
+ ClassTable* class_table = Isolate::Current()->class_table(); |
+ movq(temp_reg, Immediate(class_table->ClassStatsTableAddress())); |
+ state_address = Address(temp_reg, class_offset + state_offset); |
+ } |
+ testb(state_address, Immediate(ClassHeapStats::TraceAllocationMask())); |
+ // We are tracing for this class, jump to the trace label which will use |
+ // the allocation stub. |
+ j(NOT_ZERO, trace, near_jump); |
+} |
+ |
+ |
void Assembler::UpdateAllocationStats(intptr_t cid, |
Heap::Space space) { |
ASSERT(cid > 0); |
@@ -3522,6 +3562,10 @@ void Assembler::TryAllocate(const Class& cls, |
Register pp) { |
ASSERT(failure != NULL); |
if (FLAG_inline_alloc) { |
+ // If this allocation is traced, program will jump to failure path |
+ // (i.e. the allocation stub) which will allocate the object and trace the |
+ // allocation call site. |
+ MaybeTraceAllocation(cls.id(), failure, near_jump); |
Heap* heap = Isolate::Current()->heap(); |
const intptr_t instance_size = cls.instance_size(); |
Heap::Space space = heap->SpaceForAllocation(cls.id()); |