Author: Richard Plangger <[email protected]>
Branch: s390x-backend
Changeset: r82591:a2ccecb333f0
Date: 2016-02-27 19:15 +0100
http://bitbucket.org/pypy/pypy/changeset/a2ccecb333f0/
Log: added new module gcstress that compiles a very minimal language in a
zrpy test and feed it with input from hypothesis (work in progress)
diff --git a/rpython/jit/backend/llsupport/gcstress/__init__.py
b/rpython/jit/backend/llsupport/gcstress/__init__.py
new file mode 100644
diff --git a/rpython/jit/backend/llsupport/gcstress/code.py
b/rpython/jit/backend/llsupport/gcstress/code.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/backend/llsupport/gcstress/code.py
@@ -0,0 +1,160 @@
+
+import struct
+
+class ByteCode(object):
+ def encode(self, ctx):
+ ctx.append_byte(self.BYTE_CODE)
+
+_c = 0
+
+LIST_TYP = 'l'
+INT_TYP = 'i'
+OBJ_TYP = 'o'
+STR_TYP = 's'
+VAL_TYP = 'v' # either one of the earlier
+
+def unique_code():
+ global _c
+ v = _c
+ _c = v + 1
+ return v
+
+class Context(object):
+ def __init__(self):
+ self.consts = {}
+ self.const_idx = 0
+ self.bytecode = []
+
+ def append_byte(self, byte):
+ self.bytecode.append(('b', byte))
+
+ def get_byte(self, i):
+ typ, byte = self.bytecode[i]
+ assert typ == 'b'
+ return byte
+
+ def get_short(self, i):
+ typ, int = self.bytecode[i]
+ assert typ == 'h'
+ return int
+
+ def append_short(self, byte):
+ self.bytecode.append(('h', byte))
+
+ def append_int(self, byte):
+ self.bytecode.append(('i', byte))
+
+ def const_str(self, str):
+ self.consts[self.const_idx] = str
+ self.append_short(self.const_idx)
+ self.const_idx += 1
+
+ def to_string(self):
+ code = []
+ for typ, nmr in self.bytecode:
+ code.append(struct.pack(typ, nmr))
+ return ''.join(code)
+
+def requires_stack(*types):
+ def method(clazz):
+ clazz._stack_types = tuple(types)
+ return clazz
+
+ return method
+
+@requires_stack()
+class CondJump(ByteCode):
+ BYTE_CODE = unique_code()
+
+ COND_EQ = 0
+ COND_LT = 1
+ COND_GT = 2
+ COND_LE = 3
+ COND_GE = 4
+
+ def __init__(self, cond):
+ self.cond = cond
+ def encode(self, ctx):
+ ctx.append_byte(self.BYTE_CODE)
+ ctx.append_byte(self.cond)
+
+@requires_stack()
+class Jump(ByteCode):
+ BYTE_CODE = unique_code()
+ def __init__(self):
+ pass
+
+@requires_stack()
+class LoadStr(ByteCode):
+ BYTE_CODE = unique_code()
+ def __init__(self, string):
+ self.string = string
+ def encode(self, ctx):
+ ctx.append_byte(self.BYTE_CODE)
+ ctx.const_str(self.string)
+
+@requires_stack(STR_TYP, STR_TYP)
+class AddStr(ByteCode):
+ BYTE_CODE = unique_code()
+ def __init__(self):
+ pass
+
+@requires_stack(LIST_TYP, LIST_TYP)
+class AddList(ByteCode):
+ BYTE_CODE = unique_code()
+ def __init__(self):
+ pass
+
+@requires_stack()
+class CreateList(ByteCode):
+ BYTE_CODE = unique_code()
+ def __init__(self, size=8):
+ self.size = size
+ def encode(self, ctx):
+ ctx.append_byte(self.BYTE_CODE)
+ ctx.append_short(self.size)
+
+@requires_stack()
+class PutInt(ByteCode):
+ BYTE_CODE = unique_code()
+ def __init__(self, value):
+ self.integral = value
+ def encode(self, ctx):
+ ctx.append_byte(self.BYTE_CODE)
+ ctx.append_short(self.integral)
+
+@requires_stack(LIST_TYP, INT_TYP, VAL_TYP)
+class InsertList(ByteCode):
+ BYTE_CODE = unique_code()
+ def __init__(self, index):
+ self.index = index
+ def encode(self, ctx):
+ ctx.append_byte(self.BYTE_CODE)
+ ctx.append_int(self.index)
+
+@requires_stack(LIST_TYP, INT_TYP)
+class DelList(ByteCode):
+ BYTE_CODE = unique_code()
+ def __init__(self, index):
+ self.index = index
+ def encode(self, ctx):
+ ctx.append_byte(self.BYTE_CODE)
+ ctx.append_int(self.index)
+
+@requires_stack(LIST_TYP, INT_TYP, VAL_TYP)
+class AppendList(ByteCode):
+ BYTE_CODE = unique_code()
+ def __init__(self):
+ pass
+
+@requires_stack(LIST_TYP)
+class LenList(ByteCode):
+ BYTE_CODE = unique_code()
+ def __init__(self):
+ self.required_stack('l')
+
+@requires_stack(INT_TYP, INT_TYP)
+class CompareInt(ByteCode):
+ BYTE_CODE = unique_code()
+ def __init__(self):
+ pass
diff --git a/rpython/jit/backend/llsupport/gcstress/interp.py
b/rpython/jit/backend/llsupport/gcstress/interp.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/backend/llsupport/gcstress/interp.py
@@ -0,0 +1,23 @@
+class W_Root(object):
+ pass
+
+class W_ListObject(W_Root):
+ def __init__(self):
+ self.items = []
+
+def entry_point(argv):
+ pass
+ #bytecode = argv[0]
+ #pc = 0
+ #end = len(bytecode)
+ #stack = Stack(512)
+ #while i < end:
+ # opcode = ord(bytecode[i])
+ # if opcode == 0x0:
+ # stack.push(space.new_list())
+ # elif opcode == 0x1:
+ # w_elem = stack.pop()
+ # w_list = stack.pick(0)
+ # space.list_append(w_list, w_elem)
+ # i += 1
+ #return 0
diff --git a/rpython/jit/backend/llsupport/gcstress/stack.py
b/rpython/jit/backend/llsupport/gcstress/stack.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/backend/llsupport/gcstress/stack.py
@@ -0,0 +1,55 @@
+from rpython.rlib.jit import JitDriver, hint, dont_look_inside, promote
+
+class Stack(object):
+ _virtualizable_ = ['stackpos', 'stack[*]']
+
+ def __init__(self, size):
+ self = hint(self, access_directly=True, fresh_virtualizable=True)
+ self.stack = [0] * size
+ self.stackpos = 0 # always store a known-nonneg integer here
+
+ def append(self, elem):
+ self.stack[self.stackpos] = elem
+ self.stackpos += 1
+
+ def pop(self):
+ stackpos = self.stackpos - 1
+ if stackpos < 0:
+ raise IndexError
+ self.stackpos = stackpos # always store a known-nonneg integer here
+ return self.stack[stackpos]
+
+ def pick(self, i):
+ n = self.stackpos - i - 1
+ assert n >= 0
+ self.append(self.stack[n])
+
+ def put(self, i):
+ elem = self.pop()
+ n = self.stackpos - i - 1
+ assert n >= 0
+ self.stack[n] = elem
+
+ @dont_look_inside
+ def roll(self, r):
+ if r < -1:
+ i = self.stackpos + r
+ if i < 0:
+ raise IndexError
+ n = self.stackpos - 1
+ assert n >= 0
+ elem = self.stack[n]
+ for j in range(self.stackpos - 2, i - 1, -1):
+ assert j >= 0
+ self.stack[j + 1] = self.stack[j]
+ self.stack[i] = elem
+ elif r > 1:
+ i = self.stackpos - r
+ if i < 0:
+ raise IndexError
+ elem = self.stack[i]
+ for j in range(i, self.stackpos - 1):
+ self.stack[j] = self.stack[j + 1]
+ n = self.stackpos - 1
+ assert n >= 0
+ self.stack[n] = elem
diff --git a/rpython/jit/backend/llsupport/gcstress/test/__init__.py
b/rpython/jit/backend/llsupport/gcstress/test/__init__.py
new file mode 100644
diff --git a/rpython/jit/backend/llsupport/gcstress/test/test_interp.py
b/rpython/jit/backend/llsupport/gcstress/test/test_interp.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/backend/llsupport/gcstress/test/test_interp.py
@@ -0,0 +1,22 @@
+
+from rpython.jit.backend.llsupport.gcstress import code
+
+class TestByteCode(object):
+ def test_load_str(self):
+ c = code.Context()
+ code.LoadStr("hello world").encode(c)
+ assert c.consts[0] == "hello world"
+ assert c.get_byte(0) == code.LoadStr.BYTE_CODE
+ assert c.get_short(1) == 0
+
+ def test_str_add(self):
+ c = code.Context()
+ code.LoadStr("hello").encode(c)
+ code.LoadStr("world").encode(c)
+ code.AddStr().encode(c)
+ assert len(c.consts) == 2
+ assert c.get_byte(4) == code.AddStr.BYTE_CODE
+ assert c.get_short(3) == 1
+
+class TestInterp(object):
+ pass
diff --git a/rpython/jit/backend/llsupport/gcstress/test/zrpy_gc_hypo_test.py
b/rpython/jit/backend/llsupport/gcstress/test/zrpy_gc_hypo_test.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/backend/llsupport/gcstress/test/zrpy_gc_hypo_test.py
@@ -0,0 +1,33 @@
+from rpython.jit.backend.detect_cpu import getcpuclass
+from rpython.jit.tool.oparser import parse
+from rpython.jit.metainterp.history import JitCellToken, NoStats
+from rpython.jit.metainterp.history import BasicFinalDescr, BasicFailDescr
+from rpython.jit.metainterp.gc import get_description
+from rpython.jit.metainterp.optimize import SpeculativeError
+from rpython.annotator.listdef import s_list_of_strings
+from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
+from rpython.rtyper.rclass import getclassrepr, getinstancerepr
+from rpython.translator.unsimplify import call_initial_function
+from rpython.translator.translator import TranslationContext
+from rpython.translator.c import genc
+from rpython.jit.backend.llsupport.gcstress import interp
+
+class GCHypothesis(object):
+ def setup_class(self):
+ t = TranslationContext()
+ t.config.translation.gc = "incminimark"
+ t.config.translation.gcremovetypeptr = True
+ ann = t.buildannotator()
+ ann.build_types(interp.entry_point, [s_list_of_strings],
main_entry_point=True)
+ rtyper = t.buildrtyper()
+ rtyper.specialize()
+
+ cbuilder = genc.CStandaloneBuilder(t, f, t.config)
+ cbuilder.generate_source(defines=cbuilder.DEBUG_DEFINES)
+ cbuilder.compile()
+
+ import pdb; pdb.set_trace()
+
+
+ def test_void(self):
+ pass
diff --git a/rpython/jit/backend/zarch/test/test_rpy_gc.py
b/rpython/jit/backend/zarch/test/test_rpy_gc.py
new file mode 100644
diff --git a/rpython/jit/backend/zarch/test/test_zrpy_gc_hypo.py
b/rpython/jit/backend/zarch/test/test_zrpy_gc_hypo.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/backend/zarch/test/test_zrpy_gc_hypo.py
@@ -0,0 +1,7 @@
+from rpython.jit.backend.llsupport.gcstress.test.zrpy_gc_hypo_test import
GCHypothesis
+
+
+class TestGCHypothesis(GCHypothesis):
+ # runs ../../llsupport/gcstress/test/zrpy_gc_hypo_test.py
+ gcrootfinder = "shadowstack"
+ gc = "incminimark"
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit