diff --git a/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java b/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java index d0b1cbf37..dc9b3ce7f 100644 --- a/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java +++ b/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java @@ -12,7 +12,7 @@ import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.map.ObjectMapper; import org.teavm.chromerdp.data.*; import org.teavm.chromerdp.messages.*; -import org.teavm.debugging.*; +import org.teavm.debugging.javascript.*; /** * diff --git a/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/RDPBreakpoint.java b/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/RDPBreakpoint.java index 278400419..cc6e95754 100644 --- a/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/RDPBreakpoint.java +++ b/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/RDPBreakpoint.java @@ -16,8 +16,8 @@ package org.teavm.chromerdp; import java.util.concurrent.atomic.AtomicInteger; -import org.teavm.debugging.JavaScriptBreakpoint; -import org.teavm.debugging.JavaScriptLocation; +import org.teavm.debugging.javascript.JavaScriptBreakpoint; +import org.teavm.debugging.javascript.JavaScriptLocation; /** * diff --git a/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/RDPCallFrame.java b/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/RDPCallFrame.java index 3ed96bfc6..150187ded 100644 --- a/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/RDPCallFrame.java +++ b/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/RDPCallFrame.java @@ -17,9 +17,9 @@ package org.teavm.chromerdp; import java.util.Collections; import java.util.Map; -import org.teavm.debugging.JavaScriptCallFrame; -import org.teavm.debugging.JavaScriptLocation; -import org.teavm.debugging.JavaScriptVariable; +import org.teavm.debugging.javascript.JavaScriptCallFrame; +import org.teavm.debugging.javascript.JavaScriptLocation; +import org.teavm.debugging.javascript.JavaScriptVariable; /** * diff --git a/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/RDPLocalVariable.java b/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/RDPLocalVariable.java index 4bf308ae6..c4a6c1622 100644 --- a/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/RDPLocalVariable.java +++ b/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/RDPLocalVariable.java @@ -1,7 +1,7 @@ package org.teavm.chromerdp; -import org.teavm.debugging.JavaScriptValue; -import org.teavm.debugging.JavaScriptVariable; +import org.teavm.debugging.javascript.JavaScriptValue; +import org.teavm.debugging.javascript.JavaScriptVariable; /** * diff --git a/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/RDPValue.java b/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/RDPValue.java index 3e1d3e806..8e536cbf7 100644 --- a/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/RDPValue.java +++ b/teavm-chrome-rdp/src/main/java/org/teavm/chromerdp/RDPValue.java @@ -3,8 +3,8 @@ package org.teavm.chromerdp; import java.util.Collections; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import org.teavm.debugging.JavaScriptValue; -import org.teavm.debugging.JavaScriptVariable; +import org.teavm.debugging.javascript.JavaScriptValue; +import org.teavm.debugging.javascript.JavaScriptVariable; /** * diff --git a/teavm-core/src/main/java/org/teavm/debugging/Breakpoint.java b/teavm-core/src/main/java/org/teavm/debugging/Breakpoint.java index 4bcc22135..469272ef6 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/Breakpoint.java +++ b/teavm-core/src/main/java/org/teavm/debugging/Breakpoint.java @@ -17,6 +17,8 @@ package org.teavm.debugging; import java.util.ArrayList; import java.util.List; +import org.teavm.debugging.information.SourceLocation; +import org.teavm.debugging.javascript.JavaScriptBreakpoint; /** * diff --git a/teavm-core/src/main/java/org/teavm/debugging/CallFrame.java b/teavm-core/src/main/java/org/teavm/debugging/CallFrame.java index a27177582..96a8c84c9 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/CallFrame.java +++ b/teavm-core/src/main/java/org/teavm/debugging/CallFrame.java @@ -17,6 +17,8 @@ package org.teavm.debugging; import java.util.Collections; import java.util.Map; +import org.teavm.debugging.information.SourceLocation; +import org.teavm.debugging.javascript.JavaScriptLocation; import org.teavm.model.MethodReference; /** diff --git a/teavm-core/src/main/java/org/teavm/debugging/Debugger.java b/teavm-core/src/main/java/org/teavm/debugging/Debugger.java index 14e1819b3..b3a5c4ddf 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/Debugger.java +++ b/teavm-core/src/main/java/org/teavm/debugging/Debugger.java @@ -20,6 +20,8 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.LinkedBlockingQueue; +import org.teavm.debugging.information.*; +import org.teavm.debugging.javascript.*; import org.teavm.model.MethodReference; /** diff --git a/teavm-core/src/main/java/org/teavm/debugging/PropertyMap.java b/teavm-core/src/main/java/org/teavm/debugging/PropertyMap.java index 419df5ba3..02d6fc16f 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/PropertyMap.java +++ b/teavm-core/src/main/java/org/teavm/debugging/PropertyMap.java @@ -19,6 +19,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; +import org.teavm.debugging.javascript.JavaScriptVariable; /** * diff --git a/teavm-core/src/main/java/org/teavm/debugging/Value.java b/teavm-core/src/main/java/org/teavm/debugging/Value.java index a0968476b..22accbbf4 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/Value.java +++ b/teavm-core/src/main/java/org/teavm/debugging/Value.java @@ -17,6 +17,7 @@ package org.teavm.debugging; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; +import org.teavm.debugging.javascript.JavaScriptValue; /** * diff --git a/teavm-core/src/main/java/org/teavm/debugging/VariableMap.java b/teavm-core/src/main/java/org/teavm/debugging/VariableMap.java index 85538d0cb..2e7994399 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/VariableMap.java +++ b/teavm-core/src/main/java/org/teavm/debugging/VariableMap.java @@ -20,6 +20,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; +import org.teavm.debugging.javascript.JavaScriptLocation; +import org.teavm.debugging.javascript.JavaScriptVariable; /** * diff --git a/teavm-core/src/main/java/org/teavm/debugging/ClassNameIterator.java b/teavm-core/src/main/java/org/teavm/debugging/information/ClassNameIterator.java similarity index 97% rename from teavm-core/src/main/java/org/teavm/debugging/ClassNameIterator.java rename to teavm-core/src/main/java/org/teavm/debugging/information/ClassNameIterator.java index 5bf47e8ac..aa76261ba 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/ClassNameIterator.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/ClassNameIterator.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; /** * diff --git a/teavm-core/src/main/java/org/teavm/debugging/DebugInformation.java b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformation.java similarity index 96% rename from teavm-core/src/main/java/org/teavm/debugging/DebugInformation.java rename to teavm-core/src/main/java/org/teavm/debugging/information/DebugInformation.java index d4335f0bd..ae3a801f5 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DebugInformation.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformation.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; import java.io.*; import java.util.*; @@ -48,7 +48,7 @@ public class DebugInformation { RecordArray callSiteMapping; RecordArray[] variableMappings; RecordArray[] lineCallSites; - CFG[] controlFlowGraphs; + RecordArray[] controlFlowGraphs; List classesMetadata; RecordArray methodEntrances; MethodTree methodTree; @@ -216,28 +216,26 @@ public class DebugInformation { if (fileIndex == null) { return null; } - CFG cfg = controlFlowGraphs[fileIndex]; + RecordArray cfg = controlFlowGraphs[fileIndex]; if (cfg == null) { return null; } - if (location.getLine() >= cfg.offsets.length - 1) { + if (location.getLine() >= cfg.size()) { return null; } - int start = cfg.offsets[location.getLine()]; - int end = cfg.offsets[location.getLine() + 1]; - if (end - start == 1 && cfg.offsets[start] == -1) { - return new SourceLocation[0]; - } else if (start == end) { + int type = cfg.get(location.getLine()).get(0); + if (type == 0) { return null; } - SourceLocation[] result = new SourceLocation[end - start]; - for (int i = 0; i < result.length; ++i) { - int line = cfg.lines[i + start]; - if (line >= 0) { - result[i] = new SourceLocation(fileNames[cfg.files[i + start]], line); - } else { - result[i] = null; - } + int[] data = cfg.get(location.getLine()).getArray(0); + int length = data.length / 2; + int size = length; + if (type == 2) { + ++size; + } + SourceLocation[] result = new SourceLocation[size]; + for (int i = 0; i < length; ++i) { + result[i] = new SourceLocation(fileNames[data[i * 2]], data[i * 2 + 1]); } return result; } @@ -598,11 +596,6 @@ public class DebugInformation { int[] methods; } - static class CFG { - int[] lines; - int[] files; - int[] offsets; - } class MethodTree { int[] data; diff --git a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationBuilder.java b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationBuilder.java similarity index 80% rename from teavm-core/src/main/java/org/teavm/debugging/DebugInformationBuilder.java rename to teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationBuilder.java index 00dde319e..87f7bbef1 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationBuilder.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationBuilder.java @@ -13,11 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; import java.util.*; import org.teavm.codegen.LocationProvider; -import org.teavm.common.IntegerArray; import org.teavm.common.RecordArray; import org.teavm.common.RecordArrayBuilder; import org.teavm.model.MethodDescriptor; @@ -41,14 +40,14 @@ public class DebugInformationBuilder implements DebugInformationEmitter { private RecordArrayBuilder lineMapping = new RecordArrayBuilder(3, 0); private RecordArrayBuilder classMapping = new RecordArrayBuilder(3, 0); private RecordArrayBuilder methodMapping = new RecordArrayBuilder(3, 0); - private RecordArrayBuilder callSiteMapping = new RecordArrayBuilder(3, 1); + private RecordArrayBuilder callSiteMapping = new RecordArrayBuilder(4, 0); private Map variableMappings = new HashMap<>(); private MethodDescriptor currentMethod; private String currentClass; private String currentFileName; private int currentClassMetadata = -1; private List classesMetadata = new ArrayList<>(); - private List cfgs = new ArrayList<>(); + private List cfgs = new ArrayList<>(); private int currentLine; public LocationProvider getLocationProvider() { @@ -149,20 +148,17 @@ public class DebugInformationBuilder implements DebugInformationEmitter { @Override public void setVirtualMethod(MethodReference method) { record.set(2, DebuggerCallSite.VIRTUAL); - RecordArrayBuilder.RecordSubArray array = record.getArray(0); - array.clear(); - array.add(getExactMethodIndex(method)); + record.set(3, getExactMethodIndex(method)); } @Override public void setStaticMethod(MethodReference method) { record.set(2, DebuggerCallSite.STATIC); - RecordArrayBuilder.RecordSubArray array = record.getArray(0); - array.clear(); - array.add(getExactMethodIndex(method)); + record.set(3, getExactMethodIndex(method)); } @Override public void clean() { record.set(2, DebuggerCallSite.NONE); + record.set(3, 0); } private int getExactMethodIndex(MethodReference method) { int methodIndex = methods.index(method.getDescriptor().toString()); @@ -202,19 +198,21 @@ public class DebugInformationBuilder implements DebugInformationEmitter { @Override public void addSuccessors(SourceLocation location, SourceLocation[] successors) { int fileIndex = files.index(location.getFileName()); - if (cfgs.size() <= fileIndex) { - cfgs.addAll(Collections.nCopies(fileIndex - cfgs.size() + 1, null)); + while (cfgs.size() <= fileIndex) { + cfgs.add(new RecordArrayBuilder(1, 1)); } - CFG cfg = cfgs.get(fileIndex); - if (cfg == null) { - cfg = new CFG(); - cfgs.set(fileIndex, cfg); + RecordArrayBuilder cfg = cfgs.get(fileIndex); + RecordArrayBuilder.Record record = cfg.get(location.getLine()); + if (record.get(0) == 0) { + record.set(0, 1); } + RecordArrayBuilder.RecordSubArray array = record.getArray(0); for (SourceLocation succ : successors) { if (succ == null) { - cfg.add(location.getLine(), -1, fileIndex); + record.set(0, 2); } else { - cfg.add(location.getLine(), succ.getLine(), files.index(succ.getFileName())); + array.add(files.index(succ.getFileName())); + array.add(succ.getLine()); } } } @@ -297,7 +295,7 @@ public class DebugInformationBuilder implements DebugInformationEmitter { } debugInformation.classesMetadata = builtMetadata; - DebugInformation.CFG[] cfgs = new DebugInformation.CFG[files.list.size()]; + RecordArray[] cfgs = new RecordArray[files.list.size()]; for (int i = 0; i < this.cfgs.size(); ++i) { if (this.cfgs.get(i) != null) { cfgs[i] = this.cfgs.get(i).build(); @@ -339,59 +337,4 @@ public class DebugInformationBuilder implements DebugInformationEmitter { int parentIndex; Map fieldMap = new HashMap<>(); } - - static class CFG { - IntegerArray start = new IntegerArray(1); - IntegerArray next = new IntegerArray(1); - IntegerArray lines = new IntegerArray(1); - IntegerArray files = new IntegerArray(1); - - public void add(int line, int succLine, int succFile) { - while (start.size() <= line) { - start.add(-1); - } - int ptr = start.get(line); - start.set(line, lines.size()); - next.add(ptr); - lines.add(succLine); - files.add(succFile); - } - - public DebugInformation.CFG build() { - int[] offsets = new int[start.size() + 1]; - IntegerArray linesData = new IntegerArray(1); - IntegerArray filesData = new IntegerArray(1); - for (int i = 0; i < start.size(); ++i) { - IntegerArray linesChunk = new IntegerArray(1); - IntegerArray filesChunk = new IntegerArray(1); - int ptr = start.get(i); - while (ptr >= 0) { - linesChunk.add(lines.get(ptr)); - filesChunk.add(files.get(ptr)); - ptr = next.get(ptr); - } - long[] pairs = new long[linesChunk.size()]; - for (int j = 0; j < pairs.length; ++j) { - pairs[j] = (((long)filesChunk.get(j)) << 32) | linesChunk.get(j); - } - Arrays.sort(pairs); - int distinctSize = 0; - for (int j = 0; j < pairs.length; ++j) { - long pair = pairs[j]; - if (distinctSize == 0 || pair != pairs[distinctSize - 1]) { - pairs[distinctSize++] = pair; - filesData.add((int)(pair >>> 32)); - linesData.add((int)pair); - } - } - offsets[i + 1] = linesData.size(); - } - DebugInformation.CFG cfg = new DebugInformation.CFG(); - cfg.offsets = offsets; - cfg.lines = linesData.getAll(); - cfg.files = filesData.getAll(); - return cfg; - } - } - } diff --git a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationEmitter.java b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationEmitter.java similarity index 96% rename from teavm-core/src/main/java/org/teavm/debugging/DebugInformationEmitter.java rename to teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationEmitter.java index cff999d6a..e6796c862 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationEmitter.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationEmitter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; import org.teavm.codegen.LocationProvider; import org.teavm.model.MethodDescriptor; diff --git a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationProvider.java b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationProvider.java similarity index 94% rename from teavm-core/src/main/java/org/teavm/debugging/DebugInformationProvider.java rename to teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationProvider.java index 9c8ccafb1..127a01a7b 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationProvider.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationProvider.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; /** * diff --git a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationReader.java b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationReader.java similarity index 96% rename from teavm-core/src/main/java/org/teavm/debugging/DebugInformationReader.java rename to teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationReader.java index aa6dfb74e..cfcbb2543 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationReader.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationReader.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; import java.io.EOFException; import java.io.IOException; @@ -21,6 +21,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; import org.teavm.common.IntegerArray; +import org.teavm.common.RecordArray; /** * @@ -54,8 +55,8 @@ class DebugInformationReader { return debugInfo; } - private DebugInformation.MultiMapping[] readVariableMappings(int count) throws IOException { - DebugInformation.MultiMapping[] mappings = new DebugInformation.MultiMapping[count]; + private RecordArray[] readVariableMappings(int count) throws IOException { + RecordArray[] mappings = new RecordArray[count]; int varCount = readUnsignedNumber(); int lastVar = 0; while (varCount-- > 0) { @@ -136,7 +137,7 @@ class DebugInformationReader { return !negative ? number : -number; } - private DebugInformation.MultiMapping readMultiMapping() throws IOException { + private RecordArray readMultiMapping() throws IOException { int[] lines = readRle(); int last = 0; for (int i = 0; i < lines.length; ++i) { diff --git a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationWriter.java b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationWriter.java similarity index 69% rename from teavm-core/src/main/java/org/teavm/debugging/DebugInformationWriter.java rename to teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationWriter.java index f3257b117..6e6758667 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DebugInformationWriter.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/DebugInformationWriter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; import java.io.DataOutput; import java.io.IOException; @@ -21,8 +21,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.teavm.common.IntegerArray; import org.teavm.common.RecordArray; -import org.teavm.debugging.DebugInformation.ClassMetadata; +import org.teavm.debugging.information.DebugInformation.ClassMetadata; /** * @@ -48,7 +49,7 @@ class DebugInformationWriter { writeMapping(debugInfo.lineMapping); writeMapping(debugInfo.classMapping); writeMapping(debugInfo.methodMapping); - writeMapping(debugInfo.callSiteMapping); + writeCallSiteMapping(debugInfo.callSiteMapping); writeVariableMappings(debugInfo); writeClassMetadata(debugInfo.classesMetadata); writeCFGs(debugInfo); @@ -115,27 +116,6 @@ class DebugInformationWriter { } } - private void writeLinesAndColumns(RecordArray mapping) throws IOException { - int[] lines = mapping.cut(0); - int last = 0; - for (int i = 0; i < lines.length; ++i) { - int next = lines[i]; - lines[i] -= last; - last = next; - } - writeRle(lines); - resetRelativeNumber(); - int[] columns = mapping.cut(1); - int lastLine = -1; - for (int i = 0; i < columns.length; ++i) { - if (lastLine != mapping.get(i).get(0)) { - resetRelativeNumber(); - lastLine = mapping.get(i).get(0); - } - writeRelativeNumber(columns[i]); - } - } - private void writeMultiMapping(RecordArray mapping) throws IOException { writeLinesAndColumns(mapping); for (int i = 0; i < mapping.size(); ++i) { @@ -151,47 +131,108 @@ class DebugInformationWriter { private void writeMapping(RecordArray mapping) throws IOException { writeLinesAndColumns(mapping); - resetRelativeNumber(); - int[] values = mapping.cut(2); - for (int i = 0; i < values.length; ++i) { - writeRelativeNumber(values[i]); + writeRle(extractValues(mapping)); + } + + private void writeCallSiteMapping(RecordArray mapping) throws IOException { + writeLinesAndColumns(mapping); + writeRle(extractValues(mapping)); + writeRle(extractCallSites(mapping)); + } + + private void writeLinesAndColumns(RecordArray mapping) throws IOException { + writeUnsignedNumber(mapping.size()); + writeRle(extractLines(mapping)); + writeRle(extractColumns(mapping)); + } + + private int[] extractLines(RecordArray mapping) { + int[] lines = mapping.cut(0); + int last = 0; + for (int i = 0; i < lines.length; ++i) { + int next = lines[i]; + lines[i] -= last; + last = next; } + return lines; + } + + private int[] extractColumns(RecordArray mapping) { + int[] columns = mapping.cut(1); + int lastLine = -1; + int lastColumn = 0; + for (int i = 0; i < columns.length; ++i) { + if (lastLine != mapping.get(i).get(0)) { + lastColumn = 0; + lastLine = mapping.get(i).get(0); + } + int column = columns[i]; + columns[i] = column - lastColumn; + lastColumn = column; + } + return columns; + } + + private int[] extractValues(RecordArray mapping) { + int[] values = mapping.cut(2); + int last = 0; + for (int i = 0; i < values.length; ++i) { + int value = values[i]; + if (value == -1) { + values[i] = 0; + } else { + values[i] = 1 + convertToSigned(value - last); + last = value; + } + } + return values; + } + + private int[] extractCallSites(RecordArray mapping) { + int[] callSites = mapping.cut(3); + int last = 0; + int j = 0; + for (int i = 0; i < callSites.length; ++i) { + int type = mapping.get(i).get(2); + if (type != 0) { + int callSite = callSites[i]; + callSites[j++] = 1 + convertToSigned(callSite - last); + last = callSite; + } + } + return Arrays.copyOf(callSites, j); } private void writeCFGs(DebugInformation debugInfo) throws IOException { for (int i = 0; i < debugInfo.controlFlowGraphs.length; ++i) { - writeCFG(debugInfo.controlFlowGraphs[i], i); + writeCFG(debugInfo.controlFlowGraphs[i]); } } - private void writeCFG(DebugInformation.CFG mapping, int fileIndex) throws IOException { - writeUnsignedNumber(mapping.lines.length); - int lastLine = -1; - for (int i = 0; i < mapping.offsets.length - 1; ++i) { - int start = mapping.offsets[i]; - int sz = mapping.offsets[i + 1] - start; - if (sz == 0) { + private void writeCFG(RecordArray mapping) throws IOException { + writeUnsignedNumber(mapping.size()); + writeRle(mapping.cut(0)); + IntegerArray files = new IntegerArray(1); + IntegerArray lines = new IntegerArray(1); + int lastFile = 0; + int lastLine = 0; + for (int i = 0; i < mapping.size(); ++i) { + int type = mapping.get(i).get(0); + if (type == 0) { continue; } - writeUnsignedNumber(i - lastLine); - if (sz == 1 && mapping.lines[start] == -1) { - writeUnsignedNumber(0); - } else if (sz == 1 && mapping.lines[start] == i + 1 && mapping.files[start] == fileIndex) { - writeUnsignedNumber(1); - } else { - writeUnsignedNumber(1 + sz); - int[] lines = Arrays.copyOfRange(mapping.lines, start, start + sz); - int[] files = Arrays.copyOfRange(mapping.files, start, start + sz); - int last = i; - for (int j = 0; j < sz; ++j) { - int succ = lines[j]; - writeNumber(succ - last); - writeNumber(files[j] - fileIndex); - last = succ; - } + int[] data = mapping.get(i).getArray(0); + for (int j = 0; j < data.length; j += 2) { + int file = data[j]; + int line = data[j + 1]; + files.add(file - lastFile); + lines.add(line - lastLine); + lastFile = file; + lastLine = line; } - lastLine = i; } + writeRle(files.getAll()); + writeRle(lines.getAll()); } private void writeNumber(int number) throws IOException { @@ -214,20 +255,26 @@ class DebugInformationWriter { } private void writeRle(int[] array) throws IOException { - writeUnsignedNumber(array.length); + int last = 0; for (int i = 0; i < array.length;) { int e = array[i]; int count = 1; + int current = i; ++i; while (i < array.length && array[i] == e) { ++count; ++i; } if (count > 1) { + if (current > last) { + writeUnsignedNumber(convertToSigned(current - last) | 0); + while (last < current) { + writeUnsignedNumber(array[last++]); + } + } writeUnsignedNumber((convertToSigned(e) << 1) | 1); writeUnsignedNumber(count); - } else { - writeUnsignedNumber(convertToSigned(e) << 1); + last = i; } } } diff --git a/teavm-core/src/main/java/org/teavm/debugging/DebuggerCallSite.java b/teavm-core/src/main/java/org/teavm/debugging/information/DebuggerCallSite.java similarity index 95% rename from teavm-core/src/main/java/org/teavm/debugging/DebuggerCallSite.java rename to teavm-core/src/main/java/org/teavm/debugging/information/DebuggerCallSite.java index 3a8b33b2e..a6c262bd1 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DebuggerCallSite.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/DebuggerCallSite.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; /** * diff --git a/teavm-core/src/main/java/org/teavm/debugging/DebuggerCallSiteVisitor.java b/teavm-core/src/main/java/org/teavm/debugging/information/DebuggerCallSiteVisitor.java similarity index 95% rename from teavm-core/src/main/java/org/teavm/debugging/DebuggerCallSiteVisitor.java rename to teavm-core/src/main/java/org/teavm/debugging/information/DebuggerCallSiteVisitor.java index 85218179f..964b5d6b4 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DebuggerCallSiteVisitor.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/DebuggerCallSiteVisitor.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; /** * diff --git a/teavm-core/src/main/java/org/teavm/debugging/DebuggerStaticCallSite.java b/teavm-core/src/main/java/org/teavm/debugging/information/DebuggerStaticCallSite.java similarity index 96% rename from teavm-core/src/main/java/org/teavm/debugging/DebuggerStaticCallSite.java rename to teavm-core/src/main/java/org/teavm/debugging/information/DebuggerStaticCallSite.java index 469f1f68f..4e965f0d3 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DebuggerStaticCallSite.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/DebuggerStaticCallSite.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; import org.teavm.model.MethodReference; diff --git a/teavm-core/src/main/java/org/teavm/debugging/DebuggerVirtualCallSite.java b/teavm-core/src/main/java/org/teavm/debugging/information/DebuggerVirtualCallSite.java similarity index 96% rename from teavm-core/src/main/java/org/teavm/debugging/DebuggerVirtualCallSite.java rename to teavm-core/src/main/java/org/teavm/debugging/information/DebuggerVirtualCallSite.java index 294b3baff..1bc660c2a 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DebuggerVirtualCallSite.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/DebuggerVirtualCallSite.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; import org.teavm.model.MethodReference; diff --git a/teavm-core/src/main/java/org/teavm/debugging/DeferredCallSite.java b/teavm-core/src/main/java/org/teavm/debugging/information/DeferredCallSite.java similarity index 95% rename from teavm-core/src/main/java/org/teavm/debugging/DeferredCallSite.java rename to teavm-core/src/main/java/org/teavm/debugging/information/DeferredCallSite.java index d82ccc849..f726805f3 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DeferredCallSite.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/DeferredCallSite.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; import org.teavm.model.MethodReference; diff --git a/teavm-core/src/main/java/org/teavm/debugging/DummyDebugInformationEmitter.java b/teavm-core/src/main/java/org/teavm/debugging/information/DummyDebugInformationEmitter.java similarity index 97% rename from teavm-core/src/main/java/org/teavm/debugging/DummyDebugInformationEmitter.java rename to teavm-core/src/main/java/org/teavm/debugging/information/DummyDebugInformationEmitter.java index 4684491b9..5d624b6f9 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DummyDebugInformationEmitter.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/DummyDebugInformationEmitter.java @@ -13,13 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; import org.teavm.codegen.LocationProvider; import org.teavm.model.MethodDescriptor; import org.teavm.model.MethodReference; - /** * * @author Alexey Andreev diff --git a/teavm-core/src/main/java/org/teavm/debugging/ExactMethodIterator.java b/teavm-core/src/main/java/org/teavm/debugging/information/ExactMethodIterator.java similarity index 98% rename from teavm-core/src/main/java/org/teavm/debugging/ExactMethodIterator.java rename to teavm-core/src/main/java/org/teavm/debugging/information/ExactMethodIterator.java index bdf6cbb6b..e957840b7 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/ExactMethodIterator.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/ExactMethodIterator.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; import org.teavm.common.RecordArray; import org.teavm.model.MethodDescriptor; diff --git a/teavm-core/src/main/java/org/teavm/debugging/FileNameIterator.java b/teavm-core/src/main/java/org/teavm/debugging/information/FileNameIterator.java similarity index 97% rename from teavm-core/src/main/java/org/teavm/debugging/FileNameIterator.java rename to teavm-core/src/main/java/org/teavm/debugging/information/FileNameIterator.java index 12b542918..5a818477a 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/FileNameIterator.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/FileNameIterator.java @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; + /** * diff --git a/teavm-core/src/main/java/org/teavm/debugging/GeneratedLocation.java b/teavm-core/src/main/java/org/teavm/debugging/information/GeneratedLocation.java similarity index 97% rename from teavm-core/src/main/java/org/teavm/debugging/GeneratedLocation.java rename to teavm-core/src/main/java/org/teavm/debugging/information/GeneratedLocation.java index 7ab80442e..606ff4503 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/GeneratedLocation.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/GeneratedLocation.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; /** * diff --git a/teavm-core/src/main/java/org/teavm/debugging/LineNumberIterator.java b/teavm-core/src/main/java/org/teavm/debugging/information/LineNumberIterator.java similarity index 97% rename from teavm-core/src/main/java/org/teavm/debugging/LineNumberIterator.java rename to teavm-core/src/main/java/org/teavm/debugging/information/LineNumberIterator.java index 677e33a76..f36c8a450 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/LineNumberIterator.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/LineNumberIterator.java @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; + /** * diff --git a/teavm-core/src/main/java/org/teavm/debugging/MethodIterator.java b/teavm-core/src/main/java/org/teavm/debugging/information/MethodIterator.java similarity index 97% rename from teavm-core/src/main/java/org/teavm/debugging/MethodIterator.java rename to teavm-core/src/main/java/org/teavm/debugging/information/MethodIterator.java index 3b67e604a..f58231b78 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/MethodIterator.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/MethodIterator.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; import org.teavm.model.MethodDescriptor; diff --git a/teavm-core/src/main/java/org/teavm/debugging/SourceLocation.java b/teavm-core/src/main/java/org/teavm/debugging/information/SourceLocation.java similarity index 96% rename from teavm-core/src/main/java/org/teavm/debugging/SourceLocation.java rename to teavm-core/src/main/java/org/teavm/debugging/information/SourceLocation.java index 208dee42a..6ed86524a 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/SourceLocation.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/SourceLocation.java @@ -13,8 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; - +package org.teavm.debugging.information; /** * diff --git a/teavm-core/src/main/java/org/teavm/debugging/SourceLocationIterator.java b/teavm-core/src/main/java/org/teavm/debugging/information/SourceLocationIterator.java similarity index 98% rename from teavm-core/src/main/java/org/teavm/debugging/SourceLocationIterator.java rename to teavm-core/src/main/java/org/teavm/debugging/information/SourceLocationIterator.java index eb13a3350..32451f187 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/SourceLocationIterator.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/SourceLocationIterator.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; import org.teavm.common.RecordArray; diff --git a/teavm-core/src/main/java/org/teavm/debugging/SourceMapsWriter.java b/teavm-core/src/main/java/org/teavm/debugging/information/SourceMapsWriter.java similarity index 99% rename from teavm-core/src/main/java/org/teavm/debugging/SourceMapsWriter.java rename to teavm-core/src/main/java/org/teavm/debugging/information/SourceMapsWriter.java index c1fd88f96..a14a8d8c6 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/SourceMapsWriter.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/SourceMapsWriter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; import java.io.IOException; import java.io.Writer; diff --git a/teavm-core/src/main/java/org/teavm/debugging/URLDebugInformationProvider.java b/teavm-core/src/main/java/org/teavm/debugging/information/URLDebugInformationProvider.java similarity index 96% rename from teavm-core/src/main/java/org/teavm/debugging/URLDebugInformationProvider.java rename to teavm-core/src/main/java/org/teavm/debugging/information/URLDebugInformationProvider.java index eb50bd819..a00524f3b 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/URLDebugInformationProvider.java +++ b/teavm-core/src/main/java/org/teavm/debugging/information/URLDebugInformationProvider.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.information; import java.io.IOException; import java.io.InputStream; diff --git a/teavm-core/src/main/java/org/teavm/debugging/JavaScriptBreakpoint.java b/teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptBreakpoint.java similarity index 95% rename from teavm-core/src/main/java/org/teavm/debugging/JavaScriptBreakpoint.java rename to teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptBreakpoint.java index 009c2c417..e47c633d9 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/JavaScriptBreakpoint.java +++ b/teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptBreakpoint.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.javascript; /** * diff --git a/teavm-core/src/main/java/org/teavm/debugging/JavaScriptCallFrame.java b/teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptCallFrame.java similarity index 95% rename from teavm-core/src/main/java/org/teavm/debugging/JavaScriptCallFrame.java rename to teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptCallFrame.java index a80e8aab2..87a2eb9bc 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/JavaScriptCallFrame.java +++ b/teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptCallFrame.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.javascript; import java.util.Map; diff --git a/teavm-core/src/main/java/org/teavm/debugging/JavaScriptDebugger.java b/teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptDebugger.java similarity index 96% rename from teavm-core/src/main/java/org/teavm/debugging/JavaScriptDebugger.java rename to teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptDebugger.java index eba81e325..4fe7b5f87 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/JavaScriptDebugger.java +++ b/teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptDebugger.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.javascript; /** * diff --git a/teavm-core/src/main/java/org/teavm/debugging/JavaScriptDebuggerListener.java b/teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptDebuggerListener.java similarity index 95% rename from teavm-core/src/main/java/org/teavm/debugging/JavaScriptDebuggerListener.java rename to teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptDebuggerListener.java index 76baafc2e..4ddbcab38 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/JavaScriptDebuggerListener.java +++ b/teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptDebuggerListener.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.javascript; /** * diff --git a/teavm-core/src/main/java/org/teavm/debugging/JavaScriptLocation.java b/teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptLocation.java similarity index 97% rename from teavm-core/src/main/java/org/teavm/debugging/JavaScriptLocation.java rename to teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptLocation.java index 45dc1e24a..7928a2039 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/JavaScriptLocation.java +++ b/teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptLocation.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.javascript; import java.util.Objects; diff --git a/teavm-core/src/main/java/org/teavm/debugging/JavaScriptValue.java b/teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptValue.java similarity index 95% rename from teavm-core/src/main/java/org/teavm/debugging/JavaScriptValue.java rename to teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptValue.java index aac497887..f1d3e9d8e 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/JavaScriptValue.java +++ b/teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptValue.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.javascript; import java.util.Map; diff --git a/teavm-core/src/main/java/org/teavm/debugging/JavaScriptVariable.java b/teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptVariable.java similarity index 95% rename from teavm-core/src/main/java/org/teavm/debugging/JavaScriptVariable.java rename to teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptVariable.java index ff33c83c1..e4900a0d3 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/JavaScriptVariable.java +++ b/teavm-core/src/main/java/org/teavm/debugging/javascript/JavaScriptVariable.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.debugging; +package org.teavm.debugging.javascript; /** * diff --git a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java index 34cee3244..993396ddd 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java +++ b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java @@ -23,9 +23,9 @@ import org.teavm.codegen.NamingException; import org.teavm.codegen.NamingStrategy; import org.teavm.codegen.SourceWriter; import org.teavm.common.ServiceRepository; -import org.teavm.debugging.DebugInformationEmitter; -import org.teavm.debugging.DeferredCallSite; -import org.teavm.debugging.DummyDebugInformationEmitter; +import org.teavm.debugging.information.DebugInformationEmitter; +import org.teavm.debugging.information.DeferredCallSite; +import org.teavm.debugging.information.DummyDebugInformationEmitter; import org.teavm.javascript.ast.*; import org.teavm.javascript.ni.GeneratorContext; import org.teavm.javascript.ni.InjectedBy; diff --git a/teavm-core/src/main/java/org/teavm/tooling/TeaVMTool.java b/teavm-core/src/main/java/org/teavm/tooling/TeaVMTool.java index 96eced894..dc7168596 100644 --- a/teavm-core/src/main/java/org/teavm/tooling/TeaVMTool.java +++ b/teavm-core/src/main/java/org/teavm/tooling/TeaVMTool.java @@ -21,8 +21,8 @@ import java.util.List; import java.util.Properties; import org.apache.commons.io.IOUtils; import org.teavm.common.ThreadPoolFiniteExecutor; -import org.teavm.debugging.DebugInformation; -import org.teavm.debugging.DebugInformationBuilder; +import org.teavm.debugging.information.DebugInformation; +import org.teavm.debugging.information.DebugInformationBuilder; import org.teavm.javascript.RenderingContext; import org.teavm.model.ClassHolderTransformer; import org.teavm.model.MethodDescriptor; diff --git a/teavm-core/src/main/java/org/teavm/vm/TeaVM.java b/teavm-core/src/main/java/org/teavm/vm/TeaVM.java index 70adbaa68..726447bda 100644 --- a/teavm-core/src/main/java/org/teavm/vm/TeaVM.java +++ b/teavm-core/src/main/java/org/teavm/vm/TeaVM.java @@ -20,8 +20,8 @@ import java.util.*; import org.teavm.codegen.*; import org.teavm.common.FiniteExecutor; import org.teavm.common.ServiceRepository; -import org.teavm.debugging.DebugInformationEmitter; -import org.teavm.debugging.SourceLocation; +import org.teavm.debugging.information.DebugInformationEmitter; +import org.teavm.debugging.information.SourceLocation; import org.teavm.dependency.*; import org.teavm.javascript.Decompiler; import org.teavm.javascript.Renderer;