Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
77e25cb6
Commit
77e25cb6
authored
May 15, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
When loading a shared library let the GC know about the static variables
parent
6ab26e7f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
0 deletions
+20
-0
src/gc/collector.cpp
src/gc/collector.cpp
+9
-0
src/gc/collector.h
src/gc/collector.h
+2
-0
src/runtime/capi.cpp
src/runtime/capi.cpp
+9
-0
No files found.
src/gc/collector.cpp
View file @
77e25cb6
...
@@ -142,6 +142,11 @@ void deregisterPermanentRoot(void* obj) {
...
@@ -142,6 +142,11 @@ void deregisterPermanentRoot(void* obj) {
roots
.
erase
(
obj
);
roots
.
erase
(
obj
);
}
}
static
std
::
vector
<
std
::
pair
<
void
*
,
void
*>>
potential_root_ranges
;
void
registerPotentialRootRange
(
void
*
start
,
void
*
end
)
{
potential_root_ranges
.
push_back
(
std
::
make_pair
(
start
,
end
));
}
extern
"C"
PyObject
*
PyGC_AddRoot
(
PyObject
*
obj
)
noexcept
{
extern
"C"
PyObject
*
PyGC_AddRoot
(
PyObject
*
obj
)
noexcept
{
if
(
obj
)
{
if
(
obj
)
{
// Allow duplicates from CAPI code since they shouldn't have to know
// Allow duplicates from CAPI code since they shouldn't have to know
...
@@ -268,6 +273,10 @@ void markPhase() {
...
@@ -268,6 +273,10 @@ void markPhase() {
visitor
.
visit
(
h
->
value
);
visitor
.
visit
(
h
->
value
);
}
}
for
(
auto
&
e
:
potential_root_ranges
)
{
visitor
.
visitPotentialRange
((
void
*
const
*
)
e
.
first
,
(
void
*
const
*
)
e
.
second
);
}
// if (VERBOSITY()) printf("Found %d roots\n", stack.size());
// if (VERBOSITY()) printf("Found %d roots\n", stack.size());
while
(
void
*
p
=
stack
.
pop
())
{
while
(
void
*
p
=
stack
.
pop
())
{
assert
(((
intptr_t
)
p
)
%
8
==
0
);
assert
(((
intptr_t
)
p
)
%
8
==
0
);
...
...
src/gc/collector.h
View file @
77e25cb6
...
@@ -33,6 +33,8 @@ void deregisterPermanentRoot(void* root_obj);
...
@@ -33,6 +33,8 @@ void deregisterPermanentRoot(void* root_obj);
// even if they are not heap allocated.
// even if they are not heap allocated.
void
registerNonheapRootObject
(
void
*
obj
);
void
registerNonheapRootObject
(
void
*
obj
);
void
registerPotentialRootRange
(
void
*
start
,
void
*
end
);
// If you want to have a static root "location" where multiple values could be stored, use this:
// If you want to have a static root "location" where multiple values could be stored, use this:
class
GCRootHandle
{
class
GCRootHandle
{
public:
public:
...
...
src/runtime/capi.cpp
View file @
77e25cb6
...
@@ -1290,6 +1290,15 @@ BoxedModule* importCExtension(const std::string& full_name, const std::string& l
...
@@ -1290,6 +1290,15 @@ BoxedModule* importCExtension(const std::string& full_name, const std::string& l
assert
(
init
);
assert
(
init
);
// Let the GC know about the static variables.
uintptr_t
bss_start
=
(
uintptr_t
)
dlsym
(
handle
,
"__bss_start"
);
uintptr_t
bss_end
=
(
uintptr_t
)
dlsym
(
handle
,
"_end"
);
RELEASE_ASSERT
(
bss_end
-
bss_start
<
100000
,
"Large BSS section detected - there maybe something wrong"
);
// only track void* aligned memory
bss_start
=
(
bss_start
+
(
sizeof
(
void
*
)
-
1
))
&
~
(
sizeof
(
void
*
)
-
1
);
bss_end
-=
bss_end
%
sizeof
(
void
*
);
gc
::
registerPotentialRootRange
((
void
*
)
bss_start
,
(
void
*
)
bss_end
);
char
*
packagecontext
=
strdup
(
full_name
.
c_str
());
char
*
packagecontext
=
strdup
(
full_name
.
c_str
());
char
*
oldcontext
=
_Py_PackageContext
;
char
*
oldcontext
=
_Py_PackageContext
;
_Py_PackageContext
=
packagecontext
;
_Py_PackageContext
=
packagecontext
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment