Author: fijal
Branch: jit-leaner-frontend
Changeset: r83360:f364f082cc14
Date: 2016-03-25 16:05 +0200
http://bitbucket.org/pypy/pypy/changeset/f364f082cc14/

Log:    try to make an option for having two different models in case one
        wants to have really long traces

diff --git a/rpython/config/translationoption.py 
b/rpython/config/translationoption.py
--- a/rpython/config/translationoption.py
+++ b/rpython/config/translationoption.py
@@ -126,6 +126,9 @@
     ChoiceOption("jit_profiler", "integrate profiler support into the JIT",
                  ["off", "oprofile"],
                  default="off"),
+    ChoiceOption("jit_opencoder_model", "the model limits the maximal length"
+                 " of traces. Use big if you want to go bigger than "
+                 "the default", ["big", "normal"], default="normal"),
     BoolOption("check_str_without_nul",
                "Forbid NUL chars in strings in some external function calls",
                default=False, cmdline=None),
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
@@ -4,6 +4,7 @@
 from rpython.rlib.objectmodel import compute_unique_id, specialize
 from rpython.rlib.rarithmetic import r_int64, is_valid_int
 from rpython.rlib.rarithmetic import LONG_BIT, intmask, r_uint
+from rpython.rlib.jit import Counters
 
 from rpython.conftest import option
 
@@ -12,6 +13,7 @@
     opclasses
 from rpython.jit.codewriter import heaptracker, longlong
 import weakref
+from rpython.jit.metainterp import jitexc
 
 # ____________________________________________________________
 
@@ -25,6 +27,15 @@
 
 FAILARGS_LIMIT = 1000
 
+class SwitchToBlackhole(jitexc.JitException):
+    def __init__(self, reason, raising_exception=False):
+        self.reason = reason
+        self.raising_exception = raising_exception
+        # ^^^ must be set to True if the SwitchToBlackhole is raised at a
+        #     point where the exception on metainterp.last_exc_value
+        #     is supposed to be raised.  The default False means that it
+        #     should just be copied into the blackhole interp, but not raised.
+
 def getkind(TYPE, supports_floats=True,
                   supports_longlong=True,
                   supports_singlefloats=True):
@@ -712,12 +723,23 @@
             assert lltype.typeOf(value) == llmemory.GCREF
             op.setref_base(value)
 
+    def _record_op(self, opnum, argboxes, descr=None):
+        from rpython.jit.metainterp.opencoder import FrontendTagOverflow
+
+        try:
+            return self.trace.record_op(opnum, argboxes, descr)
+        except FrontendTagOverflow:
+            # note that with the default settings this one should not
+            # happen - however if we hit that case, we don't get
+            # anything disabled
+            raise SwitchToBlackhole(Counters.ABORT_TOO_LONG)
+
     @specialize.argtype(3)
     def record(self, opnum, argboxes, value, descr=None):
         if self.trace is None:
             pos = 2**14 - 1
         else:
-            pos = self.trace.record_op(opnum, argboxes, descr)
+            pos = self._record_op(opnum, argboxes, descr)
         if value is None:
             op = FrontendOp(pos)
         elif isinstance(value, bool):
@@ -735,7 +757,7 @@
 
     def record_nospec(self, opnum, argboxes, descr=None):
         tp = opclasses[opnum].type
-        pos = self.trace.record_op(opnum, argboxes, descr)
+        pos = self._record_op(opnum, argboxes, descr)
         if tp == 'v':
             return FrontendOp(pos)
         elif tp == 'i':
diff --git a/rpython/jit/metainterp/opencoder.py 
b/rpython/jit/metainterp/opencoder.py
--- a/rpython/jit/metainterp/opencoder.py
+++ b/rpython/jit/metainterp/opencoder.py
@@ -19,21 +19,32 @@
 TAGMASK = 0x3
 TAGSHIFT = 2
 
-STORAGE_TP = rffi.USHORT
-MAX_SIZE = 2**16-1
+class Model:
+    STORAGE_TP = rffi.USHORT
+    # this is the initial size of the trace - note that we probably
+    # want something that would fit the inital "max_trace_length"
+    INIT_SIZE = 30000
+    MIN_SHORT = 0
+    MAX_SHORT = 2**16 - 1
+    check_range = True
+
+class BigModel:
+    INIT_SIZE = 30000
+    STORAGE_TP = lltype.Signed
+    check_range = False
+    # we can move SMALL ints here, if necessary
+
+@specialize.memo()
+def get_model(self):
+    return getattr(self.metainterp_sd, 'opencoder_model', Model)
+
 SMALL_INT_STOP  = (2 ** (15 - TAGSHIFT)) - 1
 SMALL_INT_START = -SMALL_INT_STOP # we might want to distribute them uneven
-MIN_SHORT = 0
-MAX_SHORT = 2**16 - 1
 
 def expand_sizes_to_signed():
     """ This function will make sure we can use sizes all the
     way up to lltype.Signed for indexes everywhere
     """
-    globals()['STORAGE_TP'] = lltype.Signed
-    globals()['MAX_SIZE'] = 2**31-1
-    globals()['MIN_SHORT'] = -2**31
-    globals()['MAX_SHORT'] = 2**31 - 1
 
 class FrontendTagOverflow(Exception):
     pass
@@ -252,7 +263,8 @@
     _deadranges = (-1, None)
 
     def __init__(self, inputargs, metainterp_sd):
-        self._ops = [rffi.cast(STORAGE_TP, 0)] * MAX_SIZE
+        self.metainterp_sd = metainterp_sd
+        self._ops = [rffi.cast(get_model(self).STORAGE_TP, 0)] * 
get_model(self).INIT_SIZE
         self._pos = 0
         self._consts_bigint = 0
         self._consts_float = 0
@@ -273,15 +285,16 @@
         self._start = len(inputargs)
         self._pos = self._start
         self.inputargs = inputargs
-        self.metainterp_sd = metainterp_sd
 
     def append(self, v):
+        model = get_model(self)
         if self._pos >= len(self._ops):
             # grow by 2X
-            self._ops = self._ops + [rffi.cast(STORAGE_TP, 0)] * len(self._ops)
-        if not MIN_SHORT <= v <= MAX_SHORT:
-            raise FrontendTagOverflow
-        self._ops[self._pos] = rffi.cast(STORAGE_TP, v)
+            self._ops = self._ops + [rffi.cast(model.STORAGE_TP, 0)] * 
len(self._ops)
+        if model.check_range:
+            if not model.MIN_SHORT <= v <= model.MAX_SHORT:
+                raise FrontendTagOverflow
+        self._ops[self._pos] = rffi.cast(model.STORAGE_TP, v)
         self._pos += 1
 
     def done(self):
@@ -387,16 +400,16 @@
         return len(self._descrs) - 1 + len(self.metainterp_sd.all_descrs) + 1
 
     def _list_of_boxes(self, boxes):
-        array = [rffi.cast(STORAGE_TP, 0)] * len(boxes)
+        array = [rffi.cast(get_model(self).STORAGE_TP, 0)] * len(boxes)
         for i in range(len(boxes)):
             array[i] = self._encode_cast(boxes[i])
         return array
 
     def new_array(self, lgt):
-        return [rffi.cast(STORAGE_TP, 0)] * lgt
+        return [rffi.cast(get_model(self).STORAGE_TP, 0)] * lgt
 
     def _encode_cast(self, i):
-        return rffi.cast(STORAGE_TP, self._encode(i))
+        return rffi.cast(get_model(self).STORAGE_TP, self._encode(i))
 
     def create_top_snapshot(self, jitcode, pc, frame, flag, vable_boxes, 
vref_boxes):
         self._total_snapshots += 1
@@ -408,7 +421,7 @@
         assert rffi.cast(lltype.Signed, self._ops[self._pos - 1]) == 0
         # guards have no descr
         self._snapshots.append(s)
