From 0437e95b4f1982268969f080b5e2e4cc8ae3811d Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Thu, 9 Jul 2015 10:31:50 +0200 Subject: [PATCH] do not instantiate millions of HighlightData --- .../decompiler/flash/abc/avm2/graph/AVM2Graph.java | 4 ++-- .../abc/avm2/instructions/other/SetPropertyIns.java | 2 +- .../decompiler/flash/abc/avm2/model/AVM2Item.java | 8 +++++--- .../flash/abc/avm2/model/GetLexAVM2Item.java | 12 ++++++------ .../flash/abc/avm2/model/GetSlotAVM2Item.java | 2 +- .../flash/abc/avm2/model/InitPropertyAVM2Item.java | 2 +- .../flash/abc/avm2/model/LocalRegAVM2Item.java | 3 ++- .../flash/abc/avm2/model/SetLocalAVM2Item.java | 4 ++-- .../flash/abc/avm2/model/SetPropertyAVM2Item.java | 2 +- .../flash/abc/avm2/model/SetSlotAVM2Item.java | 4 ++-- .../flash/abc/avm2/model/ThisAVM2Item.java | 11 ++++++----- .../abc/avm2/model/clauses/DeclarationAVM2Item.java | 5 +++++ .../flash/abc/avm2/model/clauses/TryAVM2Item.java | 1 + .../decompiler/flash/helpers/GraphTextWriter.java | 4 ++-- .../flash/helpers/hilight/HighlightData.java | 12 ++++++++---- .../com/jpexs/decompiler/graph/GraphTargetItem.java | 13 +++++++++---- 16 files changed, 54 insertions(+), 35 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java index ee207dbcb..a930438d1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java @@ -756,9 +756,9 @@ public class AVM2Graph extends Graph { SetTypeAVM2Item sti = (SetTypeAVM2Item) w.commands.remove(0); GraphTargetItem gti = sti.getValue().getNotCoerced(); if (gti instanceof NextValueAVM2Item) { - return new ForEachInAVM2Item(w.src, w.loop, new InAVM2Item(hn.instruction, sti.getObject(), ((HasNextAVM2Item) w.expression.get(w.expression.size() - 1)).collection), w.commands); + return new ForEachInAVM2Item(w.src, w.loop, new InAVM2Item(hn.getInstruction(), sti.getObject(), ((HasNextAVM2Item) w.expression.get(w.expression.size() - 1)).collection), w.commands); } else if (gti instanceof NextNameAVM2Item) { - return new ForInAVM2Item(w.src, w.loop, new InAVM2Item(hn.instruction, sti.getObject(), ((HasNextAVM2Item) w.expression.get(w.expression.size() - 1)).collection), w.commands); + return new ForInAVM2Item(w.src, w.loop, new InAVM2Item(hn.getInstruction(), sti.getObject(), ((HasNextAVM2Item) w.expression.get(w.expression.size() - 1)).collection), w.commands); } } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetPropertyIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetPropertyIns.java index b2da78ba5..8ae8904fe 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetPropertyIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/SetPropertyIns.java @@ -129,7 +129,7 @@ public class SetPropertyIns extends InstructionDefinition implements SetTypeIns c.args.clear(); List vals = new ArrayList<>(); vals.add(value); - c.object = new InitVectorAVM2Item(c.instruction, at.params.get(0), vals); + c.object = new InitVectorAVM2Item(c.getInstruction(), at.params.get(0), vals); return; } else if (c.object instanceof InitVectorAVM2Item) { InitVectorAVM2Item iv = (InitVectorAVM2Item) c.object; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java index ed5d47968..113243933 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/AVM2Item.java @@ -35,9 +35,7 @@ import java.util.List; public abstract class AVM2Item extends GraphTargetItem { - public AVM2Instruction instruction; - - public boolean hidden = false; + private AVM2Instruction instruction; public AVM2Item(GraphSourceItem instruction, int precedence) { super(instruction, precedence); @@ -46,6 +44,10 @@ public abstract class AVM2Item extends GraphTargetItem { } } + public AVM2Instruction getInstruction() { + return instruction; + } + @Override public boolean needsSemicolon() { return true; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/GetLexAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/GetLexAVM2Item.java index 61b0fea3a..72f0edb15 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/GetLexAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/GetLexAVM2Item.java @@ -1,18 +1,19 @@ /* * Copyright (C) 2010-2015 JPEXS, All rights reserved. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.abc.avm2.model; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; @@ -33,9 +34,8 @@ public class GetLexAVM2Item extends AVM2Item { @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) { - String localName = propertyName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false); - srcData.localName = localName; + getSrcData().localName = localName; return writer.append(propertyName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false)); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/GetSlotAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/GetSlotAVM2Item.java index 7097b7f64..9606a6ca4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/GetSlotAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/GetSlotAVM2Item.java @@ -40,8 +40,8 @@ public class GetSlotAVM2Item extends AVM2Item { if (slotName == null) { return writer.append("/*UnknownSlot*/"); } - srcData.localName = getNameAsStr(localData); + getSrcData().localName = getNameAsStr(localData); return writer.append(slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false)); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/InitPropertyAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/InitPropertyAVM2Item.java index 94fe8276a..8a5ddcfdb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/InitPropertyAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/InitPropertyAVM2Item.java @@ -46,7 +46,7 @@ public class InitPropertyAVM2Item extends AVM2Item implements SetTypeAVM2Item, A @Override public GraphTargetItem getObject() { - return new GetPropertyAVM2Item(instruction, object, propertyName); + return new GetPropertyAVM2Item(getInstruction(), object, propertyName); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/LocalRegAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/LocalRegAVM2Item.java index f37f9ca98..6b898f45f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/LocalRegAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/LocalRegAVM2Item.java @@ -65,8 +65,9 @@ public class LocalRegAVM2Item extends AVM2Item { if (computedValue instanceof FilterAVM2Item) { return computedValue.toString(writer, localData); } + String localName = localRegName(localData.localRegNames, regIndex); - srcData.localName = localName; + getSrcData().localName = localName; return writer.append(localName); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetLocalAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetLocalAVM2Item.java index a95553c3f..fcb604b96 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetLocalAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetLocalAVM2Item.java @@ -48,14 +48,14 @@ public class SetLocalAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assig @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { String localName = localRegName(localData.localRegNames, regIndex); - srcData.localName = localName; + getSrcData().localName = localName; writer.append(localName).append(" = "); return value.toString(writer, localData); } @Override public GraphTargetItem getObject() { - return new LocalRegAVM2Item(instruction, regIndex, null); + return new LocalRegAVM2Item(getInstruction(), regIndex, null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java index 11ff06193..ec7233a73 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java @@ -60,7 +60,7 @@ public class SetPropertyAVM2Item extends AVM2Item implements SetTypeAVM2Item, As @Override public GraphTargetItem getObject() { - return new GetPropertyAVM2Item(instruction, object, propertyName); + return new GetPropertyAVM2Item(getInstruction(), object, propertyName); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSlotAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSlotAVM2Item.java index 68256562d..69da8f87e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSlotAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSlotAVM2Item.java @@ -46,7 +46,7 @@ public class SetSlotAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assign @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { - srcData.localName = slotName == null ? "/*UnknownSlot*/" : slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false); + getSrcData().localName = slotName == null ? "/*UnknownSlot*/" : slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false); getName(writer, localData); writer.append(" = "); return value.toString(writer, localData); @@ -65,7 +65,7 @@ public class SetSlotAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assign @Override public GraphTargetItem getObject() { - return new GetSlotAVM2Item(instruction, scope, slotName); + return new GetSlotAVM2Item(getInstruction(), scope, slotName); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/ThisAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/ThisAVM2Item.java index 52571fb1c..07562c810 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/ThisAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/ThisAVM2Item.java @@ -1,18 +1,19 @@ /* * Copyright (C) 2010-2015 JPEXS, All rights reserved. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.abc.avm2.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; @@ -35,7 +36,7 @@ public class ThisAVM2Item extends AVM2Item { public ThisAVM2Item(GraphSourceItem instruction, Multiname className) { super(instruction, PRECEDENCE_PRIMARY); this.className = className; - srcData.localName = "this"; + getSrcData().localName = "this"; } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/clauses/DeclarationAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/clauses/DeclarationAVM2Item.java index 956ecd8d6..f6924db2d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/clauses/DeclarationAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/clauses/DeclarationAVM2Item.java @@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.SetLocalAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.SetSlotAVM2Item; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; +import com.jpexs.decompiler.flash.helpers.hilight.HighlightData; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.TypeItem; import com.jpexs.decompiler.graph.model.LocalData; @@ -54,6 +55,7 @@ public class DeclarationAVM2Item extends AVM2Item { if (assignment instanceof LocalRegAVM2Item) { //for..in LocalRegAVM2Item lti = (LocalRegAVM2Item) assignment; String localName = localRegName(localData.localRegNames, lti.regIndex); + HighlightData srcData = getSrcData(); srcData.localName = localName; srcData.declaration = true; srcData.declaredType = "*"; @@ -64,6 +66,7 @@ public class DeclarationAVM2Item extends AVM2Item { if (assignment instanceof GetSlotAVM2Item) { //for..in GetSlotAVM2Item sti = (GetSlotAVM2Item) assignment; + HighlightData srcData = getSrcData(); srcData.localName = sti.getNameAsStr(localData); srcData.declaration = true; srcData.declaredType = "*"; @@ -75,6 +78,7 @@ public class DeclarationAVM2Item extends AVM2Item { if (assignment instanceof SetLocalAVM2Item) { SetLocalAVM2Item lti = (SetLocalAVM2Item) assignment; String localName = localRegName(localData.localRegNames, lti.regIndex); + HighlightData srcData = getSrcData(); srcData.localName = localName; srcData.declaration = true; @@ -95,6 +99,7 @@ public class DeclarationAVM2Item extends AVM2Item { } if (assignment instanceof SetSlotAVM2Item) { SetSlotAVM2Item ssti = (SetSlotAVM2Item) assignment; + HighlightData srcData = getSrcData(); srcData.localName = ssti.getNameAsStr(localData); srcData.declaration = true; srcData.declaredType = (type instanceof TypeItem) ? ((TypeItem) type).fullTypeName.toPrintableString() : "*"; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/clauses/TryAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/clauses/TryAVM2Item.java index ab8a69b17..929e3e738 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/clauses/TryAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/clauses/TryAVM2Item.java @@ -90,6 +90,7 @@ public class TryAVM2Item extends AVM2Item implements Block { if (localName.isEmpty()) { localName = finCatchName; } + HighlightData data = new HighlightData(); data.localName = localName; data.declaration = true; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/GraphTextWriter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/GraphTextWriter.java index 2cf5f25c9..91b4da078 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/GraphTextWriter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/GraphTextWriter.java @@ -109,7 +109,7 @@ public abstract class GraphTextWriter { } public final GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, int specialValue) { - return hilightSpecial(text, type, Integer.toString(specialValue), new HighlightData()); + return hilightSpecial(text, type, Integer.toString(specialValue), null); } public final GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, int specialValue, HighlightData data) { @@ -117,7 +117,7 @@ public abstract class GraphTextWriter { } public final GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, String specialValue) { - return hilightSpecial(text, type, specialValue, new HighlightData()); + return hilightSpecial(text, type, specialValue, null); } protected GraphTextWriter hilightSpecial(String text, HighlightSpecialType type, String specialValue, HighlightData data) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightData.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightData.java index e88a2b1a1..3733e2360 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightData.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightData.java @@ -1,18 +1,19 @@ /* * Copyright (C) 2010-2015 JPEXS, All rights reserved. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.helpers.hilight; import java.io.Serializable; @@ -44,6 +45,9 @@ public class HighlightData implements Cloneable, Serializable { } public void merge(HighlightData data) { + if (data == null) { + return; + } if (data.declaration) { declaration = data.declaration; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java index 81f02f912..9708af050 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java @@ -82,7 +82,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { public GraphTargetItem value; - protected HighlightData srcData = new HighlightData(); + private HighlightData srcData; public int getLine() { if (src != null) { @@ -310,10 +310,15 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { } } - /*public GraphTargetItem invert() { - return invert(null); - }*/ public GraphTargetItem invert(GraphSourceItem src) { return new NotItem(src, this); } + + protected HighlightData getSrcData() { + if (srcData == null) { + srcData = new HighlightData(); + } + + return srcData; + } }