Skip to content

Commit fbcacd7

Browse files
rmacnak-googlecommit-bot@chromium.org
authored andcommitted
Reapply "[vm] Streamline Zones."
Fix imprecision in Zone::SizeInBytes that was finally noticed by vm/cc/AllocateZone because the size of the initial inline buffer changed. TEST=ci Bug: #47399 Change-Id: I152d24d03a59b21267a9a24e5d929b51af57af71 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215980 Reviewed-by: Siva Annamalai <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent b5c911e commit fbcacd7

28 files changed

+1720
-1897
lines changed

runtime/vm/benchmark_test.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ BENCHMARK(CorelibCompileAll) {
4848
bin::Builtin::SetNativeResolver(bin::Builtin::kCLILibrary);
4949
TransitionNativeToVM transition(thread);
5050
StackZone zone(thread);
51-
HANDLESCOPE(thread);
5251
Timer timer;
5352
timer.Start();
5453
const Error& error =
@@ -413,7 +412,6 @@ BENCHMARK_SIZE(CoreSnapshotSize) {
413412

414413
TransitionNativeToVM transition(thread);
415414
StackZone zone(thread);
416-
HANDLESCOPE(thread);
417415

418416
Api::CheckAndFinalizePendingClasses(thread);
419417

@@ -451,7 +449,6 @@ BENCHMARK_SIZE(StandaloneSnapshotSize) {
451449

452450
TransitionNativeToVM transition(thread);
453451
StackZone zone(thread);
454-
HANDLESCOPE(thread);
455452

456453
Api::CheckAndFinalizePendingClasses(thread);
457454

@@ -496,7 +493,6 @@ BENCHMARK(EnterExitIsolate) {
496493
{
497494
TransitionNativeToVM transition(thread);
498495
StackZone zone(thread);
499-
HANDLESCOPE(thread);
500496
Api::CheckAndFinalizePendingClasses(thread);
501497
}
502498
Dart_Isolate isolate = Dart_CurrentIsolate();
@@ -514,7 +510,6 @@ BENCHMARK(EnterExitIsolate) {
514510
BENCHMARK(SerializeNull) {
515511
TransitionNativeToVM transition(thread);
516512
StackZone zone(thread);
517-
HANDLESCOPE(thread);
518513
const Object& null_object = Object::Handle();
519514
const intptr_t kLoopCount = 1000000;
520515
Timer timer;
@@ -536,7 +531,6 @@ BENCHMARK(SerializeNull) {
536531
BENCHMARK(SerializeSmi) {
537532
TransitionNativeToVM transition(thread);
538533
StackZone zone(thread);
539-
HANDLESCOPE(thread);
540534
const Integer& smi_object = Integer::Handle(Smi::New(42));
541535
const intptr_t kLoopCount = 1000000;
542536
Timer timer;
@@ -558,7 +552,6 @@ BENCHMARK(SerializeSmi) {
558552
BENCHMARK(SimpleMessage) {
559553
TransitionNativeToVM transition(thread);
560554
StackZone zone(thread);
561-
HANDLESCOPE(thread);
562555
const Array& array_object = Array::Handle(Array::New(2));
563556
array_object.SetAt(0, Integer::Handle(Smi::New(42)));
564557
array_object.SetAt(1, Object::Handle());
@@ -592,7 +585,6 @@ BENCHMARK(LargeMap) {
592585
EXPECT_VALID(h_result);
593586
TransitionNativeToVM transition(thread);
594587
StackZone zone(thread);
595-
HANDLESCOPE(thread);
596588
Instance& map = Instance::Handle();
597589
map ^= Api::UnwrapHandle(h_result);
598590
const intptr_t kLoopCount = 100;

runtime/vm/class_finalizer.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,6 @@ void ClassFinalizer::ClearAllCode(bool including_nonchanging_cids) {
17311731
auto const isolate_group = thread->isolate_group();
17321732
SafepointWriteRwLocker ml(thread, isolate_group->program_lock());
17331733
StackZone stack_zone(thread);
1734-
HANDLESCOPE(thread);
17351734
auto const zone = thread->zone();
17361735

17371736
class ClearCodeVisitor : public FunctionVisitor {

runtime/vm/compiler/aot/precompiler.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3028,7 +3028,6 @@ void Precompiler::FinalizeAllClasses() {
30283028
// otherwise unreachable constants of dropped classes, which would
30293029
// cause assertion failures during GC after classes are dropped.
30303030
StackZone stack_zone(thread());
3031-
HANDLESCOPE(thread());
30323031

30333032
error_ = Library::FinalizeAllClasses();
30343033
if (!error_.IsNull()) {

runtime/vm/compiler/jit/compiler.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,6 @@ void BackgroundCompiler::Run() {
11331133
Thread* thread = Thread::Current();
11341134
StackZone stack_zone(thread);
11351135
Zone* zone = stack_zone.GetZone();
1136-
HANDLESCOPE(thread);
11371136
Function& function = Function::Handle(zone);
11381137
{
11391138
SafepointMonitorLocker ml(&queue_monitor_);

runtime/vm/compiler/runtime_offsets_extracted.h

Lines changed: 1634 additions & 1634 deletions
Large diffs are not rendered by default.

runtime/vm/dart_api_impl.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,6 @@ static Dart_Isolate CreateIsolate(IsolateGroup* group,
13011301
bool success = false;
13021302
{
13031303
StackZone zone(T);
1304-
HANDLESCOPE(T);
13051304
// We enter an API scope here as InitializeIsolate could compile some
13061305
// bootstrap library files which call out to a tag handler that may create
13071306
// Api Handles when an error is encountered.
@@ -2053,7 +2052,6 @@ DART_EXPORT bool Dart_RunLoopAsync(bool errors_are_fatal,
20532052
auto thread = Thread::Current();
20542053
TransitionNativeToVM transition(thread);
20552054
StackZone zone(thread);
2056-
HANDLESCOPE(thread);
20572055

20582056
if (on_error_port != ILLEGAL_PORT) {
20592057
const auto& port =

runtime/vm/dart_api_impl_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,7 +3128,6 @@ VM_UNIT_TEST_CASE(DartAPI_PersistentHandles) {
31283128
{
31293129
TransitionNativeToVM transition(thread);
31303130
StackZone zone(thread);
3131-
HANDLESCOPE(thread);
31323131
for (int i = 0; i < 500; i++) {
31333132
String& str = String::Handle();
31343133
str ^= PersistentHandle::Cast(handles[i])->ptr();
@@ -4551,7 +4550,6 @@ VM_UNIT_TEST_CASE(DartAPI_LocalHandles) {
45514550
{
45524551
TransitionNativeToVM transition1(thread);
45534552
StackZone zone(thread);
4554-
HANDLESCOPE(thread);
45554553
Smi& val = Smi::Handle();
45564554
TransitionVMToNative transition2(thread);
45574555

@@ -4619,9 +4617,11 @@ VM_UNIT_TEST_CASE(DartAPI_LocalZoneMemory) {
46194617
Thread* thread = Thread::Current();
46204618
EXPECT(thread != NULL);
46214619
ApiLocalScope* scope = thread->api_top_scope();
4620+
EXPECT_EQ(0, thread->ZoneSizeInBytes());
46224621
{
46234622
// Start a new scope and allocate some memory.
46244623
Dart_EnterScope();
4624+
EXPECT_EQ(0, thread->ZoneSizeInBytes());
46254625
for (int i = 0; i < 100; i++) {
46264626
Dart_ScopeAllocate(16);
46274627
}

runtime/vm/dart_api_state.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,4 @@
1414

1515
namespace dart {
1616

17-
RelaxedAtomic<intptr_t> ApiNativeScope::current_memory_usage_ = 0;
18-
1917
} // namespace dart

runtime/vm/dart_api_state.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class ApiZone {
110110
if ((thread != NULL) && (thread->zone() == &zone_)) {
111111
thread->set_zone(zone_.previous_);
112112
}
113-
zone_.DeleteAll();
113+
zone_.Reset();
114114
}
115115

116116
private:
@@ -656,35 +656,18 @@ class ApiNativeScope {
656656
ASSERT(Current() == NULL);
657657
OSThread::SetThreadLocal(Api::api_native_key_,
658658
reinterpret_cast<uword>(this));
659-
// We manually increment the memory usage counter since there is memory
660-
// initially allocated within the zone on creation.
661-
IncrementNativeScopeMemoryCapacity(zone_.GetZone()->CapacityInBytes());
662659
}
663660

664661
~ApiNativeScope() {
665662
ASSERT(Current() == this);
666663
OSThread::SetThreadLocal(Api::api_native_key_, 0);
667-
// We must also manually decrement the memory usage counter since the native
668-
// is still holding it's initial memory and ~Zone() won't be able to
669-
// determine which memory usage counter to decrement.
670-
DecrementNativeScopeMemoryCapacity(zone_.GetZone()->CapacityInBytes());
671664
}
672665

673666
static inline ApiNativeScope* Current() {
674667
return reinterpret_cast<ApiNativeScope*>(
675668
OSThread::GetThreadLocal(Api::api_native_key_));
676669
}
677670

678-
static uintptr_t current_memory_usage() { return current_memory_usage_; }
679-
680-
static void IncrementNativeScopeMemoryCapacity(intptr_t size) {
681-
current_memory_usage_.fetch_add(size);
682-
}
683-
684-
static void DecrementNativeScopeMemoryCapacity(intptr_t size) {
685-
current_memory_usage_.fetch_sub(size);
686-
}
687-
688671
Zone* zone() {
689672
Zone* result = zone_.GetZone();
690673
ASSERT(result->handles()->CountScopedHandles() == 0);
@@ -693,9 +676,6 @@ class ApiNativeScope {
693676
}
694677

695678
private:
696-
// The current total memory usage within ApiNativeScopes.
697-
static RelaxedAtomic<intptr_t> current_memory_usage_;
698-
699679
ApiZone zone_;
700680
};
701681

runtime/vm/handles.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ namespace dart {
1919

2020
DEFINE_FLAG(bool, verify_handles, false, "Verify handles.");
2121

22-
VMHandles::~VMHandles() {
23-
if (FLAG_trace_handles) {
24-
OS::PrintErr("*** Handle Counts for 0x(%" Px "):Zone = %d,Scoped = %d\n",
25-
reinterpret_cast<intptr_t>(this), CountZoneHandles(),
26-
CountScopedHandles());
27-
OS::PrintErr("*** Deleting VM handle block 0x%" Px "\n",
28-
reinterpret_cast<intptr_t>(this));
29-
}
30-
}
31-
3222
void VMHandles::VisitObjectPointers(ObjectPointerVisitor* visitor) {
3323
return Handles<kVMHandleSizeInWords, kVMHandlesPerChunk,
3424
kOffsetOfRawPtr>::VisitObjectPointers(visitor);

runtime/vm/handles.h

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,24 @@ class Handles {
107107
return true;
108108
}
109109

110+
intptr_t ZoneHandlesCapacityInBytes() const {
111+
intptr_t capacity = 0;
112+
for (HandlesBlock* block = zone_blocks_; block != nullptr;
113+
block = block->next_block()) {
114+
capacity += sizeof(*block);
115+
}
116+
return capacity;
117+
}
118+
119+
intptr_t ScopedHandlesCapacityInBytes() const {
120+
intptr_t capacity = 0;
121+
for (HandlesBlock* block = scoped_blocks_; block != nullptr;
122+
block = block->next_block()) {
123+
capacity += sizeof(*block);
124+
}
125+
return capacity;
126+
}
127+
110128
protected:
111129
// Returns a count of active handles (used for testing purposes).
112130
int CountScopedHandles() const;
@@ -126,7 +144,7 @@ class Handles {
126144
class HandlesBlock : public MallocAllocated {
127145
public:
128146
explicit HandlesBlock(HandlesBlock* next)
129-
: next_handle_slot_(0), next_block_(next) {}
147+
: next_block_(next), next_handle_slot_(0) {}
130148
~HandlesBlock();
131149

132150
// Reinitializes handle block for reuse.
@@ -175,9 +193,9 @@ class Handles {
175193
void set_next_block(HandlesBlock* next) { next_block_ = next; }
176194

177195
private:
178-
uword data_[kHandleSizeInWords * kHandlesPerChunk]; // Handles area.
179-
intptr_t next_handle_slot_; // Next slot for allocation in current block.
180196
HandlesBlock* next_block_; // Link to next block of handles.
197+
intptr_t next_handle_slot_; // Next slot for allocation in current block.
198+
uword data_[kHandleSizeInWords * kHandlesPerChunk]; // Handles area.
181199

182200
DISALLOW_COPY_AND_ASSIGN(HandlesBlock);
183201
};
@@ -222,7 +240,7 @@ class Handles {
222240
};
223241

224242
static const int kVMHandleSizeInWords = 2;
225-
static const int kVMHandlesPerChunk = 64;
243+
static const int kVMHandlesPerChunk = 63;
226244
static const int kOffsetOfRawPtr = kWordSize;
227245
class VMHandles : public Handles<kVMHandleSizeInWords,
228246
kVMHandlesPerChunk,
@@ -232,12 +250,25 @@ class VMHandles : public Handles<kVMHandleSizeInWords,
232250

233251
VMHandles()
234252
: Handles<kVMHandleSizeInWords, kVMHandlesPerChunk, kOffsetOfRawPtr>() {
253+
#if defined(DEBUG)
235254
if (FLAG_trace_handles) {
236255
OS::PrintErr("*** Starting a new VM handle block 0x%" Px "\n",
237256
reinterpret_cast<intptr_t>(this));
238257
}
258+
#endif
259+
}
260+
~VMHandles() {
261+
#if defined(DEBUG)
262+
if (FLAG_trace_handles) {
263+
OS::PrintErr("*** Handle Counts for 0x(%" Px
264+
"):Zone = %d,Scoped = %d\n",
265+
reinterpret_cast<intptr_t>(this), CountZoneHandles(),
266+
CountScopedHandles());
267+
OS::PrintErr("*** Deleting VM handle block 0x%" Px "\n",
268+
reinterpret_cast<intptr_t>(this));
269+
}
270+
#endif
239271
}
240-
~VMHandles();
241272

242273
// Visit all object pointers stored in the various handles.
243274
void VisitObjectPointers(ObjectPointerVisitor* visitor);

runtime/vm/handles_impl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ uword Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>::
8181
AllocateHandle(Zone* zone) {
8282
#if defined(DEBUG)
8383
Thread* thread = Thread::Current();
84-
ASSERT(thread->top_handle_scope() != NULL);
8584
ASSERT(thread->MayAllocateHandles());
8685
#endif // DEBUG
8786
Handles* handles = zone->handles();

runtime/vm/heap/heap_test.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,6 @@ VM_UNIT_TEST_CASE(CleanupBequestNeverReceived) {
592592
Thread* thread = Thread::Current();
593593
TransitionNativeToVM transition(thread);
594594
StackZone zone(thread);
595-
HANDLESCOPE(thread);
596595

597596
String& string = String::Handle(String::New(TEST_MESSAGE));
598597
PersistentHandle* handle =
@@ -626,7 +625,6 @@ VM_UNIT_TEST_CASE(ReceivesSendAndExitMessage) {
626625
Thread* thread = Thread::Current();
627626
TransitionNativeToVM transition(thread);
628627
StackZone zone(thread);
629-
HANDLESCOPE(thread);
630628

631629
String& string = String::Handle(String::New(TEST_MESSAGE));
632630

@@ -644,7 +642,6 @@ VM_UNIT_TEST_CASE(ReceivesSendAndExitMessage) {
644642
Thread* thread = Thread::Current();
645643
TransitionNativeToVM transition(thread);
646644
StackZone zone(thread);
647-
HANDLESCOPE(thread);
648645

649646
EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
650647
}

runtime/vm/kernel_isolate.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ class RunKernelTask : public ThreadPool::Task {
174174
Thread* T = Thread::Current();
175175
ASSERT(I == T->isolate());
176176
StackZone zone(T);
177-
HANDLESCOPE(T);
178177
// Invoke main which will return the port to which load requests are sent.
179178
const Library& root_library =
180179
Library::Handle(Z, I->group()->object_store()->root_library());

runtime/vm/metrics_test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ VM_UNIT_TEST_CASE(Metric_OnDemand) {
5353
Thread* thread = Thread::Current();
5454
TransitionNativeToVM transition(thread);
5555
StackZone zone(thread);
56-
HANDLESCOPE(thread);
5756
MyMetric metric;
5857

5958
metric.InitInstance(Isolate::Current(), "a.b.c", "foobar", Metric::kByte);

runtime/vm/profiler_service.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,6 @@ void ProfilerService::PrintJSONImpl(Thread* thread,
17771777
ASSERT(buffer != nullptr);
17781778

17791779
StackZone zone(thread);
1780-
HANDLESCOPE(thread);
17811780
Profile profile;
17821781
profile.Build(thread, filter, buffer);
17831782
profile.PrintProfileJSON(stream, include_code_samples);

0 commit comments

Comments
 (0)