-        self._ops[self._pos - 1] = rffi.cast(STORAGE_TP, len(self._snapshots) 
- 1)
+        self._ops[self._pos - 1] = rffi.cast(get_model(self).STORAGE_TP, 
len(self._snapshots) - 1)
         return s
 
     def create_empty_top_snapshot(self, vable_boxes, vref_boxes):
@@ -420,7 +433,7 @@
         assert rffi.cast(lltype.Signed, self._ops[self._pos - 1]) == 0
         # guards have no descr
         self._snapshots.append(s)
-        self._ops[self._pos - 1] = rffi.cast(STORAGE_TP, len(self._snapshots) 
- 1)
+        self._ops[self._pos - 1] = rffi.cast(get_model(self).STORAGE_TP, 
len(self._snapshots) - 1)
         return s
 
     def create_snapshot(self, jitcode, pc, frame, flag):
@@ -474,8 +487,6 @@
         return iter.inputargs, ops
 
 def tag(kind, pos):
-    #if not SMALL_INT_START <= pos < SMALL_INT_STOP:
-    #    raise some error
     return (pos << TAGSHIFT) | kind
 
 @specialize.ll()
diff --git a/rpython/jit/metainterp/pyjitpl.py 
b/rpython/jit/metainterp/pyjitpl.py
--- a/rpython/jit/metainterp/pyjitpl.py
+++ b/rpython/jit/metainterp/pyjitpl.py
@@ -8,7 +8,7 @@
 from rpython.jit.metainterp import history, compile, resume, executor, jitexc
 from rpython.jit.metainterp.heapcache import HeapCache
 from rpython.jit.metainterp.history import (Const, ConstInt, ConstPtr,
-    ConstFloat, TargetToken, MissingValue)
+    ConstFloat, TargetToken, MissingValue, SwitchToBlackhole)
 from rpython.jit.metainterp.jitprof import EmptyProfiler
 from rpython.jit.metainterp.logger import Logger
 from rpython.jit.metainterp.optimizeopt.util import args_dict
@@ -3187,15 +3187,6 @@
     """Raised after we mutated metainterp.framestack, in order to force
     it to reload the current top-of-stack frame that gets interpreted."""
 
-class SwitchToBlackhole(jitexc.JitException):
-    def __init__(self, reason, raising_exception=False):
-        self.reason = reason
-        self.raising_exception = raising_exception
-        # ^^^ must be set to True if the SwitchToBlackhole is raised at a
-        #     point where the exception on metainterp.last_exc_value
-        #     is supposed to be raised.  The default False means that it
-        #     should just be copied into the blackhole interp, but not raised.
-
 NOT_HANDLED = history.CONST_FALSE
 
 # ____________________________________________________________
diff --git a/rpython/jit/metainterp/warmspot.py 
b/rpython/jit/metainterp/warmspot.py
--- a/rpython/jit/metainterp/warmspot.py
+++ b/rpython/jit/metainterp/warmspot.py
@@ -239,7 +239,8 @@
         elif self.opt.listops:
             self.prejit_optimizations_minimal_inline(policy, graphs)
 
-        self.build_meta_interp(ProfilerClass)
+        self.build_meta_interp(ProfilerClass,
+                             translator.config.translation.jit_opencoder_model)
         self.make_args_specifications()
         #
         from rpython.jit.metainterp.virtualref import VirtualRefInfo
@@ -478,11 +479,16 @@
             cpu.supports_singlefloats = False
         self.cpu = cpu
 
-    def build_meta_interp(self, ProfilerClass):
+    def build_meta_interp(self, ProfilerClass, opencoder_model):
+        from rpython.jit.metainterp.opencoder import Model, BigModel
         self.metainterp_sd = MetaInterpStaticData(self.cpu,
                                                   self.opt,
                                                   ProfilerClass=ProfilerClass,
                                                   warmrunnerdesc=self)
+        if opencoder_model == 'big':
+            self.metainterp_sd.opencoder_model = BigModel
+        else:
+            self.metainterp_sd.opencoder_model = Model            
         self.stats.metainterp_sd = self.metainterp_sd
 
     def make_virtualizable_infos(self):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to