Author: fijal
Branch: vmprof-newstack
Changeset: r80551:ea3aa700ca28
Date: 2015-11-05 17:35 +0000
http://bitbucket.org/pypy/pypy/changeset/ea3aa700ca28/
Log: progress
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
@@ -52,22 +52,11 @@
vmprof_register_virtual_function = rffi.llexternal(
"vmprof_register_virtual_function",
[rffi.CCHARP, rffi.LONG, rffi.INT],
- rffi.INT, compilation_info=eci,
- _nowrapper=True)
+ rffi.INT, compilation_info=eci)
vmprof_ignore_signals = rffi.llexternal("vmprof_ignore_signals",
[rffi.INT], lltype.Void,
compilation_info=eci,
_nowrapper=True)
- vmprof_stack_new = rffi.llexternal("vmprof_stack_new",
- [], rffi.VOIDP, compilation_info=eci, _nowrapper=True)
- vmprof_stack_append = rffi.llexternal("vmprof_stack_append",
- [rffi.VOIDP, lltype.Signed], rffi.INT, compilation_info=eci,
- _nowrapper=True)
- vmprof_stack_pop = rffi.llexternal("vmprof_stack_pop",
- [rffi.VOIDP], lltype.Signed, compilation_info=eci,
- _nowrapper=True)
- vmprof_stack_free = rffi.llexternal("vmprof_stack_free",
- [rffi.VOIDP], lltype.Void, compilation_info=eci, _nowrapper=True)
return CInterface(locals())
@@ -106,18 +95,36 @@
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])
+ llargs = ", ".join(["%s arg%d" % (token2ctype(x), i) for i, x in
+ enumerate(token)])
type = token2ctype(restok)
target = udir.join('module_cache')
target.ensure(dir=1)
+ argnames = ", ".join(["arg%d" % i for i in range(len(token))])
target = target.join('trampoline_%s_%s.vmprof.c' % (name, token))
target.write("""
-#include <vmprof_stack.h>
+typedef struct vmprof_stack {
+ struct vmprof_stack* next;
+ long value;
+};
-%(type)s %(tramp_name)s(%(llargs)s)
+%(type)s %(cont_name)s(%(llargs)s);
+
+%(type)s %(tramp_name)s(%(llargs)s, long unique_id, void** shadowstack_base)
{
+ %(type)s result;
+ struct vmprof_stack node;
+
+ node.value = unique_id;
+ node.next = (struct vmprof_stack*)shadowstack_base[0];
+ shadowstack_base[0] = (void*)(&node);
+ result = %(cont_name)s(%(argnames)s);
+ shadowstack_base[0] = node.next;
+ return result;
}
""" % locals())
+ return finish_ll_trampoline(tramp_name, tramp_name, target, token,
+ restok, True)
def make_trampoline_function(name, func, token, restok):
from rpython.jit.backend import detect_cpu
@@ -183,18 +190,19 @@
\t.cfi_endproc
%(size_decl)s
""" % locals())
+ return finish_ll_trampoline(orig_tramp_name, tramp_name, target, token,
+ restok, False)
- def tok2cname(tok):
- if tok == 'i':
- return 'long'
- if tok == 'r':
- return 'void *'
- raise NotImplementedError(repr(tok))
+def finish_ll_trampoline(orig_tramp_name, tramp_name, target, token, restok,
+ accepts_shadowstack):
+ extra_args = ['long']
+ if accepts_shadowstack:
+ extra_args.append("void*")
header = 'RPY_EXTERN %s %s(%s);\n' % (
- tok2cname(restok),
+ token2ctype(restok),
orig_tramp_name,
- ', '.join([tok2cname(tok) for tok in token] + ['long']))
+ ', '.join([token2ctype(tok) for tok in token] + extra_args))
header += """\
static int cmp_%s(void *addr) {
@@ -214,9 +222,11 @@
separate_module_files = [str(target)],
)
+ ARGS = [token2lltype(tok) for tok in token] + [lltype.Signed]
+ if accepts_shadowstack:
+ ARGS.append(llmemory.Address)
return rffi.llexternal(
- orig_tramp_name,
- [token2lltype(tok) for tok in token] + [lltype.Signed],
+ orig_tramp_name, ARGS,
token2lltype(restok),
compilation_info=eci,
_nowrapper=True, sandboxsafe=True,
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
@@ -32,8 +32,7 @@
else:
self._code_unique_id = 0x7000000000000000
self.cintf = cintf.setup()
- self._stack = self.cintf.vmprof_stack_new()
-
+
def _cleanup_(self):
self.is_enabled = False
@@ -148,7 +147,7 @@
"""
def decorate(func):
try:
- _vmprof = _get_vmprof()
+ _get_vmprof()
except cintf.VMProfPlatformUnsupported:
return func
diff --git a/rpython/rlib/rvmprof/src/vmprof_main.h
b/rpython/rlib/rvmprof/src/vmprof_main.h
--- a/rpython/rlib/rvmprof/src/vmprof_main.h
+++ b/rpython/rlib/rvmprof/src/vmprof_main.h
@@ -37,7 +37,6 @@
#include "vmprof_unwind.h"
#endif
#include "vmprof_mt.h"
-#include "vmprof_stack.h"
/************************************************************/
@@ -210,7 +209,12 @@
* *************************************************************
*/
-static int get_stack_trace(void** result, int max_depth, ucontext_t *ucontext)
+static int get_stack_trace(void **result, int max_depth, ucontext_t *ucontext)
+{
+ return 0;
+}
+
+static int xxx_get_stack_trace(void** result, int max_depth, ucontext_t
*ucontext)
{
void *ip;
int n = 0;
diff --git a/rpython/rlib/rvmprof/src/vmprof_stack.h
b/rpython/rlib/rvmprof/src/vmprof_stack.h
deleted file mode 100644
--- a/rpython/rlib/rvmprof/src/vmprof_stack.h
+++ /dev/null
@@ -1,46 +0,0 @@
-
-#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];
-} vmprof_stack;
-
-RPY_EXTERN void *vmprof_stack_new(void)
-{
- vmprof_stack* stack = (vmprof_stack *)malloc(sizeof(vmprof_stack));
- stack->stack_depth = 0;
- return (void*)stack;
-}
-
-RPY_EXTERN int vmprof_stack_append(void *_stack, long item)
-{
- vmprof_stack* stack = (vmprof_stack*)_stack;
- if (stack->stack_depth >= STACK_SIZE - 1)
- return -1;
- stack->stack_items[stack->stack_depth] = item;
- stack->stack_depth += 1;
- return 0;
-}
-
-RPY_EXTERN long vmprof_stack_pop(void *_stack)
-{
- vmprof_stack* stack = (vmprof_stack*)_stack;
- long res;
-
- if (stack->stack_depth <= 0)
- return -1;
- res = stack->stack_items[stack->stack_depth];
- stack->stack_depth -= 1;
- return res;
-}
-
-RPY_EXTERN void vmprof_stack_free(void* stack)
-{
- free(stack);
-}
\ No newline at end of file
diff --git a/rpython/rlib/rvmprof/test/test_rvmprof.py
b/rpython/rlib/rvmprof/test/test_rvmprof.py
--- a/rpython/rlib/rvmprof/test/test_rvmprof.py
+++ b/rpython/rlib/rvmprof/test/test_rvmprof.py
@@ -25,7 +25,7 @@
return 0
assert f() == 0
- fn = compile(f, [])
+ fn = compile(f, [], gcpolicy="minimark")
assert fn() == 0
@@ -53,7 +53,7 @@
return 0
assert f() == 0
- fn = compile(f, [])
+ fn = compile(f, [], gcpolicy="minimark")
assert fn() == 0
@@ -79,7 +79,7 @@
return 0
assert f() == 0
- fn = compile(f, [])
+ fn = compile(f, [], gcpolicy="minimark")
assert fn() == 0
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit