Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
dart-lang
sdk
runtime
vm
allocation_test.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
#include "
platform/assert.h
"
7
#include "
vm/longjump.h
"
8
#include "
vm/unit_test.h
"
9
10
namespace
dart
{
11
12
class
TestValueObject
:
public
ValueObject
{
13
public
:
14
explicit
TestValueObject
(
int
* ptr) : ptr_(ptr) {
15
EXPECT_EQ(1, *ptr_);
16
*ptr_ = 2;
17
}
18
19
virtual
~TestValueObject
() {
20
EXPECT_EQ(3, *ptr_);
21
*ptr_ = 4;
22
}
23
24
int
value
()
const
{
return
*ptr_; }
25
virtual
int
GetId
()
const
{
return
3; }
26
27
private
:
28
int
* ptr_;
29
};
30
31
class
TestStackResource
:
public
StackResource
{
32
public
:
33
explicit
TestStackResource
(
int
* ptr)
34
:
StackResource
(
Thread
::Current()), ptr_(ptr) {
35
EXPECT_EQ(1, *ptr_);
36
*ptr_ = 2;
37
}
38
39
~TestStackResource
() {
40
EXPECT_EQ(6, *ptr_);
41
*ptr_ = 7;
42
}
43
44
int
value
()
const
{
return
*ptr_; }
45
virtual
int
GetId
()
const
{
return
3; }
46
47
private
:
48
int
* ptr_;
49
};
50
51
class
TestStackedStackResource
:
public
StackResource
{
52
public
:
53
explicit
TestStackedStackResource
(
int
* ptr)
54
:
StackResource
(
Thread
::Current()), ptr_(ptr) {
55
EXPECT_EQ(3, *ptr_);
56
*ptr_ = 4;
57
}
58
59
~TestStackedStackResource
() {
60
EXPECT_EQ(5, *ptr_);
61
*ptr_ = 6;
62
}
63
64
int
value
()
const
{
return
*ptr_; }
65
66
private
:
67
int
* ptr_;
68
};
69
70
static
void
StackAllocatedDestructionHelper
(
int
* ptr) {
71
TestValueObject
stacked(ptr);
72
EXPECT_EQ(2, *ptr);
73
*ptr = 3;
74
}
75
76
ISOLATE_UNIT_TEST_CASE
(StackAllocatedDestruction) {
77
int
data
= 1;
78
StackAllocatedDestructionHelper
(&
data
);
79
EXPECT_EQ(4,
data
);
80
}
81
82
static
void
StackAllocatedLongJumpHelper
(
int
* ptr,
LongJumpScope
* jump) {
83
TestValueObject
stacked(ptr);
84
EXPECT_EQ(2, *ptr);
85
*ptr = 3;
86
const
Error
&
error
=
Error::Handle
(LanguageError::New(
87
String::Handle
(
String::New
(
"StackAllocatedLongJump"
))));
88
jump->
Jump
(1,
error
);
89
UNREACHABLE
();
90
}
91
92
ISOLATE_UNIT_TEST_CASE
(StackAllocatedLongJump) {
93
LongJumpScope
jump;
94
int
data
= 1;
95
if
(setjmp(*jump.
Set
()) == 0) {
96
StackAllocatedLongJumpHelper
(&
data
, &jump);
97
UNREACHABLE
();
98
}
else
{
99
ASSERT
(
Error::Handle
(thread->StealStickyError()).IsLanguageError());
100
}
101
EXPECT_EQ(3,
data
);
102
}
103
104
static
void
StackedStackResourceDestructionHelper
(
int
* ptr) {
105
TestStackedStackResource
stacked(ptr);
106
EXPECT_EQ(4, *ptr);
107
*ptr = 5;
108
}
109
110
static
void
StackResourceDestructionHelper
(
int
* ptr) {
111
TestStackResource
stacked(ptr);
112
EXPECT_EQ(2, *ptr);
113
*ptr = 3;
114
StackedStackResourceDestructionHelper
(ptr);
115
EXPECT_EQ(6, *ptr);
116
// Do not set data because the LongJump version does not return control here.
117
}
118
119
ISOLATE_UNIT_TEST_CASE
(StackResourceDestruction) {
120
int
data
= 1;
121
StackResourceDestructionHelper
(&
data
);
122
EXPECT_EQ(7,
data
);
123
}
124
125
static
void
StackedStackResourceLongJumpHelper
(
int
* ptr,
LongJumpScope
* jump) {
126
TestStackedStackResource
stacked(ptr);
127
EXPECT_EQ(4, *ptr);
128
*ptr = 5;
129
const
Error
&
error
=
Error::Handle
(LanguageError::New(
130
String::Handle
(
String::New
(
"StackedStackResourceLongJump"
))));
131
jump->
Jump
(1,
error
);
132
UNREACHABLE
();
133
}
134
135
static
void
StackResourceLongJumpHelper
(
int
* ptr,
LongJumpScope
* jump) {
136
TestStackResource
stacked(ptr);
137
EXPECT_EQ(2, *ptr);
138
*ptr = 3;
139
StackedStackResourceLongJumpHelper
(ptr, jump);
140
UNREACHABLE
();
141
}
142
143
ISOLATE_UNIT_TEST_CASE
(StackResourceLongJump) {
144
LongJumpScope
*
base
=
Thread::Current
()->
long_jump_base
();
145
{
146
LongJumpScope
jump;
147
int
data
= 1;
148
if
(setjmp(*jump.
Set
()) == 0) {
149
StackResourceLongJumpHelper
(&
data
, &jump);
150
UNREACHABLE
();
151
}
else
{
152
ASSERT
(
Error::Handle
(thread->StealStickyError()).IsLanguageError());
153
}
154
EXPECT_EQ(7,
data
);
155
}
156
ASSERT
(
base
==
Thread::Current
()->long_jump_base());
157
}
158
159
}
// namespace dart
assert.h
UNREACHABLE
#define UNREACHABLE()
Definition
assert.h:248
dart::Error
Definition
object.h:8020
dart::LongJumpScope
Definition
longjump.h:17
dart::LongJumpScope::Jump
DART_NORETURN void Jump(int value, const Error &error)
Definition
longjump.cc:22
dart::LongJumpScope::Set
jmp_buf * Set()
Definition
longjump.cc:16
dart::Object::Handle
static Object & Handle()
Definition
object.h:407
dart::StackResource
Definition
allocation.h:23
dart::String::New
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition
object.cc:23777
dart::TestStackResource
Definition
allocation_test.cc:31
dart::TestStackResource::value
int value() const
Definition
allocation_test.cc:44
dart::TestStackResource::GetId
virtual int GetId() const
Definition
allocation_test.cc:45
dart::TestStackResource::~TestStackResource
~TestStackResource()
Definition
allocation_test.cc:39
dart::TestStackResource::TestStackResource
TestStackResource(int *ptr)
Definition
allocation_test.cc:33
dart::TestStackedStackResource
Definition
allocation_test.cc:51
dart::TestStackedStackResource::TestStackedStackResource
TestStackedStackResource(int *ptr)
Definition
allocation_test.cc:53
dart::TestStackedStackResource::~TestStackedStackResource
~TestStackedStackResource()
Definition
allocation_test.cc:59
dart::TestStackedStackResource::value
int value() const
Definition
allocation_test.cc:64
dart::TestValueObject
Definition
allocation_test.cc:12
dart::TestValueObject::value
int value() const
Definition
allocation_test.cc:24
dart::TestValueObject::~TestValueObject
virtual ~TestValueObject()
Definition
allocation_test.cc:19
dart::TestValueObject::GetId
virtual int GetId() const
Definition
allocation_test.cc:25
dart::TestValueObject::TestValueObject
TestValueObject(int *ptr)
Definition
allocation_test.cc:14
dart::ThreadState::long_jump_base
LongJumpScope * long_jump_base() const
Definition
thread_state.h:47
dart::Thread
Definition
thread.h:342
dart::Thread::Current
static Thread * Current()
Definition
thread.h:361
dart::ValueObject
Definition
allocation.h:21
ASSERT
#define ASSERT(E)
Definition
entrypoints_verification_test.cc:25
error
const uint8_t uint32_t uint32_t GError ** error
Definition
fl_pixel_buffer_texture_test.cc:40
longjump.h
base
Definition
ax_tree_id_registry.h:17
dart
Definition
dart_vm.cc:33
dart::StackResourceDestructionHelper
static void StackResourceDestructionHelper(int *ptr)
Definition
allocation_test.cc:110
dart::StackedStackResourceDestructionHelper
static void StackedStackResourceDestructionHelper(int *ptr)
Definition
allocation_test.cc:104
dart::StackResourceLongJumpHelper
static void StackResourceLongJumpHelper(int *ptr, LongJumpScope *jump)
Definition
allocation_test.cc:135
dart::StackAllocatedLongJumpHelper
static void StackAllocatedLongJumpHelper(int *ptr, LongJumpScope *jump)
Definition
allocation_test.cc:82
dart::data
static int8_t data[kExtLength]
Definition
dart_api_impl_test.cc:2256
dart::StackAllocatedDestructionHelper
static void StackAllocatedDestructionHelper(int *ptr)
Definition
allocation_test.cc:70
dart::StackedStackResourceLongJumpHelper
static void StackedStackResourceLongJumpHelper(int *ptr, LongJumpScope *jump)
Definition
allocation_test.cc:125
allocation.h
unit_test.h
ISOLATE_UNIT_TEST_CASE
#define ISOLATE_UNIT_TEST_CASE(name)
Definition
unit_test.h:64
Generated on Fri Apr 26 2024 06:14:45 for Flutter Engine by
1.9.8