From 92d40782288d156767a2107a0af741f98ef92282 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Tue, 4 Mar 2014 00:06:03 +0400 Subject: [PATCH] Fixes classpath bugs. Fixes internal analysis bug. Adds some JCL --- .../lang/TIncompatibleClassChangeError.java | 32 ++++++++ .../classlib/java/lang/TNoSuchFieldError.java | 32 ++++++++ .../java/util/RandomNativeGenerator.java | 33 +++++++++ .../org/teavm/classlib/java/util/TRandom.java | 73 +++++++++++++++++++ .../main/java/org/teavm/common/LoopGraph.java | 9 +-- teavm-html4j/pom.xml | 6 ++ 6 files changed, 180 insertions(+), 5 deletions(-) create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TIncompatibleClassChangeError.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TNoSuchFieldError.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/RandomNativeGenerator.java create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TIncompatibleClassChangeError.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TIncompatibleClassChangeError.java new file mode 100644 index 000000000..fdc9255bd --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TIncompatibleClassChangeError.java @@ -0,0 +1,32 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.lang; + +/** + * + * @author Alexey Andreev + */ +public class TIncompatibleClassChangeError extends TLinkageError { + private static final long serialVersionUID = 366119408566298082L; + + public TIncompatibleClassChangeError() { + super(); + } + + public TIncompatibleClassChangeError(TString message) { + super(message); + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TNoSuchFieldError.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TNoSuchFieldError.java new file mode 100644 index 000000000..b8db670d8 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TNoSuchFieldError.java @@ -0,0 +1,32 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.lang; + +/** + * + * @author Alexey Andreev + */ +public class TNoSuchFieldError extends TIncompatibleClassChangeError { + private static final long serialVersionUID = 7907885242472547035L; + + public TNoSuchFieldError() { + super(); + } + + public TNoSuchFieldError(TString message) { + super(message); + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/RandomNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/RandomNativeGenerator.java new file mode 100644 index 000000000..c922cf767 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/RandomNativeGenerator.java @@ -0,0 +1,33 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util; + +import java.io.IOException; +import org.teavm.codegen.SourceWriter; +import org.teavm.javascript.ni.Generator; +import org.teavm.javascript.ni.GeneratorContext; +import org.teavm.model.MethodReference; + +/** + * + * @author Alexey Andreev + */ +public class RandomNativeGenerator implements Generator { + @Override + public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException { + writer.append("return Math.random();").softNewLine(); + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java new file mode 100644 index 000000000..5924878b0 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java @@ -0,0 +1,73 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util; + +import org.teavm.classlib.java.io.TSerializable; +import org.teavm.classlib.java.lang.TMath; +import org.teavm.classlib.java.lang.TObject; +import org.teavm.javascript.ni.GeneratedBy; + +/** + * + * @author Alexey Andreev + */ +public class TRandom extends TObject implements TSerializable { + public TRandom() { + } + + public TRandom(@SuppressWarnings("unused") long seed) { + } + + public void setSeed(@SuppressWarnings("unused") long seed) { + } + + protected int next(int bits) { + return (int)(random() * (1 << TMath.min(32, bits))); + } + + public void nextBytes(byte[] bytes) { + for (int i = 0; i < bytes.length; ) { + bytes[i] = (byte)next(8); + } + } + + public int nextInt() { + return next(32); + } + + public int nextInt(int n) { + return (int)(random() * n); + } + + public long nextLong() { + return ((long)nextInt() << 32) | nextInt(); + } + + public boolean nextBoolean() { + return nextInt() % 2 == 0; + } + + public float nextFloat() { + return (float)random(); + } + + public double nextDouble() { + return random(); + } + + @GeneratedBy(RandomNativeGenerator.class) + private static native double random(); +} diff --git a/teavm-core/src/main/java/org/teavm/common/LoopGraph.java b/teavm-core/src/main/java/org/teavm/common/LoopGraph.java index ff9191ab2..3087f8973 100644 --- a/teavm-core/src/main/java/org/teavm/common/LoopGraph.java +++ b/teavm-core/src/main/java/org/teavm/common/LoopGraph.java @@ -86,7 +86,6 @@ public class LoopGraph implements Graph { LoopFrame rootFrame = new LoopFrame(); stack[stackSize++] = rootFrame; int walkIndex = 0; - int[] targetEdges = new int[sz]; int lastSortIndex = sz - 1; int loopSetSize = 0; while (stackSize > 0) { @@ -95,8 +94,8 @@ public class LoopGraph implements Graph { frames[frame.index] = frame; frame.walkIndex = walkIndex++; stack[stackSize++] = frame; - int targetEdgesCount = graph.copyOutgoingEdges(frame.index, targetEdges); - for (int i = 0; i < targetEdgesCount; ++i) { + int[] targetEdges = graph.outgoingEdges(frame.index); + for (int i = 0; i < targetEdges.length; ++i) { int next = targetEdges[i]; LoopFrame nextFrame = frames[next]; if (nextFrame == null) { @@ -109,8 +108,8 @@ public class LoopGraph implements Graph { frame.sortIndex = lastSortIndex--; frame.done = true; LoopImpl bestLoop = null; - int targetEdgesCount = graph.copyOutgoingEdges(frame.index, targetEdges); - for (int i = 0; i < targetEdgesCount; ++i) { + int[] targetEdges = graph.outgoingEdges(frame.index); + for (int i = 0; i < targetEdges.length; ++i) { int next = targetEdges[i]; LoopFrame nextFrame = frames[next]; LoopImpl loop = nextFrame.loop; diff --git a/teavm-html4j/pom.xml b/teavm-html4j/pom.xml index 3990ca7bc..8bd267988 100644 --- a/teavm-html4j/pom.xml +++ b/teavm-html4j/pom.xml @@ -38,6 +38,12 @@ org.netbeans.html net.java.html.boot 0.8-SNAPSHOT + + + org.ow2.asm + asm + + org.netbeans.html