Merge remote-tracking branch 'origin/master' into optimizations

This commit is contained in:
Alexey Andreev 2016-05-13 20:47:38 +03:00
commit 8abf4797af
7 changed files with 94 additions and 49 deletions

View File

@ -167,13 +167,28 @@ public class TPrintStream extends TFilterOutputStream {
printSB(); printSB();
} }
public void println(int i) { public void print(long l) {
sb.append(i).append('\n'); sb.append(l);
printSB(); printSB();
} }
public void print(long l) { public void print(double d) {
sb.append(l); sb.append(d);
printSB();
}
public void print(TString s) {
sb.append(s);
printSB();
}
public void print(TObject s) {
sb.append(s);
printSB();
}
public void println(int i) {
sb.append(i).append('\n');
printSB(); printSB();
} }
@ -187,11 +202,6 @@ public class TPrintStream extends TFilterOutputStream {
printSB(); printSB();
} }
public void print(TString s) {
sb.append(s);
printSB();
}
public void println(TString s) { public void println(TString s) {
sb.append(s).append('\n'); sb.append(s).append('\n');
printSB(); printSB();

View File

@ -21,6 +21,7 @@ import org.teavm.javascript.spi.Superclass;
import org.teavm.javascript.spi.Sync; import org.teavm.javascript.spi.Sync;
import org.teavm.jso.browser.TimerHandler; import org.teavm.jso.browser.TimerHandler;
import org.teavm.platform.Platform; import org.teavm.platform.Platform;
import org.teavm.platform.PlatformObject;
import org.teavm.platform.PlatformQueue; import org.teavm.platform.PlatformQueue;
import org.teavm.platform.PlatformRunnable; import org.teavm.platform.PlatformRunnable;
import org.teavm.platform.async.AsyncCallback; import org.teavm.platform.async.AsyncCallback;
@ -168,7 +169,6 @@ public class TObject {
@Rename("<init>") @Rename("<init>")
private void init() { private void init() {
Platform.getPlatformObject(this).setId(Platform.nextObjectId());
} }
@Rename("getClass") @Rename("getClass")
@ -192,6 +192,10 @@ public class TObject {
} }
int identity() { int identity() {
PlatformObject platformThis = Platform.getPlatformObject(this);
if (platformThis.getId() == 0) {
platformThis.setId(Platform.nextObjectId());
}
return Platform.getPlatformObject(this).getId(); return Platform.getPlatformObject(this).getId();
} }

View File

@ -390,6 +390,11 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
.append("=").ws().append(constantToString(value)).append(";").softNewLine(); .append("=").ws().append(constantToString(value)).append(";").softNewLine();
debugEmitter.addField(field.getName(), naming.getNameFor(fieldRef)); debugEmitter.addField(field.getName(), naming.getNameFor(fieldRef));
} }
if (cls.getName().equals("java.lang.Object")) {
writer.append("this.$id").ws().append('=').ws().append("0;").softNewLine();
}
writer.outdent().append("}").newLine(); writer.outdent().append("}").newLine();
for (FieldNode field : staticFields) { for (FieldNode field : staticFields) {
@ -1245,12 +1250,21 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
List<String> nameList = new ArrayList<>(names); List<String> nameList = new ArrayList<>(names);
Collections.sort(nameList); Collections.sort(nameList);
for (String name : nameList) { for (String name : nameList) {
sb.append('_').append(name); sb.append('_').append(escapeName(name));
} }
} }
return sb.toString(); return sb.toString();
} }
private static String escapeName(String name) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < name.length(); ++i) {
char c = name.charAt(i);
sb.append(Character.isJavaIdentifierPart(c) ? c : '_');
}
return sb.toString();
}
private String pointerName() { private String pointerName() {
return minifying ? "$p" : "$ptr"; return minifying ? "$p" : "$ptr";
} }

View File

@ -28,10 +28,10 @@ import org.teavm.model.util.ProgramUtils;
* @author Alexey Andreev * @author Alexey Andreev
*/ */
public class ProgramParser implements VariableDebugInformation { public class ProgramParser implements VariableDebugInformation {
static final byte ROOT = 0; private static final byte ROOT = 0;
static final byte SINGLE = 1; private static final byte SINGLE = 1;
static final byte DOUBLE_FIRST_HALF = 2; private static final byte DOUBLE_FIRST_HALF = 2;
static final byte DOUBLE_SECOND_HALF = 3; private static final byte DOUBLE_SECOND_HALF = 3;
private String fileName; private String fileName;
private StackFrame[] stackBefore; private StackFrame[] stackBefore;
private StackFrame[] stackAfter; private StackFrame[] stackAfter;
@ -60,17 +60,17 @@ public class ProgramParser implements VariableDebugInformation {
} }
private static class StackFrame { private static class StackFrame {
public final StackFrame next; final StackFrame next;
public final byte type; final byte type;
public final int depth; final int depth;
public StackFrame(int depth) { StackFrame(int depth) {
this.next = null; this.next = null;
this.type = ROOT; this.type = ROOT;
this.depth = depth; this.depth = depth;
} }
public StackFrame(StackFrame next, byte type) { StackFrame(StackFrame next, byte type) {
this.next = next; this.next = next;
this.type = type; this.type = type;
this.depth = next != null ? next.depth + 1 : 0; this.depth = next != null ? next.depth + 1 : 0;
@ -162,7 +162,7 @@ public class ProgramParser implements VariableDebugInformation {
@Override @Override
public Map<Integer, String> getDebugNames(Instruction insn) { public Map<Integer, String> getDebugNames(Instruction insn) {
Map<Integer, String> map = variableDebugNames.get(insn); Map<Integer, String> map = variableDebugNames.get(insn);
return map != null ? Collections.unmodifiableMap(map) : Collections.<Integer, String>emptyMap(); return map != null ? Collections.unmodifiableMap(map) : Collections.emptyMap();
} }
private void prepare(MethodNode method) { private void prepare(MethodNode method) {
@ -513,8 +513,8 @@ public class ProgramParser implements VariableDebugInformation {
} }
insn.setMethod(new MethodDescriptor(name, MethodDescriptor.parseSignature(desc))); insn.setMethod(new MethodDescriptor(name, MethodDescriptor.parseSignature(desc)));
for (int i = 0; i < bsmArgs.length; ++i) { for (Object bsmArg : bsmArgs) {
insn.getBootstrapArguments().add(convertConstant(bsmArgs[i])); insn.getBootstrapArguments().add(convertConstant(bsmArg));
} }
addInstruction(insn); addInstruction(insn);
@ -1200,8 +1200,9 @@ public class ProgramParser implements VariableDebugInformation {
case Opcodes.SWAP: { case Opcodes.SWAP: {
int b = popSingle(); int b = popSingle();
int a = popSingle(); int a = popSingle();
int tmp = pushSingle();
pushSingle(); pushSingle();
pushSingle();
int tmp = b + 1;
emitAssignInsn(a, tmp); emitAssignInsn(a, tmp);
emitAssignInsn(b, a); emitAssignInsn(b, a);
emitAssignInsn(tmp, b); emitAssignInsn(tmp, b);
@ -1726,7 +1727,7 @@ public class ProgramParser implements VariableDebugInformation {
} }
}; };
static MethodHandle parseHandle(Handle handle) { private static MethodHandle parseHandle(Handle handle) {
switch (handle.getTag()) { switch (handle.getTag()) {
case Opcodes.H_GETFIELD: case Opcodes.H_GETFIELD:
return MethodHandle.fieldGetter(handle.getOwner().replace('/', '.'), handle.getName(), return MethodHandle.fieldGetter(handle.getOwner().replace('/', '.'), handle.getName(),

View File

@ -14,9 +14,15 @@
* limitations under the License. * limitations under the License.
*/ */
"use strict"; "use strict";
var $rt_lastObjectId = 0; var $rt_lastObjectId = 1;
function $rt_nextId() { function $rt_nextId() {
return $rt_lastObjectId++; var current = $rt_lastObjectId;
var next = (current + 1) | 0;
if (next === 0) {
next = (next + 1) | 0;
}
$rt_lastObjectId = next;
return current;
} }
function $rt_compare(a, b) { function $rt_compare(a, b) {
return a > b ? 1 : a < b ? -1 : 0; return a > b ? 1 : a < b ? -1 : 0;
@ -39,14 +45,17 @@ function $rt_isAssignable(from, to) {
function $rt_createArray(cls, sz) { function $rt_createArray(cls, sz) {
var data = new Array(sz); var data = new Array(sz);
var arr = new ($rt_arraycls(cls))(data); var arr = new ($rt_arraycls(cls))(data);
for (var i = 0; i < sz; i = (i + 1) | 0) { if (sz > 0) {
data[i] = null; var i = 0;
do {
data[i] = null;
i = (i + 1) | 0;
} while (i < sz);
} }
return arr; return arr;
} }
function $rt_wrapArray(cls, data) { function $rt_wrapArray(cls, data) {
var arr = new ($rt_arraycls(cls))(data); return new ($rt_arraycls(cls))(data);
return arr;
} }
function $rt_createUnfilledArray(cls, sz) { function $rt_createUnfilledArray(cls, sz) {
return new ($rt_arraycls(cls))(new Array(sz)); return new ($rt_arraycls(cls))(new Array(sz));
@ -67,7 +76,7 @@ var $rt_createIntArray;
var $rt_createBooleanArray; var $rt_createBooleanArray;
var $rt_createFloatArray; var $rt_createFloatArray;
var $rt_createDoubleArray; var $rt_createDoubleArray;
if (ArrayBuffer) { if (typeof 'ArrayBuffer' !== 'undefined') {
$rt_createNumericArray = function(cls, nativeArray) { $rt_createNumericArray = function(cls, nativeArray) {
return new ($rt_arraycls(cls))(nativeArray); return new ($rt_arraycls(cls))(nativeArray);
}; };
@ -110,10 +119,11 @@ if (ArrayBuffer) {
$rt_createCharArray = function(sz) { return $rt_createNumericArray($rt_charcls(), sz); } $rt_createCharArray = function(sz) { return $rt_createNumericArray($rt_charcls(), sz); }
} }
function $rt_arraycls(cls) { function $rt_arraycls(cls) {
if (typeof cls.$array === 'undefined') { var result = cls.$array;
if (result === null) {
var arraycls = function(data) { var arraycls = function(data) {
this.data = data; this.data = data;
this.$id = $rt_nextId(); this.$id = 0;
}; };
arraycls.prototype = new ($rt_objcls())(); arraycls.prototype = new ($rt_objcls())();
arraycls.prototype.constructor = arraycls; arraycls.prototype.constructor = arraycls;
@ -132,12 +142,15 @@ function $rt_arraycls(cls) {
arraycls.$meta = { item : cls, supertypes : [$rt_objcls()], primitive : false, superclass : $rt_objcls(), arraycls.$meta = { item : cls, supertypes : [$rt_objcls()], primitive : false, superclass : $rt_objcls(),
name : name, binaryName : name, enum : false }; name : name, binaryName : name, enum : false };
arraycls.classObject = null; arraycls.classObject = null;
arraycls.$array = null;
result = arraycls;
cls.$array = arraycls; cls.$array = arraycls;
} }
return cls.$array; return result;
} }
function $rt_createcls() { function $rt_createcls() {
return { return {
$array : null,
classObject : null, classObject : null,
$meta : { $meta : {
supertypes : [], supertypes : [],
@ -228,7 +241,7 @@ function $rt_throw(ex) {
function $rt_exception(ex) { function $rt_exception(ex) {
var err = ex.$jsException; var err = ex.$jsException;
if (!err) { if (!err) {
var err = new Error("Java exception thrown"); err = new Error("Java exception thrown");
err.$javaException = ex; err.$javaException = ex;
ex.$jsException = err; ex.$jsException = err;
} }
@ -363,7 +376,7 @@ function $rt_putStderr(ch) {
} }
function $rt_metadata(data) { function $rt_metadata(data) {
for (var i = 0; i < data.length; i += 8) { for (var i = 0; i < data.length; i += 8) {
var cls = data[i + 0]; var cls = data[i];
cls.$meta = {}; cls.$meta = {};
var m = cls.$meta; var m = cls.$meta;
m.name = data[i + 1]; m.name = data[i + 1];
@ -402,8 +415,8 @@ function $rt_metadata(data) {
} }
var virtualMethods = data[i + 7]; var virtualMethods = data[i + 7];
for (var j = 0; j < virtualMethods.length; j += 2) { for (j = 0; j < virtualMethods.length; j += 2) {
var name = virtualMethods[j + 0]; var name = virtualMethods[j];
var func = virtualMethods[j + 1]; var func = virtualMethods[j + 1];
if (typeof name === 'string') { if (typeof name === 'string') {
name = [name]; name = [name];
@ -412,6 +425,8 @@ function $rt_metadata(data) {
cls.prototype[name[k]] = func; cls.prototype[name[k]] = func;
} }
} }
cls.$array = null;
} }
} }
function $rt_threadStarter(f) { function $rt_threadStarter(f) {
@ -681,7 +696,7 @@ function Long_compare(a, b) {
if (r !== 0) { if (r !== 0) {
return r; return r;
} }
var r = (a.lo >>> 1) - (b.lo >>> 1); r = (a.lo >>> 1) - (b.lo >>> 1);
if (r !== 0) { if (r !== 0) {
return r; return r;
} }
@ -895,15 +910,15 @@ function LongInt_ucompare(a, b) {
if (r != 0) { if (r != 0) {
return r; return r;
} }
var r = (a.hi >>> 1) - (b.hi >>> 1); r = (a.hi >>> 1) - (b.hi >>> 1);
if (r != 0) { if (r != 0) {
return r; return r;
} }
var r = (a.hi & 1) - (b.hi & 1); r = (a.hi & 1) - (b.hi & 1);
if (r != 0) { if (r != 0) {
return r; return r;
} }
var r = (a.lo >>> 1) - (b.lo >>> 1); r = (a.lo >>> 1) - (b.lo >>> 1);
if (r != 0) { if (r != 0) {
return r; return r;
} }
@ -924,7 +939,8 @@ function LongInt_numOfLeadingZeroBits(a) {
function LongInt_shl(a, b) { function LongInt_shl(a, b) {
if (b == 0) { if (b == 0) {
return; return;
} else if (b < 32) { }
if (b < 32) {
a.sup = ((a.hi >>> (32 - b)) | (a.sup << b)) & 0xFFFF; a.sup = ((a.hi >>> (32 - b)) | (a.sup << b)) & 0xFFFF;
a.hi = (a.lo >>> (32 - b)) | (a.hi << b); a.hi = (a.lo >>> (32 - b)) | (a.hi << b);
a.lo <<= b; a.lo <<= b;
@ -949,7 +965,8 @@ function LongInt_shl(a, b) {
function LongInt_shr(a, b) { function LongInt_shr(a, b) {
if (b == 0) { if (b == 0) {
return; return;
} else if (b == 32) { }
if (b == 32) {
a.lo = a.hi; a.lo = a.hi;
a.hi = a.sup; a.hi = a.sup;
a.sup = 0; a.sup = 0;

View File

@ -110,7 +110,7 @@ public interface HTMLElement extends Element, ElementCSSInlineStyle, EventTarget
HTMLDocument getOwnerDocument(); HTMLDocument getOwnerDocument();
@JSProperty @JSProperty
int getInnerHTML(); String getInnerHTML();
@JSProperty @JSProperty
void setInnerHTML(String content); void setInnerHTML(String content);

View File

@ -74,9 +74,8 @@ public final class Platform {
return (PlatformConsole) Window.current(); return (PlatformConsole) Window.current();
} }
public static int nextObjectId() { @JSBody(params = {}, script = "return $rt_nextId();")
return ((PlatformHelper) Window.current()).nextId(); public static native int nextObjectId();
}
public static <T> T newInstance(PlatformClass cls) { public static <T> T newInstance(PlatformClass cls) {
prepareNewInstance(); prepareNewInstance();