Author: Remi Meier <[email protected]>
Branch: stmgc-c4
Changeset: r66205:a95356764f49
Date: 2013-08-19 08:58 +0200
http://bitbucket.org/pypy/pypy/changeset/a95356764f49/
Log: start using allocate_public_integer_address. Breaks tests in
test_stm_integration.py...
diff --git a/rpython/jit/backend/llsupport/assembler.py
b/rpython/jit/backend/llsupport/assembler.py
--- a/rpython/jit/backend/llsupport/assembler.py
+++ b/rpython/jit/backend/llsupport/assembler.py
@@ -195,10 +195,7 @@
# we want the descr to keep alive
guardtok.faildescr.rd_loop_token = self.current_clt
fail_descr = rgc.cast_instance_to_gcref(guardtok.faildescr)
- if self.cpu.gc_ll_descr.stm:
- # only needed with STM, I think..
- fail_descr = rgc._make_sure_does_not_move(fail_descr)
- fail_descr = rgc.cast_gcref_to_int(fail_descr)
+ fail_descr = rgc._make_sure_does_not_move(fail_descr)
return fail_descr, target
def call_assembler(self, op, guard_op, argloc, vloc, result_loc, tmploc):
@@ -230,8 +227,7 @@
raise AssertionError(kind)
gcref = rgc.cast_instance_to_gcref(value)
- gcref = rgc._make_sure_does_not_move(gcref)
- value = rgc.cast_gcref_to_int(gcref)
+ value = rgc._make_sure_does_not_move(gcref)
je_location = self._call_assembler_check_descr(value, tmploc)
#
# Path A: use assembler_helper_adr
diff --git a/rpython/jit/backend/llsupport/gc.py
b/rpython/jit/backend/llsupport/gc.py
--- a/rpython/jit/backend/llsupport/gc.py
+++ b/rpython/jit/backend/llsupport/gc.py
@@ -103,27 +103,19 @@
v = op.getarg(i)
if isinstance(v, ConstPtr) and bool(v.value):
p = rgc.cast_instance_to_gcref(v.value)
- new_p = rgc._make_sure_does_not_move(p)
- if we_are_translated():
- v.value = new_p
- else:
- assert p == new_p
- gcrefs_output_list.append(new_p)
-
+ v.imm_value = rgc._make_sure_does_not_move(p)
+ # XXX: fix for stm, record imm_values and unregister
+ # them again (below too):
+ gcrefs_output_list.append(p)
+
+ if self.stm:
+ return # for descr, we do it on the fly in assembler.py
if op.is_guard() or op.getopnum() == rop.FINISH:
# the only ops with descrs that get recorded in a trace
- from rpython.jit.metainterp.history import AbstractDescr
descr = op.getdescr()
llref = rgc.cast_instance_to_gcref(descr)
- new_llref = rgc._make_sure_does_not_move(llref)
- if we_are_translated():
- new_d = rgc.try_cast_gcref_to_instance(AbstractDescr,
- new_llref)
- # tests don't allow this:
- op.setdescr(new_d)
- else:
- assert llref == new_llref
- gcrefs_output_list.append(new_llref)
+ rgc._make_sure_does_not_move(llref)
+ gcrefs_output_list.append(llref)
def rewrite_assembler(self, cpu, operations, gcrefs_output_list):
if not self.stm:
@@ -711,6 +703,12 @@
if self.stm:
# XXX remove the indirections in the following calls
from rpython.rlib import rstm
+ def stm_allocate_nonmovable_int_adr(obj):
+ return llop1.stm_allocate_nonmovable_int_adr(
+ lltype.Signed, obj)
+ self.generate_function('stm_allocate_nonmovable_int_adr',
+ stm_allocate_nonmovable_int_adr,
+ [llmemory.GCREF], RESULT=lltype.Signed)
self.generate_function('stm_try_inevitable',
rstm.become_inevitable, [],
RESULT=lltype.Void)
diff --git a/rpython/jit/backend/x86/assembler.py
b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -249,9 +249,8 @@
self._store_and_reset_exception(self.mc, eax)
ofs = self.cpu.get_ofs_of_frame_field('jf_guard_exc')
self.mc.MOV_br(ofs, eax.value)
- propagate_exception_descr = rgc.cast_gcref_to_int(
- rgc._make_sure_does_not_move(
-
rgc.cast_instance_to_gcref(self.cpu.propagate_exception_descr)))
+ propagate_exception_descr = rgc._make_sure_does_not_move(
+ rgc.cast_instance_to_gcref(self.cpu.propagate_exception_descr))
ofs = self.cpu.get_ofs_of_frame_field('jf_descr')
self.mc.MOV(RawEbpLoc(ofs), imm(propagate_exception_descr))
self.mc.MOV_rr(eax.value, ebp.value)
@@ -2122,10 +2121,10 @@
cb.emit()
def _store_force_index(self, guard_op):
- faildescr = guard_op.getdescr()
+ faildescr = rgc._make_sure_does_not_move(
+ rgc.cast_instance_to_gcref(guard_op.getdescr()))
ofs = self.cpu.get_ofs_of_frame_field('jf_force_descr')
- self.mc.MOV(raw_stack(ofs), imm(rffi.cast(lltype.Signed,
- cast_instance_to_gcref(faildescr))))
+ self.mc.MOV(raw_stack(ofs), imm(faildescr))
def _emit_guard_not_forced(self, guard_token):
ofs = self.cpu.get_ofs_of_frame_field('jf_descr')
diff --git a/rpython/jit/backend/x86/regalloc.py
b/rpython/jit/backend/x86/regalloc.py
--- a/rpython/jit/backend/x86/regalloc.py
+++ b/rpython/jit/backend/x86/regalloc.py
@@ -8,7 +8,7 @@
BoxFloat, INT, REF, FLOAT,
TargetToken)
from rpython.jit.backend.x86.regloc import *
-from rpython.rtyper.lltypesystem import lltype, rffi, rstr
+from rpython.rtyper.lltypesystem import lltype, rffi, rstr, llmemory
from rpython.rtyper.annlowlevel import cast_instance_to_gcref
from rpython.rlib.objectmodel import we_are_translated
from rpython.rlib import rgc
@@ -45,9 +45,11 @@
if isinstance(c, ConstInt):
return imm(c.value)
elif isinstance(c, ConstPtr):
- if we_are_translated() and c.value and rgc.can_move(c.value):
+ # if we_are_translated() and c.value and rgc.can_move(c.value):
+ # not_implemented("convert_to_imm: ConstPtr needs special
care")
+ if c.value and not c.imm_value:
not_implemented("convert_to_imm: ConstPtr needs special care")
- return imm(rffi.cast(lltype.Signed, c.value))
+ return imm(c.get_imm_value())
else:
not_implemented("convert_to_imm: got a %s" % c)
@@ -369,7 +371,6 @@
fail_descr = rgc.cast_instance_to_gcref(descr)
# we know it does not move, but well
fail_descr = rgc._make_sure_does_not_move(fail_descr)
- fail_descr = rgc.cast_gcref_to_int(fail_descr)
if op.numargs() == 1:
loc = self.make_sure_var_in_reg(op.getarg(0))
locs = [loc, imm(fail_descr)]
diff --git a/rpython/jit/backend/x86/test/test_stm_integration.py
b/rpython/jit/backend/x86/test/test_stm_integration.py
--- a/rpython/jit/backend/x86/test/test_stm_integration.py
+++ b/rpython/jit/backend/x86/test/test_stm_integration.py
@@ -21,10 +21,14 @@
from rpython.memory.gc.stmgc import StmGC
from rpython.jit.metainterp import history
from rpython.jit.codewriter.effectinfo import EffectInfo
+from rpython.rlib import rgc
from rpython.rtyper.llinterp import LLException
import itertools, sys
import ctypes
+def cast_to_int(obj):
+ return rgc.cast_gcref_to_int(rgc.cast_instance_to_gcref(obj))
+
CPU = getcpuclass()
class MockSTMRootMap(object):
@@ -171,6 +175,14 @@
self.generate_function('stm_ptr_eq', ptr_eq, [llmemory.GCREF] * 2,
RESULT=lltype.Bool)
+ def stm_allocate_nonmovable_int_adr(obj):
+ assert False # should not be reached
+ return rgc.cast_gcref_to_int(obj)
+ self.generate_function('stm_allocate_nonmovable_int_adr',
+ stm_allocate_nonmovable_int_adr,
+ [llmemory.GCREF],
+ RESULT=lltype.Signed)
+
def malloc_big_fixedsize(size, tid):
entries = size + StmGC.GCHDRSIZE
TP = rffi.CArray(lltype.Char)
diff --git a/rpython/jit/metainterp/history.py
b/rpython/jit/metainterp/history.py
--- a/rpython/jit/metainterp/history.py
+++ b/rpython/jit/metainterp/history.py
@@ -10,6 +10,7 @@
from rpython.jit.metainterp.resoperation import ResOperation, rop
from rpython.jit.codewriter import heaptracker, longlong
from rpython.rlib.objectmodel import compute_identity_hash
+from rpython.rlib import rgc
import weakref
# ____________________________________________________________
@@ -308,17 +309,24 @@
class ConstPtr(Const):
type = REF
value = lltype.nullptr(llmemory.GCREF.TO)
- _attrs_ = ('value',)
+ imm_value = 0
+ _attrs_ = ('value', 'imm_value',)
def __init__(self, value):
assert lltype.typeOf(value) == llmemory.GCREF
self.value = value
+ self.imm_value = 0
def clonebox(self):
return BoxPtr(self.value)
nonconstbox = clonebox
+ def get_imm_value(self):
+ # imm_value set if needed:
+ assert (not self.value) or self.imm_value
+ return self.imm_value
+
def getref_base(self):
return self.value
diff --git a/rpython/memory/gctransform/framework.py
b/rpython/memory/gctransform/framework.py
--- a/rpython/memory/gctransform/framework.py
+++ b/rpython/memory/gctransform/framework.py
@@ -314,13 +314,6 @@
self.can_move_ptr = getfn(GCClass.can_move.im_func,
[s_gc, annmodel.SomeAddress()],
annmodel.SomeBool())
- if hasattr(GCClass, 'get_original_copy'):
- self.get_original_copy_ptr = getfn(
- GCClass.get_original_copy.im_func,
- [s_gc, annmodel.SomePtr(llmemory.GCREF)],
- annmodel.SomePtr(llmemory.GCREF))
- else:
- self.get_original_copy_ptr = None
if hasattr(GCClass, 'shrink_array'):
self.shrink_array_ptr = getfn(
@@ -751,16 +744,6 @@
hop.genop("direct_call", [self.can_move_ptr, self.c_const_gc, v_addr],
resultvar=op.result)
- def gct_gc_get_original_copy(self, hop):
- if self.get_original_copy_ptr is None:
- raise Exception("unreachable code")
- op = hop.spaceop
- v_addr = hop.genop('cast_ptr_to_adr',
- [op.args[0]], resulttype=llmemory.Address)
- hop.genop("direct_call", [self.get_original_copy_ptr,
- self.c_const_gc, v_addr],
- resultvar=op.result)
-
def gct_shrink_array(self, hop):
if self.shrink_array_ptr is None:
return GCTransformer.gct_shrink_array(self, hop)
diff --git a/rpython/memory/gctransform/stmframework.py
b/rpython/memory/gctransform/stmframework.py
--- a/rpython/memory/gctransform/stmframework.py
+++ b/rpython/memory/gctransform/stmframework.py
@@ -99,6 +99,7 @@
gct_stm_become_inevitable = _gct_with_roots_pushed
gct_stm_perform_transaction = _gct_with_roots_pushed
+ gct_stm_allocate_nonmovable_int_adr = _gct_with_roots_pushed
class StmRootWalker(BaseRootWalker):
diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py
--- a/rpython/rlib/rgc.py
+++ b/rpython/rlib/rgc.py
@@ -26,12 +26,6 @@
return None # means 'not translated at all';
# in "if stm_is_enabled()" it is equivalent to False
-def stm_get_original_copy(obj):
- """ Returns a non-moving reference to an object (only use if obj is
- already OLD!)
- """
- return obj
-
# ____________________________________________________________
# Annotation and specialization
@@ -76,20 +70,6 @@
hop.exception_cannot_occur()
return hop.inputconst(lltype.Bool, hop.s_result.const)
-
-class StmGCGetOriginalCopy(ExtRegistryEntry):
- _about_ = stm_get_original_copy
-
- def compute_result_annotation(self, s_obj):
- from rpython.annotator import model as annmodel
- return annmodel.SomePtr(llmemory.GCREF)
-
- def specialize_call(self, hop):
- hop.exception_cannot_occur()
- return hop.genop('gc_get_original_copy', hop.args_v,
- resulttype=hop.r_result)
-
-
def can_move(p):
"""Check if the GC object 'p' is at an address that can move.
Must not be called with None. With non-moving GCs, it is always False.
@@ -119,7 +99,13 @@
on objects that are already a bit old, so have a chance to be
already non-movable."""
if not we_are_translated():
- return p
+ return cast_gcref_to_int(p)
+
+ if stm_is_enabled():
+ from rpython.rtyper.lltypesystem.lloperation import llop
+ res = llop.stm_allocate_nonmovable_int_adr(lltype.Signed, p)
+ return res
+
i = 0
while can_move(p):
if i > 6:
@@ -127,10 +113,7 @@
collect(i)
i += 1
- if stm_is_enabled():
- return stm_get_original_copy(p)
- else:
- return p
+ return 0
def _heap_stats():
raise NotImplementedError # can't be run directly
diff --git a/rpython/rtyper/lltypesystem/lloperation.py
b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -425,6 +425,7 @@
'stm_finalize': LLOp(),
'stm_barrier': LLOp(sideeffects=False),
'stm_allocate': LLOp(sideeffects=False, canmallocgc=True),
+ 'stm_allocate_nonmovable_int_adr': LLOp(sideeffects=False,
canmallocgc=True),
'stm_become_inevitable': LLOp(canmallocgc=True),
'stm_minor_collect': LLOp(canmallocgc=True),
'stm_major_collect': LLOp(canmallocgc=True),
@@ -533,7 +534,6 @@
'gc_obtain_free_space': LLOp(),
'gc_set_max_heap_size': LLOp(),
'gc_can_move' : LLOp(sideeffects=False),
- 'gc_get_original_copy': LLOp(sideeffects=False),
'gc_thread_prepare' : LLOp(canmallocgc=True),
'gc_thread_run' : LLOp(),
'gc_thread_start' : LLOp(),
diff --git a/rpython/translator/c/funcgen.py b/rpython/translator/c/funcgen.py
--- a/rpython/translator/c/funcgen.py
+++ b/rpython/translator/c/funcgen.py
@@ -617,6 +617,7 @@
OP_STM_MAJOR_COLLECT = _OP_STM
OP_STM_MINOR_COLLECT = _OP_STM
OP_STM_CLEAR_EXCEPTION_DATA_ON_ABORT= _OP_STM
+ OP_STM_ALLOCATE_NONMOVABLE_INT_ADR = _OP_STM
def OP_PTR_NONZERO(self, op):
diff --git a/rpython/translator/stm/funcgen.py
b/rpython/translator/stm/funcgen.py
--- a/rpython/translator/stm/funcgen.py
+++ b/rpython/translator/stm/funcgen.py
@@ -117,6 +117,11 @@
result = funcgen.expr(op.result)
return '%s = stm_weakref_allocate(%s, %s, %s);' % (result, arg0,
arg1, arg2)
+
+def stm_allocate_nonmovable_int_adr(funcgen, op):
+ arg0 = funcgen.expr(op.args[0])
+ result = funcgen.expr(op.result)
+ return '%s = stm_allocate_public_integer_address(%s);' % (result, arg0)
def stm_allocate(funcgen, op):
arg0 = funcgen.expr(op.args[0])
diff --git a/rpython/translator/stm/inevitable.py
b/rpython/translator/stm/inevitable.py
--- a/rpython/translator/stm/inevitable.py
+++ b/rpython/translator/stm/inevitable.py
@@ -15,8 +15,7 @@
'jit_force_quasi_immutable', 'jit_marker', 'jit_is_virtual',
'jit_record_known_class',
'gc_identityhash', 'gc_id', 'gc_can_move', 'gc__collect',
- 'gc_adr_of_root_stack_top', 'gc_get_original_copy',
- 'stmgc_get_original_copy',
+ 'gc_adr_of_root_stack_top',
'weakref_create', 'weakref_deref',
'stm_threadlocalref_get', 'stm_threadlocalref_set',
'stm_threadlocalref_count', 'stm_threadlocalref_addr',
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit