Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
bb5316b9
Commit
bb5316b9
authored
11 years ago
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
gc: reserve first block; lexer: free vstr.
parent
fd8b6bcf
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/gc.c
+31
-26
31 additions, 26 deletions
py/gc.c
py/lexer.c
+1
-0
1 addition, 0 deletions
py/lexer.c
with
32 additions
and
26 deletions
py/gc.c
+
31
−
26
View file @
bb5316b9
...
...
@@ -20,7 +20,6 @@ typedef unsigned char byte;
#define STACK_SIZE (64) // tunable; minimum is 1
static
byte
*
gc_alloc_table_start
;
static
byte
*
gc_alloc_table_end
;
static
machine_uint_t
gc_alloc_table_byte_len
;
static
machine_uint_t
*
gc_pool_start
;
static
machine_uint_t
*
gc_pool_end
;
...
...
@@ -29,31 +28,6 @@ static int gc_stack_overflow;
static
machine_uint_t
gc_stack
[
STACK_SIZE
];
static
machine_uint_t
*
gc_sp
;
// TODO waste less memory; currently requires that all entries in alloc_table have a corresponding block in pool
void
gc_init
(
void
*
start
,
void
*
end
)
{
// align end pointer on block boundary
end
=
(
void
*
)((
machine_uint_t
)
end
&
(
~
(
BYTES_PER_BLOCK
-
1
)));
// calculate parameters for GC
machine_uint_t
total_word_len
=
(
machine_uint_t
*
)
end
-
(
machine_uint_t
*
)
start
;
gc_alloc_table_byte_len
=
total_word_len
*
BYTES_PER_WORD
/
(
1
+
BITS_PER_BYTE
/
2
*
BYTES_PER_BLOCK
);
gc_alloc_table_start
=
(
byte
*
)
start
;
gc_alloc_table_end
=
gc_alloc_table_start
+
gc_alloc_table_byte_len
;
machine_uint_t
gc_pool_block_len
=
gc_alloc_table_byte_len
*
BITS_PER_BYTE
/
2
;
machine_uint_t
gc_pool_word_len
=
gc_pool_block_len
*
WORDS_PER_BLOCK
;
gc_pool_start
=
(
machine_uint_t
*
)
end
-
gc_pool_word_len
;
gc_pool_end
=
end
;
// clear ATBs
memset
(
gc_alloc_table_start
,
0
,
gc_alloc_table_byte_len
);
/*
printf("GC layout:\n");
printf(" alloc table at %p, length %u bytes\n", gc_alloc_table_start, gc_alloc_table_byte_len);
printf(" pool at %p, length %u blocks = %u words = %u bytes\n", gc_pool_start, gc_pool_block_len, gc_pool_word_len, gc_pool_word_len * BYTES_PER_WORD);
*/
}
// ATB = allocation table byte
// 0b00 = FREE -- free block
// 0b01 = HEAD -- head of a chain of blocks
...
...
@@ -88,6 +62,37 @@ void gc_init(void *start, void *end) {
#define PTR_FROM_BLOCK(block) (((block) * BYTES_PER_BLOCK + (machine_uint_t)gc_pool_start))
#define ATB_FROM_BLOCK(bl) ((bl) / BLOCKS_PER_ATB)
// TODO waste less memory; currently requires that all entries in alloc_table have a corresponding block in pool
void
gc_init
(
void
*
start
,
void
*
end
)
{
// align end pointer on block boundary
end
=
(
void
*
)((
machine_uint_t
)
end
&
(
~
(
BYTES_PER_BLOCK
-
1
)));
// calculate parameters for GC
machine_uint_t
total_word_len
=
(
machine_uint_t
*
)
end
-
(
machine_uint_t
*
)
start
;
gc_alloc_table_byte_len
=
total_word_len
*
BYTES_PER_WORD
/
(
1
+
BITS_PER_BYTE
/
2
*
BYTES_PER_BLOCK
);
gc_alloc_table_start
=
(
byte
*
)
start
;
machine_uint_t
gc_pool_block_len
=
gc_alloc_table_byte_len
*
BITS_PER_BYTE
/
2
;
machine_uint_t
gc_pool_word_len
=
gc_pool_block_len
*
WORDS_PER_BLOCK
;
gc_pool_start
=
(
machine_uint_t
*
)
end
-
gc_pool_word_len
;
gc_pool_end
=
end
;
// clear ATBs
memset
(
gc_alloc_table_start
,
0
,
gc_alloc_table_byte_len
);
// allocate first block because gc_pool_start points there and it will never
// be freed, so allocating 1 block with null pointers will minimise memory loss
ATB_FREE_TO_HEAD
(
0
);
for
(
int
i
=
0
;
i
<
WORDS_PER_BLOCK
;
i
++
)
{
gc_pool_start
[
i
]
=
0
;
}
/*
printf("GC layout:\n");
printf(" alloc table at %p, length %u bytes\n", gc_alloc_table_start, gc_alloc_table_byte_len);
printf(" pool at %p, length %u blocks = %u words = %u bytes\n", gc_pool_start, gc_pool_block_len, gc_pool_word_len, gc_pool_word_len * BYTES_PER_WORD);
*/
}
#define VERIFY_PTR(ptr) ( \
(ptr & (BYTES_PER_BLOCK - 1)) == 0
/* must be aligned on a block */
\
&& ptr >= (machine_uint_t)gc_pool_start
/* must be above start of pool */
\
...
...
This diff is collapsed.
Click to expand it.
py/lexer.c
+
1
−
0
View file @
bb5316b9
...
...
@@ -635,6 +635,7 @@ void py_lexer_free(py_lexer_t *lex) {
if
(
lex
->
stream_close
)
{
lex
->
stream_close
(
lex
->
stream_data
);
}
vstr_clear
(
&
lex
->
vstr
);
m_free
(
lex
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment