Flutter Engine
The Flutter Engine
allocation.cc
Go to the documentation of this file.
1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include "vm/allocation.h"
6
7#include "platform/assert.h"
8#include "vm/isolate.h"
9#include "vm/thread.h"
10#include "vm/zone.h"
11
12namespace dart {
13
14static void* Allocate(uword size, Zone* zone) {
15 ASSERT(zone != nullptr);
16 if (size > static_cast<uword>(kIntptrMax)) {
17 FATAL("ZoneAllocated object has unexpectedly large size %" Pu "", size);
18 }
19 return reinterpret_cast<void*>(zone->AllocUnsafe(size));
20}
21
22void* ZoneAllocated::operator new(uword size) {
23 return Allocate(size, Thread::Current()->zone());
24}
25
26void* ZoneAllocated::operator new(uword size, Zone* zone) {
27 return Allocate(size, zone);
28}
29
31 if (thread_ != nullptr) {
32 StackResource* top = thread_->top_resource();
33 ASSERT(top == this);
34 thread_->set_top_resource(previous_);
35 }
36#if defined(DEBUG)
37 if (thread_ != nullptr) {
38 ASSERT(Thread::Current() == thread_);
39 }
40#endif
41}
42
43void StackResource::Init(ThreadState* thread) {
44 // We can only have longjumps and exceptions when there is a current
45 // thread and isolate. If there is no current thread, we don't need to
46 // protect this case.
47 if (thread != nullptr) {
49 thread_ = thread;
50 previous_ = thread_->top_resource();
51 ASSERT((previous_ == nullptr) || (previous_->thread_ == thread));
52 thread_->set_top_resource(this);
53 }
54}
55
57 StackResource* current_resource = thread->top_resource();
58 while (current_resource != new_top) {
59 current_resource->~StackResource();
60 current_resource = thread->top_resource();
61 }
62}
63
64} // namespace dart
ThreadState * thread() const
Definition: allocation.h:33
static void UnwindAbove(ThreadState *thread, StackResource *new_top)
Definition: allocation.cc:56
virtual ~StackResource()
Definition: allocation.cc:30
void set_top_resource(StackResource *value)
Definition: thread_state.h:42
StackResource * top_resource() const
Definition: thread_state.h:41
static Thread * Current()
Definition: thread.h:362
void * AllocUnsafe(intptr_t size)
#define ASSERT(E)
#define FATAL(error)
Definition: dart_vm.cc:33
static void * Allocate(uword size, Zone *zone)
Definition: allocation.cc:14
uintptr_t uword
Definition: globals.h:501
constexpr intptr_t kIntptrMax
Definition: globals.h:557
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
#define Pu
Definition: globals.h:409