Advertisement
theambient

Untitled

Dec 9th, 2014
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.69 KB | None | 0 0
  1.     private auto _samples_addrs() const
  2.     {
  3.         const(AccessUnit)[] samples;
  4.  
  5.         if(_samples.keys().length > 0)
  6.         {
  7.             samples = _samples[_samples.keys()[0]];
  8.         }
  9.  
  10.         return map!(x => cast(void*)x)(samples);
  11.     }
  12.  
  13.     private static string attr(void * p)
  14.     {
  15.         import core.memory : GC;
  16.         auto root = GC.addrOf(p);
  17.         auto bi = GC.getAttr(root);
  18.  
  19.         auto map = [
  20.             GC.BlkAttr.FINALIZE : "FINALIZE",
  21.             GC.BlkAttr.NO_SCAN : "NO_SCAN",
  22.             GC.BlkAttr.NO_MOVE : "NO_MOVE",
  23.             GC.BlkAttr.APPENDABLE : "APPENDABLE",
  24.             GC.BlkAttr.NO_INTERIOR : "NO_INTERIOR",
  25.         ];
  26.  
  27.         string s = "";
  28.         foreach(k, v; map)
  29.         {
  30.             if(bi && k)
  31.             {
  32.                 s ~= v ~ " ";
  33.             }
  34.         }
  35.  
  36.         return s;
  37.     }
  38.  
  39.     invariant()
  40.     {
  41.         import core.memory;
  42.         std.stdio.stderr.writefln("-> invariant %s: as: %s samples: %s", cast(void*) this, _adapt_stream_index, _samples_addrs());
  43.  
  44.         //std.stdio.stderr.writefln("\t-> collect");
  45.         //GC.collect();
  46.         //std.stdio.stderr.writefln("\t<- collect");
  47.  
  48.         assert(GC.addrOf(cast(void*)this) !is null);
  49.  
  50.         foreach(as, s; _samples)
  51.         {
  52.             auto root = GC.addrOf(cast(void*) s.ptr);
  53.  
  54.             std.stdio.stderr.writefln("\t\tkeys ptr: %s root: %s:%s attr: %s", s.ptr, root, GC.sizeOf(root), attr(root));
  55.  
  56.             foreach(x; s)
  57.             {
  58.                 std.stdio.stderr.writefln("\t\t[%s] keys: %s as: %s au: %s", cast(void*) Thread.getThis(), _samples.keys, _adapt_stream_index, cast(void*)x);
  59.                 assert(GC.addrOf(cast(void*)x) !is null);
  60.                 //std.file.write("/dev/null", "%s".format(x.random_access));
  61.                 //auto s1 = x.random_access;
  62.             }
  63.  
  64.             foreach(x; s)
  65.             {
  66.                 auto s1 = x.random_access;
  67.             }
  68.         }
  69.         std.stdio.stderr.writefln("<- invariant %s", cast(void*) this);
  70.     }
  71.  
  72.     private AccessUnit[][StreamIndex] _samples;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement