Skip to content

Commit 8e7ffaf

Browse files
rmacnak-googlecommit-bot@chromium.org
authored andcommitted
Reland "[vm, compiler] Reduce alignment of Instructions and remove some debugging trap instructions."
Further adjustments for simarm_x64. Flutter Gallery: ARM32 Instructions(CodeSize): 6979424 -> 6771856 (-2.97%) Total(CodeSize): 10855163 -> 10363319 (-4.53%) ARM64 Instructions(CodeSize): 7334368 -> 6817312 (-7.05%) Total(CodeSize): 11505069 -> 10771431 (-6.37%) Bug: #37103 Bug: #38452 Change-Id: I2bb44e7b2c002d53830b66cf4aedc4455c815326 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/119440 Commit-Queue: Ryan Macnak <rmacnak@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
1 parent eb9480d commit 8e7ffaf

28 files changed

+133
-204
lines changed

runtime/vm/compiler/backend/code_statistics.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ void CodeStatistics::Finalize() {
167167
intptr_t function_size = assembler_->CodeSize();
168168
unaccounted_bytes_ = function_size - instruction_bytes_;
169169
ASSERT(unaccounted_bytes_ >= 0);
170+
171+
const intptr_t unaligned_bytes = Instructions::HeaderSize() + function_size;
170172
alignment_bytes_ =
171-
Utils::RoundUp(function_size, OS::PreferredCodeAlignment()) -
172-
function_size;
173+
Utils::RoundUp(unaligned_bytes, kObjectAlignment) - unaligned_bytes;
173174
assembler_ = NULL;
174175
}
175176

runtime/vm/compiler/backend/flow_graph_compiler_arm.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,9 @@ void FlowGraphCompiler::CompileGraph() {
952952

953953
VisitBlocks();
954954

955+
#if defined(DEBUG)
955956
__ bkpt(0);
957+
#endif
956958

957959
if (!skip_body_compilation()) {
958960
ASSERT(assembler()->constant_pool_allowed());

runtime/vm/compiler/backend/flow_graph_compiler_arm64.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,9 @@ void FlowGraphCompiler::CompileGraph() {
920920

921921
VisitBlocks();
922922

923+
#if defined(DEBUG)
923924
__ brk(0);
925+
#endif
924926

925927
if (!skip_body_compilation()) {
926928
ASSERT(assembler()->constant_pool_allowed());

runtime/vm/compiler/backend/flow_graph_compiler_ia32.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,9 @@ void FlowGraphCompiler::CompileGraph() {
839839
VisitBlocks();
840840

841841
if (!skip_body_compilation()) {
842+
#if defined(DEBUG)
842843
__ int3();
844+
#endif
843845
GenerateDeferredCode();
844846
}
845847
}

runtime/vm/compiler/backend/flow_graph_compiler_x64.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,9 @@ void FlowGraphCompiler::CompileGraph() {
935935
ASSERT(!block_order().is_empty());
936936
VisitBlocks();
937937

938+
#if defined(DEBUG)
938939
__ int3();
940+
#endif
939941

940942
if (!skip_body_compilation()) {
941943
ASSERT(assembler()->constant_pool_allowed());

runtime/vm/compiler/backend/il_arm.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,9 @@ static void EmitAssertBoolean(Register reg,
510510
compiler->GenerateRuntimeCall(token_pos, deopt_id,
511511
kNonBoolTypeErrorRuntimeEntry, 1, locs);
512512
// We should never return here.
513+
#if defined(DEBUG)
513514
__ bkpt(0);
515+
#endif
514516
__ Bind(&done);
515517
}
516518

runtime/vm/compiler/backend/il_arm64.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,9 @@ static void EmitAssertBoolean(Register reg,
499499
compiler->GenerateRuntimeCall(token_pos, deopt_id,
500500
kNonBoolTypeErrorRuntimeEntry, 1, locs);
501501
// We should never return here.
502+
#if defined(DEBUG)
502503
__ brk(0);
504+
#endif
503505
__ Bind(&done);
504506
}
505507

runtime/vm/compiler/backend/il_ia32.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ static void EmitAssertBoolean(Register reg,
398398
compiler->GenerateRuntimeCall(token_pos, deopt_id,
399399
kNonBoolTypeErrorRuntimeEntry, 1, locs);
400400
// We should never return here.
401+
#if defined(DEBUG)
401402
__ int3();
403+
#endif
402404
__ Bind(&done);
403405
}
404406

runtime/vm/compiler/backend/il_x64.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,9 @@ static void EmitAssertBoolean(Register reg,
527527
compiler->GenerateRuntimeCall(token_pos, deopt_id,
528528
kNonBoolTypeErrorRuntimeEntry, 1, locs);
529529
// We should never return here.
530+
#if defined(DEBUG)
530531
__ int3();
532+
#endif
531533
__ Bind(&done);
532534
}
533535

runtime/vm/compiler/relocation.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ DEFINE_FLAG(bool,
2121
false,
2222
"Generate always trampolines (for testing purposes).");
2323

24-
// The trampolines will have a 1-word object header in front of them.
24+
// The trampolines will be disguised as FreeListElement objects, with a 1-word
25+
// object header in front of the jump code.
2526
const intptr_t kOffsetInTrampoline = kWordSize;
26-
const intptr_t kTrampolineSize = OS::kMaxPreferredCodeAlignment;
27+
const intptr_t kTrampolineSize = Utils::RoundUp(
28+
kOffsetInTrampoline + PcRelativeTrampolineJumpPattern::kLengthInBytes,
29+
kObjectAlignment);
2730

2831
CodeRelocator::CodeRelocator(Thread* thread,
2932
GrowableArray<RawCode*>* code_objects,
@@ -408,7 +411,12 @@ bool CodeRelocator::IsTargetInRangeFor(UnresolvedCall* unresolved_call,
408411
static void MarkAsFreeListElement(uint8_t* trampoline_bytes,
409412
intptr_t trampoline_length) {
410413
uint32_t tags = 0;
414+
#if defined(IS_SIMARM_X64)
415+
// Account for difference in kObjectAlignment between host and target.
416+
tags = RawObject::SizeTag::update(trampoline_length * 2, tags);
417+
#else
411418
tags = RawObject::SizeTag::update(trampoline_length, tags);
419+
#endif
412420
tags = RawObject::ClassIdTag::update(kFreeListElement, tags);
413421
tags = RawObject::OldBit::update(true, tags);
414422
tags = RawObject::OldAndNotMarkedBit::update(true, tags);
@@ -464,9 +472,6 @@ void CodeRelocator::BuildTrampolinesForAlmostOutOfRangeCalls() {
464472
// buffer.
465473
auto trampoline_bytes = new uint8_t[kTrampolineSize];
466474
memset(trampoline_bytes, 0x00, kTrampolineSize);
467-
ASSERT((kOffsetInTrampoline +
468-
PcRelativeTrampolineJumpPattern::kLengthInBytes) <
469-
kTrampolineSize);
470475
auto unresolved_trampoline = new UnresolvedTrampoline{
471476
unresolved_call->callee,
472477
unresolved_call->offset_into_target,

0 commit comments

Comments
 (0)