<s> from pypy . rlib . jit import JitDriver <EOL> from pypy . jit . metainterp . test . test_basic import LLJitMixin , OOJitMixin <EOL> from pypy . jit . metainterp import pyjitpl <EOL> class BlackholeTests ( object ) : <EOL> def meta_interp ( self , * args ) : <EOL> def counting_init ( frame , metainterp , jitcode ) : <EOL> previnit ( frame , metainterp , jitcode ) <EOL> self . seen_frames . append ( jitcode . name ) <EOL> previnit = pyjitpl . MIFrame . __init__ . im_func <EOL> try : <EOL> self . seen_frames = [ ] <EOL> pyjitpl . MIFrame . __init__ = counting_init <EOL> return super ( BlackholeTests , self ) . meta_interp ( * args ) <EOL> finally : <EOL> pyjitpl . MIFrame . __init__ = previnit <EOL> def test_calls_not_followed ( self ) : <EOL> myjitdriver = JitDriver ( greens = [ ] , reds = [ '<STR_LIT:n>' ] ) <EOL> def h ( ) : <EOL> return <NUM_LIT> <EOL> def g ( ) : <EOL> return h ( ) <EOL> def f ( n ) : <EOL> while n > <NUM_LIT:0> : <EOL> myjitdriver . can_enter_jit ( n = n ) <EOL> myjitdriver . jit_merge_point ( n = n ) <EOL> n -= <NUM_LIT:1> <EOL> return g ( ) <EOL> res = self . meta_interp ( f , [ <NUM_LIT:7> ] ) <EOL> assert res == <NUM_LIT> <EOL> assert self . seen_frames == [ '<STR_LIT:f>' , '<STR_LIT:f>' ] <EOL> def test_indirect_calls_not_followed ( self ) : <EOL> myjitdriver = JitDriver ( greens = [ ] , reds = [ '<STR_LIT:n>' ] ) <EOL> def h ( ) : <EOL> return <NUM_LIT> <EOL> def g ( ) : <EOL> return h ( ) <EOL> def f ( n ) : <EOL> while n > <NUM_LIT:0> : <EOL> myjitdriver . can_enter_jit ( n = n ) <EOL> myjitdriver . jit_merge_point ( n = n ) <EOL> n -= <NUM_LIT:1> <EOL> if n < <NUM_LIT:0> : <EOL> call = h <EOL> else : <EOL> call = g <EOL> return call ( ) <EOL> res = self . meta_interp ( f , [ <NUM_LIT:7> ] ) <EOL> assert res == <NUM_LIT> <EOL> assert self . seen_frames == [ '<STR_LIT:f>' , '<STR_LIT:f>' ] <EOL> def test_oosends_not_followed ( self ) : <EOL> myjitdriver = JitDriver ( greens = [ ] , reds = [ '<STR_LIT:n>' ] ) <EOL> class A : <EOL> def meth ( self ) : <EOL> return <NUM_LIT> <EOL> class B ( A ) : <EOL> def meth ( self ) : <EOL> return <NUM_LIT> <EOL> class C ( A ) : <EOL> def meth ( self ) : <EOL> return <NUM_LIT:64> <EOL> def f ( n ) : <EOL> while n > <NUM_LIT:0> : <EOL> myjitdriver . can_enter_jit ( n = n ) <EOL> myjitdriver . jit_merge_point ( n = n ) <EOL> n -= <NUM_LIT:1> <EOL> if n < <NUM_LIT:0> : <EOL> x = B ( ) <EOL> else : <EOL> x = C ( ) <EOL> return x . meth ( ) <EOL> res = self . meta_interp ( f , [ <NUM_LIT:7> ] ) <EOL> assert res == <NUM_LIT:64> <EOL> assert self . seen_frames == [ '<STR_LIT:f>' , '<STR_LIT:f>' ] <EOL> class TestLLtype ( BlackholeTests , LLJitMixin ) : <EOL> pass <EOL> class TestOOtype ( BlackholeTests , OOJitMixin ) : <EOL> pass </s>
