Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
dart-lang
sdk
runtime
vm
allocation.h
Go to the documentation of this file.
1
// Copyright (c) 2013, 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
#ifndef RUNTIME_VM_ALLOCATION_H_
6
#define RUNTIME_VM_ALLOCATION_H_
7
8
#include "
platform/allocation.h
"
9
#include "
platform/assert.h
"
10
#include "
vm/globals.h
"
11
12
namespace
dart
{
13
14
// Forward declarations.
15
class
ThreadState;
16
class
Zone;
17
18
// Stack resources subclass from this base class. The VM will ensure that the
19
// destructors of these objects are called before the stack is unwound past the
20
// objects location on the stack. Use stack resource objects if objects
21
// need to be destroyed even in the case of exceptions when a Longjump is done
22
// to a stack frame above the frame where these objects were allocated.
23
class
StackResource
{
24
public
:
25
explicit
StackResource
(
ThreadState
*
thread
)
26
: thread_(nullptr), previous_(nullptr) {
27
Init
(
thread
);
28
}
29
30
virtual
~StackResource
();
31
32
// The thread that owns this resource.
33
ThreadState
*
thread
()
const
{
return
thread_; }
34
35
// Destroy stack resources of thread until top exit frame.
36
static
void
Unwind
(
ThreadState
*
thread
) {
UnwindAbove
(
thread
,
nullptr
); }
37
// Destroy stack resources of thread above new_top, exclusive.
38
static
void
UnwindAbove
(
ThreadState
*
thread
,
StackResource
* new_top);
39
40
private
:
41
void
Init
(
ThreadState
*
thread
);
42
43
ThreadState
* thread_;
44
StackResource
* previous_;
45
46
DISALLOW_ALLOCATION();
47
DISALLOW_IMPLICIT_CONSTRUCTORS
(
StackResource
);
48
};
49
50
// Zone allocated objects cannot be individually deallocated, but have
51
// to rely on the destructor of Zone which is called when the Zone
52
// goes out of scope to reclaim memory.
53
class
ZoneAllocated
{
54
public
:
55
ZoneAllocated
() {}
56
57
// Implicitly allocate the object in the current zone.
58
void
*
operator
new
(
size_t
size);
59
60
// Allocate the object in the given zone, which must be the current zone.
61
void
*
operator
new
(
size_t
size,
Zone
* zone);
62
63
// Ideally, the delete operator should be protected instead of
64
// public, but unfortunately the compiler sometimes synthesizes
65
// (unused) destructors for classes derived from ZoneObject, which
66
// require the operator to be visible. MSVC requires the delete
67
// operator to be public.
68
69
// Disallow explicit deallocation of nodes. Nodes can only be
70
// deallocated by invoking DeleteAll() on the zone they live in.
71
void
operator
delete
(
void
* pointer) {
UNREACHABLE
(); }
72
73
private
:
74
DISALLOW_COPY_AND_ASSIGN
(
ZoneAllocated
);
75
};
76
77
}
// namespace dart
78
79
// Prevent use of `new (zone) DoesNotExtendZoneAllocated()`, which places the
80
// DoesNotExtendZoneAllocated on top of the Zone.
81
void
*
operator
new
(
size_t
size,
dart::Zone
* zone) =
delete
;
82
83
#endif
// RUNTIME_VM_ALLOCATION_H_
assert.h
UNREACHABLE
#define UNREACHABLE()
Definition
assert.h:248
dart::StackResource
Definition
allocation.h:23
dart::StackResource::thread
ThreadState * thread() const
Definition
allocation.h:33
dart::StackResource::StackResource
StackResource(ThreadState *thread)
Definition
allocation.h:25
dart::StackResource::UnwindAbove
static void UnwindAbove(ThreadState *thread, StackResource *new_top)
Definition
allocation.cc:56
dart::StackResource::Unwind
static void Unwind(ThreadState *thread)
Definition
allocation.h:36
dart::StackResource::~StackResource
virtual ~StackResource()
Definition
allocation.cc:30
dart::ThreadState
Definition
thread_state.h:24
dart::ZoneAllocated
Definition
allocation.h:53
dart::ZoneAllocated::ZoneAllocated
ZoneAllocated()
Definition
allocation.h:55
dart::Zone
Definition
unit_test_custom_zone.h:19
Init
void Init()
Definition
gm_bindings.cpp:346
dart
Definition
dart_vm.cc:33
DISALLOW_IMPLICIT_CONSTRUCTORS
#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName)
Definition
globals.h:593
DISALLOW_COPY_AND_ASSIGN
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition
globals.h:581
allocation.h
globals.h
Generated on Fri Apr 26 2024 06:14:07 for Flutter Engine by
1.9.8