"Fossies" - the Fresh Open Source Software Archive

Member "julia-1.1.1/share/julia/test/gcext/LocalTest.jl" (16 May 2019, 2301 Bytes) of package /linux/misc/julia-1.1.1-linux-i686.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Julia source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # This file is a part of Julia. License is MIT: https://julialang.org/license
    2 
    3 const Stack = Main.TestGCExt.Stack
    4 
    5 function make()
    6     ccall(:stk_make, Stack, ())
    7 end
    8 
    9 function push(stack :: Stack, val :: String)
   10     ccall(:stk_push, Nothing, (Stack, String), stack, val)
   11 end
   12 
   13 function top(stack :: Stack)
   14     return ccall(:stk_top, String, (Stack,), stack)
   15 end
   16 
   17 function pop(stack :: Stack)
   18     return ccall(:stk_pop, String, (Stack,), stack)
   19 end
   20 
   21 function size(stack :: Stack)
   22     return ccall(:stk_size, UInt, (Stack,), stack)
   23 end
   24 
   25 function empty(stack :: Stack)
   26     return size(stack) == 0
   27 end
   28 
   29 function blob(stack :: Stack)
   30     return ccall(:stk_blob, Any, (Stack,), stack)
   31 end
   32 
   33 function gc_counter_full()
   34     return ccall(:get_gc_counter, UInt, (Cint,), 1)
   35 end
   36 
   37 function gc_counter_inc()
   38     return ccall(:get_gc_counter, UInt, (Cint,), 0)
   39 end
   40 
   41 function gc_counter()
   42     return gc_counter_full() + gc_counter_inc()
   43 end
   44 
   45 function num_obj_sweeps()
   46     return ccall(:get_obj_sweeps, UInt, ())
   47 end
   48 
   49 function get_aux_root(n :: Int)
   50     return ccall(:get_aux_root, String, (UInt,), n)
   51 end
   52 
   53 function set_aux_root(n :: Int, x :: String)
   54     return ccall(:set_aux_root, Nothing, (UInt, String), n, x)
   55 end
   56 
   57 function internal_obj_scan(p :: Any)
   58     if ccall(:internal_obj_scan, Cint, (Any,), p) == 0
   59         global internal_obj_scan_failures += 1
   60     end
   61 end
   62 
   63 global internal_obj_scan_failures = 0
   64 
   65 for i in 0:1000
   66     set_aux_root(i, string(i))
   67 end
   68 
   69 function test()
   70     local stack = make()
   71     for i in 1:100000
   72         push(stack, string(i, base=2))
   73         internal_obj_scan(top(stack))
   74     end
   75     for i in 1:1000
   76         local stack2 = make()
   77         internal_obj_scan(stack2)
   78         internal_obj_scan(blob(stack2))
   79         while !empty(stack)
   80             push(stack2, pop(stack))
   81         end
   82         stack = stack2
   83         if i % 100 == 0
   84             GC.gc()
   85         end
   86     end
   87 end
   88 
   89 @time test()
   90 
   91 global corrupted_roots = 0
   92 for i in 0:1000
   93     if get_aux_root(i) != string(i)
   94         global corrupted_roots += 1
   95     end
   96 end
   97 
   98 print(gc_counter_full(), " full collections.\n")
   99 print(gc_counter_inc(), " partial collections.\n")
  100 print(num_obj_sweeps(), " object sweeps.\n")
  101 print(internal_obj_scan_failures, " internal object scan failures.\n")
  102 print(corrupted_roots, " corrupted auxiliary roots.\n")