Browse Source

exclude with subtypes, auto load hlmemory.dump

ncannasse 6 years ago
parent
commit
a588852f83
2 changed files with 33 additions and 6 deletions
  1. 26 6
      other/memory/Memory.hx
  2. 7 0
      other/memory/TType.hx

+ 26 - 6
other/memory/Memory.hx

@@ -255,6 +255,13 @@ class Memory {
 				var pt = closuresPointers[cid++];
 				if( pt != null )
 					pointerType.set(pt, ct);
+			case HObj(o):
+				if( o.tsuper != null )
+					for( j in 0...types.length )
+						if( types[j].t == o.tsuper ) {
+							types[i].parentClass = types[j];
+							break;
+						}
 			default:
 			}
 		}
@@ -597,20 +604,25 @@ class Memory {
 		}
 		var ctx = new Stats(this);
 		Block.MARK_UID++;
+		var mark = [];
 		for( b in blocks )
 			if( b.type == t )
-				visitRec(b, ctx, texclude);
+				visitRec(b,ctx,[],mark);
+		while( mark.length > 0 ) {
+			var b = mark.pop();
+			for( s in b.subs )
+				visitRec(s,ctx,texclude,mark);
+		}
 		ctx.print(true);
 	}
 
-	function visitRec( b : Block, ctx : Stats, exclude : Array<TType> ) {
+	function visitRec( b : Block, ctx : Stats, exclude : Array<TType>, mark : Array<Block> ) {
 		if( b.mark == Block.MARK_UID ) return;
 		b.mark = Block.MARK_UID;
-		for( t in exclude ) if( b.type == t ) return;
-		ctx.addPath([b.type.tid],b.getMemSize());
+		if( b.type != null ) for( t in exclude ) if( b.type.match(t) ) return;
+		ctx.addPath(b.type == null ? [] : [b.type.tid],b.getMemSize());
 		if( b.subs != null )
-			for( s in b.subs )
-				visitRec(s,ctx,exclude);
+			mark.push(b);
 	}
 
 	function parents( tstr : String, up = 0 ) {
@@ -763,15 +775,23 @@ class Memory {
 
 		//hl.Gc.dumpMemory(); Sys.command("cp memory.hl test.hl");
 
+		var code = null, memory = null;
 		var args = Sys.args();
 		while( args.length > 0 ) {
 			var arg = args.shift();
 			if( StringTools.endsWith(arg, ".hl") ) {
+				code = arg;
 				m.loadBytecode(arg);
 				continue;
 			}
+			memory = arg;
 			m.loadMemory(arg);
 		}
+		if( code != null && memory == null ) {
+			memory = new haxe.io.Path(code).dir+"/hlmemory.dump";
+			if( sys.FileSystem.exists(memory) ) m.loadMemory(memory);
+		}
+
 		m.check();
 
 		var stdin = Sys.stdin();

+ 7 - 0
other/memory/TType.hx

@@ -12,6 +12,7 @@ class TType {
 	public var constructs : Array<Array<TType>>;
 	public var nullWrap : TType;
 	public var ptrTags : haxe.io.Bytes;
+	public var parentClass : TType;
 
 	public var falsePositive = 0;
 	public var falsePositiveIndexes = [];
@@ -29,6 +30,12 @@ class TType {
 		}
 	}
 
+	public function match( t : TType ) {
+		if( t == this ) return true;
+		if( parentClass != null ) return parentClass.match(t);
+		return false;
+	}
+
 	function tagPtr( pos : Int ) {
 		var p = pos >> 5;
 		if( ptrTags == null || ptrTags.length <= p ) {