diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringNativeGenerator.java index 64d510deb..34ccf207e 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringNativeGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/StringNativeGenerator.java @@ -32,7 +32,7 @@ public class StringNativeGenerator implements Injector, DependencyPlugin { public void methodAchieved(DependencyChecker checker, MethodDependency method) { switch (method.getReference().getName()) { case "wrap": - method.getVariable(0).connect(method.getResult()); + method.getVariable(1).connect(method.getResult()); break; } } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TInteger.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TInteger.java index d70498198..5bd0d31ce 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TInteger.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TInteger.java @@ -317,11 +317,11 @@ public class TInteger extends TNumber implements TComparable { } public static int bitCount(int i) { - i = (i & 0xAAAAAAAA) >> 1 + i & 0x55555555; - i = (i & 0xCCCCCCCC) >> 2 + i & 0x33333333; - i = (i & 0x30303030) >> 4 + i & 0x03030303; - i = (i & 0x07000700) >> 8 + i & 0x00070007; - i = (i & 0x000F0000) >> 16 + i & 0x0000000F; + i = ((i & 0xAAAAAAAA) >>> 1) + (i & 0x55555555); + i = ((i & 0xCCCCCCCC) >>> 2) + (i & 0x33333333); + i = ((i & 0x70707070) >>> 4) + (i & 0x07070707); + i = ((i & 0x0F000F00) >>> 8) + (i & 0x000F000F); + i = ((i & 0x001F0000) >>> 16) + (i & 0x0000001F); return i; } @@ -336,17 +336,17 @@ public class TInteger extends TNumber implements TComparable { } public static int reverse(int i) { - i = (i & 0xAAAAAAAA) >> 1 | (i & 0x55555555) << 1; - i = (i & 0xCCCCCCCC) >> 2 | (i & 0x33333333) << 2; - i = (i & 0xF0F0F0F0) >> 4 | (i & 0x0F0F0F0F) << 4; - i = (i & 0xFF00FF00) >> 8 | (i & 0x00FF00FF) << 8; - i = (i & 0xFFFF0000) >> 16 | (i & 0x0000FFFF) << 16; + i = ((i & 0xAAAAAAAA) >>> 1) | ((i & 0x55555555) << 1); + i = ((i & 0xCCCCCCCC) >>> 2) | ((i & 0x33333333) << 2); + i = ((i & 0xF0F0F0F0) >>> 4) | ((i & 0x0F0F0F0F) << 4); + i = ((i & 0xFF00FF00) >>> 8) | ((i & 0x00FF00FF) << 8); + i = ((i & 0xFFFF0000) >>> 16) | ((i & 0x0000FFFF) << 16); return i; } public static int reverseBytes(int i) { - i = (i & 0xFF00FF00) >> 8 | (i & 0x00FF00FF) << 8; - i = i >> 16 + i << 16; + i = ((i & 0xFF00FF00) >>> 8) | ((i & 0x00FF00FF) << 8); + i = (i >>> 16) + (i << 16); return i; } diff --git a/teavm-core/src/main/java/org/teavm/parsing/ProgramParser.java b/teavm-core/src/main/java/org/teavm/parsing/ProgramParser.java index f334c983e..0fa2d575b 100644 --- a/teavm-core/src/main/java/org/teavm/parsing/ProgramParser.java +++ b/teavm-core/src/main/java/org/teavm/parsing/ProgramParser.java @@ -40,7 +40,6 @@ public class ProgramParser { private List> targetInstructions; private List builder = new ArrayList<>(); private List basicBlocks = new ArrayList<>(); - private int[] localsMap; private int minLocal; private Program program; private String currentClassName; @@ -81,7 +80,6 @@ public class ProgramParser { return program; } prepare(method); - prepareParameters(method); program.createBasicBlock(); getBasicBlock(0); JumpInstruction insn = new JumpInstruction(); @@ -146,34 +144,6 @@ public class ProgramParser { return depth; } - private void prepareParameters(MethodNode method) { - int var = 0; - int offset = 0; - if ((method.access & Opcodes.ACC_STATIC) == 0) { - getVariable(var++); - ++offset; - } - ValueType[] desc = MethodDescriptor.parse(method.desc).getParameterTypes(); - localsMap = new int[desc.length * 2 + 1]; - for (int i = 0; i < desc.length; ++i) { - ValueType paramType = desc[i]; - localsMap[var] = i + offset; - getVariable(var++); - if (paramType instanceof ValueType.Primitive) { - switch (((ValueType.Primitive)paramType).getKind()) { - case LONG: - case DOUBLE: - localsMap[var] = i + offset; - getVariable(var++); - break; - default: - break; - } - } - } - localsMap = Arrays.copyOf(localsMap, var); - } - private void prepare(MethodNode method) { InsnList instructions = method.instructions; minLocal = 0; @@ -323,9 +293,6 @@ public class ProgramParser { } private int mapLocal(int local) { - if (local < localsMap.length) { - local = localsMap[local]; - } return local; } @@ -1528,8 +1495,7 @@ public class ProgramParser { @Override public void visitIincInsn(int var, int increment) { - var = mapLocal(var); - var += minLocal; + var = minLocal + mapLocal(var); int tmp = pushSingle(); popSingle(); IntegerConstantInstruction intInsn = new IntegerConstantInstruction(); diff --git a/teavm-core/src/main/java/org/teavm/parsing/SSATransformer.java b/teavm-core/src/main/java/org/teavm/parsing/SSATransformer.java index fd8d2585f..46d93dbc0 100644 --- a/teavm-core/src/main/java/org/teavm/parsing/SSATransformer.java +++ b/teavm-core/src/main/java/org/teavm/parsing/SSATransformer.java @@ -69,7 +69,7 @@ public class SSATransformer { variableMap[index] = program.variableAt(index); ++index; for (int i = 0; i < arguments.length; ++i) { - variableMap[index] = program.variableAt(index); + variableMap[index] = program.variableAt(i + 1); ++index; ValueType arg = arguments[i]; if (arg instanceof ValueType.Primitive) {