Author: fijal
Branch: vmprof-newstack
Changeset: r80550:1b09a35e77d4
Date: 2015-11-04 19:56 +0000
http://bitbucket.org/pypy/pypy/changeset/1b09a35e77d4/
Log: in progress
diff --git a/rpython/memory/gctransform/shadowstack.py
b/rpython/memory/gctransform/shadowstack.py
--- a/rpython/memory/gctransform/shadowstack.py
+++ b/rpython/memory/gctransform/shadowstack.py
@@ -74,6 +74,7 @@
self.decr_stack = decr_stack
def walk_stack_root(callback, start, end):
+ # shadowstack[0] contains the vmprof stack
gc = self.gc
addr = end
addr -= sizeofaddr
@@ -283,6 +284,7 @@
def start_fresh_new_state(self):
self.gcdata.root_stack_base = self.unused_full_stack
+ # shadowstack[0] contains the vmprof stack
self.gcdata.root_stack_top = self.unused_full_stack + sizeofaddr
self.unused_full_stack = llmemory.NULL
@@ -310,6 +312,7 @@
SHADOWSTACKREFPTR.TO.become(SHADOWSTACKREF)
def customtrace(gc, obj, callback, arg):
+ # we intentionally don't read shadowstack[0]
obj = llmemory.cast_adr_to_ptr(obj, SHADOWSTACKREFPTR)
addr = obj.top
start = obj.base
diff --git a/rpython/rlib/rvmprof/cintf.py b/rpython/rlib/rvmprof/cintf.py
--- a/rpython/rlib/rvmprof/cintf.py
+++ b/rpython/rlib/rvmprof/cintf.py
@@ -86,6 +86,39 @@
return llmemory.GCREF
raise NotImplementedError(repr(tok))
+def token2ctype(tok):
+ if tok == 'i':
+ return 'long'
+ elif tok == 'r':
+ return 'void*'
+ elif tok == 'f':
+ return 'double'
+ else:
+ raise NotImplementedError(repr(tok))
+
+def make_c_trampoline_function(name, func, token, restok):
+ cont_name = 'rpyvmprof_f_%s_%s' % (name, token)
+ tramp_name = 'rpyvmprof_t_%s_%s' % (name, token)
+
+ func.c_name = cont_name
+ func._dont_inline_ = True
+
+ assert detect_cpu.autodetect().startswith(detect_cpu.MODEL_X86_64), (
+ "rvmprof only supports x86-64 CPUs for now")
+
+ llargs = ", ".join([token2ctype(x) for x in token])
+ type = token2ctype(restok)
+ target = udir.join('module_cache')
+ target.ensure(dir=1)
+ target = target.join('trampoline_%s_%s.vmprof.c' % (name, token))
+ target.write("""
+#include <vmprof_stack.h>
+
+%(type)s %(tramp_name)s(%(llargs)s)
+{
+}
+""" % locals())
+
def make_trampoline_function(name, func, token, restok):
from rpython.jit.backend import detect_cpu
diff --git a/rpython/rlib/rvmprof/rvmprof.py b/rpython/rlib/rvmprof/rvmprof.py
--- a/rpython/rlib/rvmprof/rvmprof.py
+++ b/rpython/rlib/rvmprof/rvmprof.py
@@ -4,7 +4,8 @@
from rpython.rlib.rvmprof import cintf
from rpython.rtyper.annlowlevel import cast_instance_to_gcref
from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance
-from rpython.rtyper.lltypesystem import rffi
+from rpython.rtyper.lltypesystem import rffi, llmemory
+from rpython.rtyper.lltypesystem.lloperation import llop
MAX_FUNC_NAME = 1023
@@ -168,13 +169,16 @@
return (ll_arg,) + ll_args, tok + token
@specialize.memo()
- def get_ll_trampoline(token):
+ def get_ll_trampoline(token, c_version=False):
""" Used by the trampoline-version only
"""
if result_class is None:
restok = "i"
else:
restok = "r"
+ if c_version:
+ return cintf.make_c_trampoline_function(name, func, token,
+ restok)
return cintf.make_trampoline_function(name, func, token, restok)
def decorated_function(*args):
@@ -194,20 +198,21 @@
ll_args, token = lower(*args)
ll_trampoline = get_ll_trampoline(token)
ll_result = ll_trampoline(*ll_args + (unique_id,))
- if result_class is not None:
- return cast_base_ptr_to_instance(result_class,
ll_result)
- else:
- return ll_result
else:
return func(*args)
else: # this is the case of the stack
- unique_id = get_code_fn(*args)._vmprof_unique_id
- _vmprof.cintf.vmprof_stack_append(_vmprof._stack, unique_id)
- try:
- res = func(*args)
- finally:
- _vmprof.cintf.vmprof_stack_pop(_vmprof._stack)
- return res
+ if we_are_translated() and not jit.we_are_jitted():
+ unique_id = get_code_fn(*args)._vmprof_unique_id
+ shadowstack_0 =
llop.gc_adr_of_root_stack_base(llmemory.Address)
+ ll_args, token = lower(*args)
+ ll_trampoline = get_ll_trampoline(token, True)
+ ll_result = ll_trampoline(*ll_args + (unique_id,
shadowstack_0))
+ else:
+ return func(*args)
+ if result_class is not None:
+ return cast_base_ptr_to_instance(result_class, ll_result)
+ else:
+ return ll_result
decorated_function.__name__ = func.__name__ + '_rvmprof'
return decorated_function
diff --git a/rpython/rlib/rvmprof/src/vmprof_stack.h
b/rpython/rlib/rvmprof/src/vmprof_stack.h
--- a/rpython/rlib/rvmprof/src/vmprof_stack.h
+++ b/rpython/rlib/rvmprof/src/vmprof_stack.h
@@ -2,6 +2,10 @@
#define STACK_SIZE 8192
#include <stdlib.h>
+typedef stuct vmprof_stack {
+
+} vmprof_stack;
+
typedef struct vmprof_stack {
volatile long stack_depth;
long stack_items[STACK_SIZE];
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit