Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(611)

Unified Diff: runtime/vm/assembler_x64.cc

Issue 1241863002: VM: Refactor allocation stats code and remove duplicate code. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: make context allocation isolate-independent Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/assembler_x64.cc
diff --git a/runtime/vm/assembler_x64.cc b/runtime/vm/assembler_x64.cc
index 7477651e67e5ae985df53a16da4e542fcb9176f5..f6fa80af9031e5c2787001baf7bf4d8334988103 100644
--- a/runtime/vm/assembler_x64.cc
+++ b/runtime/vm/assembler_x64.cc
@@ -3438,111 +3438,80 @@ void Assembler::LeaveStubFrame() {
}
-void Assembler::ComputeCounterAddressesForCid(intptr_t cid,
- Heap::Space space,
- Address* count_address,
- Address* size_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 count_field_offset = (space == Heap::kNew)
- ? ClassHeapStats::allocated_since_gc_new_space_offset()
- : ClassHeapStats::allocated_since_gc_old_space_offset();
- const uword size_field_offset = (space == Heap::kNew)
- ? ClassHeapStats::allocated_size_since_gc_new_space_offset()
- : ClassHeapStats::allocated_size_since_gc_old_space_offset();
- movq(temp_reg, Immediate(class_heap_stats_table_address + class_offset));
- *count_address = Address(temp_reg, count_field_offset);
- *size_address = Address(temp_reg, size_field_offset);
-}
-
-
-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);
+ intptr_t state_offset;
+ ClassTable* class_table = Isolate::Current()->class_table();
+ ClassHeapStats** table_ptr =
+ class_table->StateAddressFor(cid, &state_offset);
+ Register temp_reg = TMP;
if (cid < kNumPredefinedCids) {
- ComputeHeapStatsStateAddressForCid(cid, &state_address);
+ movq(temp_reg, Immediate(reinterpret_cast<uword>(*table_ptr)));
} 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()));
+ movq(temp_reg, Immediate(reinterpret_cast<uword>(table_ptr)));
+ movq(temp_reg, Address(temp_reg, 0));
+ }
+ testb(Address(temp_reg, state_offset),
+ 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) {
+ClassHeapStats** Assembler::UpdateAllocationStats(intptr_t cid,
+ Heap::Space space,
+ bool inline_isolate) {
ASSERT(cid > 0);
- if (cid < kNumPredefinedCids) {
- Address count_address(kNoRegister, 0), size_address(kNoRegister, 0);
- ComputeCounterAddressesForCid(cid, space, &count_address, &size_address);
- incq(count_address);
+ intptr_t counter_offset;
+ ClassTable* class_table = Isolate::Current()->class_table();
+ ClassHeapStats** table_ptr = class_table->CountAddressFor(
+ cid, space == Heap::kNew, &counter_offset);
+ Register temp_reg = TMP;
+ if (cid < kNumPredefinedCids && inline_isolate) {
+ movq(temp_reg, Immediate(reinterpret_cast<uword>(*table_ptr)));
} else {
- Register temp_reg = TMP;
- const uword class_offset = cid * sizeof(ClassHeapStats); // NOLINT
- const uword count_field_offset = (space == Heap::kNew)
- ? ClassHeapStats::allocated_since_gc_new_space_offset()
- : ClassHeapStats::allocated_since_gc_old_space_offset();
- ClassTable* class_table = Isolate::Current()->class_table();
- movq(temp_reg, Immediate(class_table->ClassStatsTableAddress()));
- movq(temp_reg, Address(temp_reg, 0));
- incq(Address(temp_reg, class_offset + count_field_offset));
+ if (inline_isolate) {
+ movq(temp_reg, Immediate(reinterpret_cast<uword>(table_ptr)));
+ movq(temp_reg, Address(temp_reg, 0));
+ } else {
+ LoadIsolate(temp_reg);
+ intptr_t table_offset =
+ Isolate::class_table_offset() + ClassTable::TableOffsetFor(cid);
+ movq(temp_reg, Address(temp_reg, table_offset));
+ }
}
+ incq(Address(temp_reg, counter_offset));
+ return table_ptr;
}
void Assembler::UpdateAllocationStatsWithSize(intptr_t cid,
Register size_reg,
- Heap::Space space) {
+ Heap::Space space,
+ bool inline_isolate) {
ASSERT(cid > 0);
ASSERT(cid < kNumPredefinedCids);
- Address count_address(kNoRegister, 0), size_address(kNoRegister, 0);
- ComputeCounterAddressesForCid(cid, space, &count_address, &size_address);
- incq(count_address);
- addq(size_address, size_reg);
+ UpdateAllocationStats(cid, space, inline_isolate);
+ Register temp_reg = TMP;
+ intptr_t size_offset = ClassTable::SizeOffsetFor(cid, space == Heap::kNew);
+ addq(Address(temp_reg, size_offset), size_reg);
}
void Assembler::UpdateAllocationStatsWithSize(intptr_t cid,
intptr_t size_in_bytes,
- Heap::Space space) {
+ Heap::Space space,
+ bool inline_isolate) {
ASSERT(cid > 0);
ASSERT(cid < kNumPredefinedCids);
- Address count_address(kNoRegister, 0), size_address(kNoRegister, 0);
- ComputeCounterAddressesForCid(cid, space, &count_address, &size_address);
- incq(count_address);
- addq(size_address, Immediate(size_in_bytes));
+ UpdateAllocationStats(cid, space, inline_isolate);
+ Register temp_reg = TMP;
+ intptr_t size_offset = ClassTable::SizeOffsetFor(cid, space == Heap::kNew);
+ addq(Address(temp_reg, size_offset), Immediate(size_in_bytes));
}

Powered by Google App Engine
This is Rietveld 408576698