diff --git a/core/src/main/java/org/teavm/backend/javascript/JavaScriptTarget.java b/core/src/main/java/org/teavm/backend/javascript/JavaScriptTarget.java index d21afc3eb..0c79b9e89 100644 --- a/core/src/main/java/org/teavm/backend/javascript/JavaScriptTarget.java +++ b/core/src/main/java/org/teavm/backend/javascript/JavaScriptTarget.java @@ -531,7 +531,7 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost { initExceptionInsn.setInstance(exceptionVar); initExceptionInsn.setMethod(new MethodReference(NoSuchMethodError.class, "", String.class, void.class)); initExceptionInsn.setType(InvocationType.SPECIAL); - initExceptionInsn.getArguments().add(constVar); + initExceptionInsn.setArguments(constVar); block.add(initExceptionInsn); RaiseInstruction raiseInsn = new RaiseInstruction(); diff --git a/core/src/main/java/org/teavm/cache/ProgramIO.java b/core/src/main/java/org/teavm/cache/ProgramIO.java index eaae23f2e..f99e5dcff 100644 --- a/core/src/main/java/org/teavm/cache/ProgramIO.java +++ b/core/src/main/java/org/teavm/cache/ProgramIO.java @@ -1039,9 +1039,11 @@ public class ProgramIO { MethodDescriptor methodDesc = parseMethodDescriptor(symbolTable.at(input.readInt())); insn.setMethod(createMethodReference(className, methodDesc)); int paramCount = insn.getMethod().getDescriptor().parameterCount(); + Variable[] arguments = new Variable[paramCount]; for (int i = 0; i < paramCount; ++i) { - insn.getArguments().add(program.variableAt(input.readShort())); + arguments[i] = program.variableAt(input.readShort()); } + insn.setArguments(arguments); return insn; } case 34: { @@ -1054,9 +1056,11 @@ public class ProgramIO { MethodDescriptor methodDesc = parseMethodDescriptor(symbolTable.at(input.readInt())); insn.setMethod(createMethodReference(className, methodDesc)); int paramCount = insn.getMethod().getDescriptor().parameterCount(); + Variable[] arguments = new Variable[paramCount]; for (int i = 0; i < paramCount; ++i) { - insn.getArguments().add(program.variableAt(input.readShort())); + arguments[i] = program.variableAt(input.readShort()); } + insn.setArguments(arguments); return insn; } case 35: { @@ -1069,9 +1073,11 @@ public class ProgramIO { MethodDescriptor methodDesc = parseMethodDescriptor(symbolTable.at(input.readInt())); insn.setMethod(createMethodReference(className, methodDesc)); int paramCount = insn.getMethod().getDescriptor().parameterCount(); + Variable[] arguments = new Variable[paramCount]; for (int i = 0; i < paramCount; ++i) { - insn.getArguments().add(program.variableAt(input.readShort())); + arguments[i] = program.variableAt(input.readShort()); } + insn.setArguments(arguments); return insn; } case 36: { diff --git a/core/src/main/java/org/teavm/model/InstructionReadVisitor.java b/core/src/main/java/org/teavm/model/InstructionReadVisitor.java index 3106730ea..9c0c68642 100644 --- a/core/src/main/java/org/teavm/model/InstructionReadVisitor.java +++ b/core/src/main/java/org/teavm/model/InstructionReadVisitor.java @@ -179,8 +179,7 @@ public class InstructionReadVisitor implements InstructionVisitor { @Override public void visit(InvokeInstruction insn) { - reader.invoke(insn.getReceiver(), insn.getInstance(), insn.getMethod(), - Collections.unmodifiableList(insn.getArguments()), insn.getType()); + reader.invoke(insn.getReceiver(), insn.getInstance(), insn.getMethod(), insn.getArguments(), insn.getType()); } @Override diff --git a/core/src/main/java/org/teavm/model/emit/ProgramEmitter.java b/core/src/main/java/org/teavm/model/emit/ProgramEmitter.java index 2e7dad5a3..2484ff6d2 100644 --- a/core/src/main/java/org/teavm/model/emit/ProgramEmitter.java +++ b/core/src/main/java/org/teavm/model/emit/ProgramEmitter.java @@ -236,9 +236,12 @@ public final class ProgramEmitter { insn.setType(InvocationType.SPECIAL); insn.setMethod(method); insn.setReceiver(result); - for (ValueEmitter arg : arguments) { - insn.getArguments().add(arg.variable); + Variable[] insnArguments = new Variable[arguments.length]; + for (int i = 0; i < insnArguments.length; ++i) { + insnArguments[i] = arguments[i].variable; } + insn.setArguments(insnArguments); + addInstruction(insn); return result != null ? var(result, method.getReturnType()) : null; } @@ -260,9 +263,11 @@ public final class ProgramEmitter { insn.setType(InvocationType.SPECIAL); insn.setMethod(method); insn.setReceiver(result); - for (ValueEmitter arg : arguments) { - insn.getArguments().add(arg.variable); + Variable[] insnArguments = new Variable[arguments.length]; + for (int i = 0; i < insnArguments.length; ++i) { + insnArguments[i] = arguments[i].variable; } + insn.setArguments(insnArguments); addInstruction(insn); return result != null ? var(result, resultType) : null; } diff --git a/core/src/main/java/org/teavm/model/emit/ValueEmitter.java b/core/src/main/java/org/teavm/model/emit/ValueEmitter.java index 5c8549c0a..657bb19a0 100644 --- a/core/src/main/java/org/teavm/model/emit/ValueEmitter.java +++ b/core/src/main/java/org/teavm/model/emit/ValueEmitter.java @@ -445,9 +445,11 @@ public class ValueEmitter { insn.setMethod(method); insn.setInstance(variable); insn.setReceiver(result); - for (ValueEmitter arg : arguments) { - insn.getArguments().add(arg.variable); + Variable[] insnArguments = new Variable[arguments.length]; + for (int i = 0; i < insnArguments.length; ++i) { + insnArguments[i] = arguments[i].variable; } + insn.setArguments(insnArguments); pe.addInstruction(insn); return result != null ? pe.var(result, method.getReturnType()) : null; } @@ -474,9 +476,11 @@ public class ValueEmitter { insn.setMethod(method); insn.setInstance(variable); insn.setReceiver(result); - for (ValueEmitter arg : arguments) { - insn.getArguments().add(arg.variable); + Variable[] insnArguments = new Variable[arguments.length]; + for (int i = 0; i < insnArguments.length; ++i) { + insnArguments[i] = arguments[i].variable; } + insn.setArguments(insnArguments); pe.addInstruction(insn); return result != null ? pe.var(result, resultType) : null; } diff --git a/core/src/main/java/org/teavm/model/instructions/InvokeInstruction.java b/core/src/main/java/org/teavm/model/instructions/InvokeInstruction.java index 213349458..f546ab852 100644 --- a/core/src/main/java/org/teavm/model/instructions/InvokeInstruction.java +++ b/core/src/main/java/org/teavm/model/instructions/InvokeInstruction.java @@ -15,8 +15,10 @@ */ package org.teavm.model.instructions; +import java.util.AbstractList; import java.util.ArrayList; import java.util.List; +import java.util.function.UnaryOperator; import org.teavm.model.Instruction; import org.teavm.model.MethodReference; import org.teavm.model.Variable; @@ -25,7 +27,7 @@ public class InvokeInstruction extends Instruction { private InvocationType type; private MethodReference method; private Variable instance; - private List arguments = new ArrayList<>(1); + private Variable[] arguments; private Variable receiver; public InvocationType getType() { @@ -44,8 +46,20 @@ public class InvokeInstruction extends Instruction { this.instance = instance; } - public List getArguments() { - return arguments; + public List getArguments() { + return argumentList; + } + + public void replaceArguments(UnaryOperator f) { + if (arguments != null) { + for (int i = 0; i < arguments.length; ++i) { + arguments[i] = f.apply(arguments[i]); + } + } + } + + public void setArguments(Variable... arguments) { + this.arguments = arguments.length > 0 ? arguments.clone() : null; } public MethodReference getMethod() { @@ -68,4 +82,19 @@ public class InvokeInstruction extends Instruction { public void acceptVisitor(InstructionVisitor visitor) { visitor.visit(this); } + + private List argumentList = new AbstractList() { + @Override + public Variable get(int index) { + if (arguments == null) { + throw new IndexOutOfBoundsException(); + } + return arguments[index]; + } + + @Override + public int size() { + return arguments != null ? arguments.length : 0; + } + }; } diff --git a/core/src/main/java/org/teavm/model/lowlevel/ClassInitializerTransformer.java b/core/src/main/java/org/teavm/model/lowlevel/ClassInitializerTransformer.java index 02e782487..2a86b8edb 100644 --- a/core/src/main/java/org/teavm/model/lowlevel/ClassInitializerTransformer.java +++ b/core/src/main/java/org/teavm/model/lowlevel/ClassInitializerTransformer.java @@ -95,7 +95,7 @@ public class ClassInitializerTransformer { InvokeInstruction checkInitialized = new InvokeInstruction(); checkInitialized.setType(InvocationType.SPECIAL); checkInitialized.setMethod(new MethodReference(Allocator.class, "isInitialized", Class.class, boolean.class)); - checkInitialized.getArguments().add(clsVariable); + checkInitialized.setArguments(clsVariable); checkInitialized.setReceiver(initializedVariable); block.add(checkInitialized); diff --git a/core/src/main/java/org/teavm/model/lowlevel/ExceptionHandlingShadowStackContributor.java b/core/src/main/java/org/teavm/model/lowlevel/ExceptionHandlingShadowStackContributor.java index 1a096511f..699ca5d5b 100644 --- a/core/src/main/java/org/teavm/model/lowlevel/ExceptionHandlingShadowStackContributor.java +++ b/core/src/main/java/org/teavm/model/lowlevel/ExceptionHandlingShadowStackContributor.java @@ -185,7 +185,7 @@ public class ExceptionHandlingShadowStackContributor { raise.setMethod(new MethodReference(ExceptionHandling.class, "throwException", Throwable.class, void.class)); raise.setType(InvocationType.SPECIAL); - raise.getArguments().add(((RaiseInstruction) insn).getException()); + raise.setArguments(((RaiseInstruction) insn).getException()); raise.setLocation(insn.getLocation()); insn.replace(raise); insn = raise; @@ -300,7 +300,7 @@ public class ExceptionHandlingShadowStackContributor { InvokeInstruction registerInsn = new InvokeInstruction(); registerInsn.setMethod(new MethodReference(ShadowStack.class, "registerCallSite", int.class, void.class)); registerInsn.setType(InvocationType.SPECIAL); - registerInsn.getArguments().add(idVariable); + registerInsn.setArguments(idVariable); instructions.add(registerInsn); return instructions; diff --git a/core/src/main/java/org/teavm/model/lowlevel/GCShadowStackContributor.java b/core/src/main/java/org/teavm/model/lowlevel/GCShadowStackContributor.java index c0ca218db..85733d79e 100644 --- a/core/src/main/java/org/teavm/model/lowlevel/GCShadowStackContributor.java +++ b/core/src/main/java/org/teavm/model/lowlevel/GCShadowStackContributor.java @@ -374,18 +374,20 @@ public class GCShadowStackContributor { slotConstant.setLocation(callInstruction.getLocation()); instructionsToAdd.add(slotConstant); + List arguments = new ArrayList<>(); InvokeInstruction registerInvocation = new InvokeInstruction(); registerInvocation.setLocation(callInstruction.getLocation()); registerInvocation.setType(InvocationType.SPECIAL); - registerInvocation.getArguments().add(slotVar); + arguments.add(slotVar); if (var >= 0) { registerInvocation.setMethod(new MethodReference(ShadowStack.class, "registerGCRoot", int.class, Object.class, void.class)); - registerInvocation.getArguments().add(program.variableAt(var)); + arguments.add(program.variableAt(var)); } else { registerInvocation.setMethod(new MethodReference(ShadowStack.class, "removeGCRoot", int.class, void.class)); } + registerInvocation.setArguments(arguments.toArray(new Variable[0])); instructionsToAdd.add(registerInvocation); } diff --git a/core/src/main/java/org/teavm/model/lowlevel/ShadowStackTransformer.java b/core/src/main/java/org/teavm/model/lowlevel/ShadowStackTransformer.java index b06ff7d9c..c8b184f00 100644 --- a/core/src/main/java/org/teavm/model/lowlevel/ShadowStackTransformer.java +++ b/core/src/main/java/org/teavm/model/lowlevel/ShadowStackTransformer.java @@ -74,7 +74,7 @@ public class ShadowStackTransformer { InvokeInstruction invocation = new InvokeInstruction(); invocation.setType(InvocationType.SPECIAL); invocation.setMethod(new MethodReference(ShadowStack.class, "allocStack", int.class, void.class)); - invocation.getArguments().add(sizeVariable); + invocation.setArguments(sizeVariable); instructionsToAdd.add(invocation); block.addFirstAll(instructionsToAdd); @@ -139,7 +139,7 @@ public class ShadowStackTransformer { InvokeInstruction invocation = new InvokeInstruction(); invocation.setType(InvocationType.SPECIAL); invocation.setMethod(new MethodReference(ShadowStack.class, "releaseStack", int.class, void.class)); - invocation.getArguments().add(sizeVariable); + invocation.setArguments(sizeVariable); instructionsToAdd.add(invocation); exitBlock.getLastInstruction().insertPreviousAll(instructionsToAdd); diff --git a/core/src/main/java/org/teavm/model/optimization/GlobalValueNumbering.java b/core/src/main/java/org/teavm/model/optimization/GlobalValueNumbering.java index c9714fdd4..4977f0b45 100644 --- a/core/src/main/java/org/teavm/model/optimization/GlobalValueNumbering.java +++ b/core/src/main/java/org/teavm/model/optimization/GlobalValueNumbering.java @@ -727,7 +727,7 @@ public class GlobalValueNumbering implements MethodOptimization { int instance = map[insn.getInstance().getIndex()]; insn.setInstance(program.variableAt(instance)); } - insn.getArguments().replaceAll(mapper); + insn.replaceArguments(mapper); } @Override diff --git a/core/src/main/java/org/teavm/model/text/ListingParser.java b/core/src/main/java/org/teavm/model/text/ListingParser.java index 14d249024..9a5abef63 100644 --- a/core/src/main/java/org/teavm/model/text/ListingParser.java +++ b/core/src/main/java/org/teavm/model/text/ListingParser.java @@ -713,9 +713,9 @@ public class ListingParser { lexer.getIndex()); } insn.setInstance(arguments.get(0)); - insn.getArguments().addAll(arguments.subList(1, arguments.size())); + insn.setArguments(arguments.subList(1, arguments.size()).toArray(new Variable[0])); } else { - insn.getArguments().addAll(arguments); + insn.setArguments(arguments.toArray(new Variable[0])); } addInstruction(insn); diff --git a/core/src/main/java/org/teavm/model/util/InstructionCopyReader.java b/core/src/main/java/org/teavm/model/util/InstructionCopyReader.java index fe1cce9b7..7a3d024a9 100644 --- a/core/src/main/java/org/teavm/model/util/InstructionCopyReader.java +++ b/core/src/main/java/org/teavm/model/util/InstructionCopyReader.java @@ -411,9 +411,11 @@ public class InstructionCopyReader implements InstructionReader { insnCopy.setType(type); insnCopy.setInstance(instance != null ? copyVar(instance) : null); insnCopy.setReceiver(receiver != null ? copyVar(receiver) : null); - for (VariableReader arg : arguments) { - insnCopy.getArguments().add(copyVar(arg)); + Variable[] argsCopy = new Variable[arguments.size()]; + for (int i = 0; i < argsCopy.length; ++i) { + argsCopy[i] = copyVar(arguments.get(i)); } + insnCopy.setArguments(argsCopy); copy = insnCopy; copy.setLocation(location); } diff --git a/core/src/main/java/org/teavm/model/util/InstructionVariableMapper.java b/core/src/main/java/org/teavm/model/util/InstructionVariableMapper.java index 277866939..32dad3d31 100644 --- a/core/src/main/java/org/teavm/model/util/InstructionVariableMapper.java +++ b/core/src/main/java/org/teavm/model/util/InstructionVariableMapper.java @@ -267,9 +267,7 @@ public class InstructionVariableMapper extends AbstractInstructionVisitor { if (insn.getInstance() != null) { insn.setInstance(map(insn.getInstance())); } - for (int i = 0; i < insn.getArguments().size(); ++i) { - insn.getArguments().set(i, map(insn.getArguments().get(i))); - } + insn.replaceArguments(this::map); } @Override diff --git a/core/src/main/java/org/teavm/model/util/MissingItemsProcessor.java b/core/src/main/java/org/teavm/model/util/MissingItemsProcessor.java index 1ec9f645f..abc64f8ae 100644 --- a/core/src/main/java/org/teavm/model/util/MissingItemsProcessor.java +++ b/core/src/main/java/org/teavm/model/util/MissingItemsProcessor.java @@ -117,7 +117,7 @@ public class MissingItemsProcessor { initExceptionInsn.setMethod(new MethodReference(exceptionName, "", ValueType.object("java.lang.String"), ValueType.VOID)); initExceptionInsn.setType(InvocationType.SPECIAL); - initExceptionInsn.getArguments().add(constVar); + initExceptionInsn.setArguments(constVar); initExceptionInsn.setLocation(location); instructionsToAdd.add(initExceptionInsn); diff --git a/core/src/main/java/org/teavm/model/util/PhiUpdater.java b/core/src/main/java/org/teavm/model/util/PhiUpdater.java index 530271027..ba21ded67 100644 --- a/core/src/main/java/org/teavm/model/util/PhiUpdater.java +++ b/core/src/main/java/org/teavm/model/util/PhiUpdater.java @@ -686,10 +686,7 @@ public class PhiUpdater { @Override public void visit(InvokeInstruction insn) { - List args = insn.getArguments(); - for (int i = 0; i < args.size(); ++i) { - args.set(i, use(args.get(i))); - } + insn.replaceArguments(v -> use(v)); if (insn.getInstance() != null) { insn.setInstance(use(insn.getInstance())); } diff --git a/core/src/main/java/org/teavm/parsing/ProgramParser.java b/core/src/main/java/org/teavm/parsing/ProgramParser.java index 27066d515..4647de2b7 100644 --- a/core/src/main/java/org/teavm/parsing/ProgramParser.java +++ b/core/src/main/java/org/teavm/parsing/ProgramParser.java @@ -657,7 +657,7 @@ public class ProgramParser { if (result >= 0) { insn.setReceiver(getVariable(result)); } - insn.getArguments().addAll(Arrays.asList(args)); + insn.setArguments(args); addInstruction(insn); } else { InvokeInstruction insn = new InvokeInstruction(); @@ -671,7 +671,7 @@ public class ProgramParser { insn.setReceiver(getVariable(result)); } insn.setInstance(getVariable(instance)); - insn.getArguments().addAll(Arrays.asList(args)); + insn.setArguments(args); addInstruction(insn); } break; diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java index 0c274f821..f0e702957 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java @@ -329,7 +329,12 @@ class JSClassProcessor { if (method.getProgram() != null && method.getProgram().basicBlockCount() > 0) { invoke.setMethod(new MethodReference(method.getOwnerName(), method.getName() + "$static", getStaticSignature(method.getReference()))); - invoke.getArguments().add(0, invoke.getInstance()); + Variable[] newArguments = new Variable[invoke.getArguments().size() + 1]; + newArguments[0] = invoke.getInstance(); + for (int i = 0; i < invoke.getArguments().size(); ++i) { + newArguments[i + 1] = invoke.getArguments().get(i); + } + invoke.setArguments(newArguments); invoke.setInstance(null); } invoke.setType(InvocationType.SPECIAL); @@ -369,16 +374,18 @@ class JSClassProcessor { newInvoke.setType(InvocationType.SPECIAL); newInvoke.setReceiver(result); newInvoke.setLocation(invoke.getLocation()); + List newArgs = new ArrayList<>(); if (invoke.getInstance() != null) { Variable arg = marshaller.wrapArgument(callLocation, invoke.getInstance(), ValueType.object(method.getOwnerName()), false); - newInvoke.getArguments().add(arg); + newArgs.add(arg); } for (int i = 0; i < invoke.getArguments().size(); ++i) { Variable arg = marshaller.wrapArgument(callLocation, invoke.getArguments().get(i), method.parameterType(i), byRefParams[i]); - newInvoke.getArguments().add(arg); + newArgs.add(arg); } + newInvoke.setArguments(newArgs.toArray(new Variable[0])); replacement.add(newInvoke); if (result != null) { result = marshaller.unwrapReturnValue(callLocation, result, method.getResultType()); @@ -501,15 +508,17 @@ class JSClassProcessor { newInvoke.setMethod(JSMethods.invoke(method.parameterCount())); newInvoke.setType(InvocationType.SPECIAL); newInvoke.setReceiver(result); - newInvoke.getArguments().add(invoke.getInstance()); - newInvoke.getArguments().add(marshaller.addStringWrap(marshaller.addString(name, invoke.getLocation()), + List newArguments = new ArrayList<>(); + newArguments.add(invoke.getInstance()); + newArguments.add(marshaller.addStringWrap(marshaller.addString(name, invoke.getLocation()), invoke.getLocation())); newInvoke.setLocation(invoke.getLocation()); for (int i = 0; i < invoke.getArguments().size(); ++i) { Variable arg = marshaller.wrapArgument(callLocation, invoke.getArguments().get(i), method.parameterType(i), byRefParams[i]); - newInvoke.getArguments().add(arg); + newArguments.add(arg); } + newInvoke.setArguments(newArguments.toArray(new Variable[0])); replacement.add(newInvoke); if (result != null) { result = marshaller.unwrapReturnValue(callLocation, result, method.getResultType()); @@ -661,10 +670,12 @@ class JSClassProcessor { insn.setInstance(marshaller.unwrapReturnValue(location, program.variableAt(paramIndex++), ValueType.object(calleeRef.getClassName()))); } + Variable[] args = new Variable[callee.parameterCount()]; for (int i = 0; i < callee.parameterCount(); ++i) { - insn.getArguments().add(marshaller.unwrapReturnValue(location, program.variableAt(paramIndex++), - callee.parameterType(i))); + args[i] = marshaller.unwrapReturnValue(location, program.variableAt(paramIndex++), + callee.parameterType(i)); } + insn.setArguments(args); if (callee.getResultType() != ValueType.VOID) { insn.setReceiver(program.createVariable()); } @@ -691,8 +702,7 @@ class JSClassProcessor { insn.setType(InvocationType.SPECIAL); insn.setMethod(JSMethods.GET); insn.setReceiver(receiver); - insn.getArguments().add(instance); - insn.getArguments().add(nameVar); + insn.setArguments(instance, nameVar); insn.setLocation(location); replacement.add(insn); } @@ -702,9 +712,7 @@ class JSClassProcessor { InvokeInstruction insn = new InvokeInstruction(); insn.setType(InvocationType.SPECIAL); insn.setMethod(JSMethods.SET); - insn.getArguments().add(instance); - insn.getArguments().add(nameVar); - insn.getArguments().add(value); + insn.setArguments(instance, nameVar, value); insn.setLocation(location); replacement.add(insn); } @@ -714,8 +722,7 @@ class JSClassProcessor { insn.setType(InvocationType.SPECIAL); insn.setMethod(JSMethods.GET); insn.setReceiver(receiver); - insn.getArguments().add(array); - insn.getArguments().add(index); + insn.setArguments(array, index); insn.setLocation(location); replacement.add(insn); } @@ -724,9 +731,7 @@ class JSClassProcessor { InvokeInstruction insn = new InvokeInstruction(); insn.setType(InvocationType.SPECIAL); insn.setMethod(JSMethods.SET); - insn.getArguments().add(array); - insn.getArguments().add(index); - insn.getArguments().add(value); + insn.setArguments(array, index, value); insn.setLocation(location); replacement.add(insn); } diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSObjectClassTransformer.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSObjectClassTransformer.java index b0a3ae458..c6aeb0f41 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSObjectClassTransformer.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSObjectClassTransformer.java @@ -125,15 +125,14 @@ class JSObjectClassTransformer implements ClassHolderTransformer { JSValueMarshaller marshaller = new JSValueMarshaller(diagnostics, typeHelper, hierarchy.getClassSource(), program, marshallInstructions); - List variablesToPass = new ArrayList<>(); + Variable[] variablesToPass = new Variable[method.parameterCount()]; for (int i = 0; i < method.parameterCount(); ++i) { - variablesToPass.add(program.createVariable()); + variablesToPass[i] = program.createVariable(); } for (int i = 0; i < method.parameterCount(); ++i) { - Variable var = marshaller.unwrapReturnValue(callLocation, variablesToPass.get(i), + variablesToPass[i] = marshaller.unwrapReturnValue(callLocation, variablesToPass[i], method.parameterType(i)); - variablesToPass.set(i, var); } basicBlock.addAll(marshallInstructions); @@ -143,7 +142,7 @@ class JSObjectClassTransformer implements ClassHolderTransformer { invocation.setType(InvocationType.VIRTUAL); invocation.setInstance(program.variableAt(0)); invocation.setMethod(methodRef); - invocation.getArguments().addAll(variablesToPass); + invocation.setArguments(variablesToPass); basicBlock.add(invocation); ExitInstruction exit = new ExitInstruction(); diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSValueMarshaller.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSValueMarshaller.java index 8efee5de0..39c9042fa 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSValueMarshaller.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSValueMarshaller.java @@ -15,6 +15,7 @@ */ package org.teavm.jso.impl; +import java.util.ArrayList; import java.util.List; import java.util.function.Function; import org.teavm.diagnostics.Diagnostics; @@ -90,8 +91,7 @@ class JSValueMarshaller { insn.setType(InvocationType.SPECIAL); insn.setMethod(JSMethods.FUNCTION); insn.setReceiver(functor); - insn.getArguments().add(var); - insn.getArguments().add(nameVar); + insn.setArguments(var, nameVar); insn.setLocation(location.getSourceLocation()); replacement.add(insn); return functor; @@ -103,7 +103,7 @@ class JSValueMarshaller { insn.setMethod(JSMethods.ARRAY_DATA); insn.setReceiver(program.createVariable()); insn.setType(InvocationType.SPECIAL); - insn.getArguments().add(var); + insn.setArguments(var); replacement.add(insn); return insn.getReceiver(); } @@ -127,7 +127,7 @@ class JSValueMarshaller { InvokeInstruction insn = new InvokeInstruction(); insn.setMethod(referenceCache.getCached(new MethodReference(JS.class.getName(), "wrap", getWrappedType(type), getWrapperType(type)))); - insn.getArguments().add(var); + insn.setArguments(var); insn.setReceiver(result); insn.setType(InvocationType.SPECIAL); insn.setLocation(location); @@ -145,7 +145,7 @@ class JSValueMarshaller { while (--degree > 1) { insn = new InvokeInstruction(); insn.setMethod(JSMethods.ARRAY_MAPPER); - insn.getArguments().add(function); + insn.setArguments(function); function = program.createVariable(); insn.setReceiver(function); insn.setType(InvocationType.SPECIAL); @@ -156,8 +156,7 @@ class JSValueMarshaller { insn = new InvokeInstruction(); insn.setMethod(referenceCache.getCached(new MethodReference(JS.class.getName(), "map", getWrappedType(type), ValueType.parse(Function.class), getWrapperType(type)))); - insn.getArguments().add(var); - insn.getArguments().add(function); + insn.setArguments(var, function); insn.setReceiver(result); insn.setType(InvocationType.SPECIAL); insn.setLocation(location); @@ -309,6 +308,7 @@ class JSValueMarshaller { InvokeInstruction insn = new InvokeInstruction(); insn.setMethod(singleDimensionArrayUnwrapper(type)); insn.setType(InvocationType.SPECIAL); + List args = new ArrayList<>(); if (insn.getMethod().parameterCount() == 2) { Variable cls = program.createVariable(); @@ -317,10 +317,11 @@ class JSValueMarshaller { clsInsn.setLocation(location.getSourceLocation()); clsInsn.setReceiver(cls); replacement.add(clsInsn); - insn.getArguments().add(cls); + args.add(cls); } - insn.getArguments().add(var); + args.add(var); + insn.setArguments(args.toArray(new Variable[0])); insn.setReceiver(result); replacement.add(insn); return result; @@ -340,7 +341,7 @@ class JSValueMarshaller { clsInsn.setLocation(location.getSourceLocation()); clsInsn.setReceiver(cls); replacement.add(clsInsn); - insn.getArguments().add(cls); + insn.setArguments(cls); } insn.setReceiver(function); @@ -359,8 +360,7 @@ class JSValueMarshaller { insn = new InvokeInstruction(); insn.setMethod(JSMethods.ARRAY_UNMAPPER); insn.setType(InvocationType.SPECIAL); - insn.getArguments().add(cls); - insn.getArguments().add(function); + insn.setArguments(cls, function); function = program.createVariable(); insn.setReceiver(function); replacement.add(insn); @@ -375,9 +375,7 @@ class JSValueMarshaller { insn = new InvokeInstruction(); insn.setMethod(JSMethods.UNMAP_ARRAY); - insn.getArguments().add(cls); - insn.getArguments().add(var); - insn.getArguments().add(function); + insn.setArguments(cls, var, function); insn.setReceiver(var); insn.setType(InvocationType.SPECIAL); insn.setLocation(location.getSourceLocation()); @@ -454,7 +452,7 @@ class JSValueMarshaller { InvokeInstruction insn = new InvokeInstruction(); insn.setMethod(referenceCache.getCached(referenceCache.getCached(new MethodReference( JS.class.getName(), methodName, argType, resultType)))); - insn.getArguments().add(var); + insn.setArguments(var); insn.setReceiver(result); insn.setType(InvocationType.SPECIAL); insn.setLocation(location); @@ -476,8 +474,7 @@ class JSValueMarshaller { insn.setType(InvocationType.SPECIAL); insn.setMethod(JSMethods.FUNCTION_AS_OBJECT); insn.setReceiver(functor); - insn.getArguments().add(var); - insn.getArguments().add(nameVar); + insn.setArguments(var, nameVar); insn.setLocation(location.getSourceLocation()); replacement.add(insn); return functor; diff --git a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/CompositeMethodGenerator.java b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/CompositeMethodGenerator.java index 054c7d0c5..b3375e9ed 100644 --- a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/CompositeMethodGenerator.java +++ b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/CompositeMethodGenerator.java @@ -406,7 +406,7 @@ public class CompositeMethodGenerator { InvokeInstruction insn = new InvokeInstruction(); insn.setMethod(new MethodReference(wrapper, "valueOf", primitive, wrapper)); insn.setType(InvocationType.SPECIAL); - insn.getArguments().add(var); + insn.setArguments(var); var = program.createVariable(); insn.setReceiver(var); add(insn); @@ -851,7 +851,7 @@ public class CompositeMethodGenerator { insn.setReceiver(var(receiver)); insn.setMethod(method); insn.setType(type); - insn.getArguments().addAll(arguments.stream().map(this::var).collect(Collectors.toList())); + insn.setArguments(arguments.stream().map(this::var).toArray(Variable[]::new)); add(insn); } @@ -932,7 +932,7 @@ public class CompositeMethodGenerator { insn.setType(Modifier.isStatic(reflectMethod.getModifiers()) ? InvocationType.SPECIAL : InvocationType.VIRTUAL); insn.setMethod(reflectMethod.method.getReference()); - emitArguments(var(arguments.get(1)), reflectMethod, insn.getArguments()); + insn.setArguments(emitArguments(var(arguments.get(1)), reflectMethod)); add(insn); if (receiver != null) { @@ -964,7 +964,7 @@ public class CompositeMethodGenerator { insn.setInstance(constructInsn.getReceiver()); insn.setType(InvocationType.SPECIAL); insn.setMethod(reflectMethod.method.getReference()); - emitArguments(var(arguments.get(0)), reflectMethod, insn.getArguments()); + insn.setArguments(emitArguments(var(arguments.get(0)), reflectMethod)); add(insn); return true; @@ -1054,14 +1054,14 @@ public class CompositeMethodGenerator { } } - private void emitArguments(Variable argumentsVar, ReflectMethodImpl reflectMethod, - List arguments) { + private Variable[] emitArguments(Variable argumentsVar, ReflectMethodImpl reflectMethod) { UnwrapArrayInstruction unwrapInsn = new UnwrapArrayInstruction(ArrayElementType.OBJECT); unwrapInsn.setArray(argumentsVar); unwrapInsn.setReceiver(program.createVariable()); add(unwrapInsn); argumentsVar = unwrapInsn.getReceiver(); + Variable[] arguments = new Variable[reflectMethod.getParameterCount()]; for (int i = 0; i < reflectMethod.getParameterCount(); ++i) { IntegerConstantInstruction indexInsn = new IntegerConstantInstruction(); indexInsn.setConstant(i); @@ -1074,9 +1074,10 @@ public class CompositeMethodGenerator { extractArgInsn.setReceiver(program.createVariable()); add(extractArgInsn); - arguments.add(unbox(extractArgInsn.getReceiver(), - reflectMethod.method.parameterType(i))); + arguments[i] = unbox(extractArgInsn.getReceiver(), reflectMethod.method.parameterType(i)); } + + return arguments; } private Variable unwrapArray(ValueType type, Variable array) { diff --git a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/ProxyVariableContext.java b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/ProxyVariableContext.java index 12e821bca..d91882753 100644 --- a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/ProxyVariableContext.java +++ b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/ProxyVariableContext.java @@ -130,9 +130,11 @@ public class ProxyVariableContext extends VariableContext { initInsn.setInstance(constructInsn.getReceiver()); initInsn.setMethod(ctor.getReference()); initInsn.setType(InvocationType.SPECIAL); + Variable[] initArgs = new Variable[capturedValues.size()]; for (int i = 0; i < capturedValues.size(); ++i) { - initInsn.getArguments().add(capturedValues.get(i).value); + initArgs[i] = capturedValues.get(i).value; } + initInsn.setArguments(initArgs); generator.add(initInsn); return constructInsn.getReceiver(); diff --git a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/UsageGenerator.java b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/UsageGenerator.java index 2b89bfd5d..d0f2def74 100644 --- a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/UsageGenerator.java +++ b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/UsageGenerator.java @@ -333,7 +333,7 @@ class UsageGenerator { InvokeInstruction insn = new InvokeInstruction(); insn.setType(InvocationType.SPECIAL); insn.setMethod(new MethodReference(boxed, "valueOf", primitive, boxed)); - insn.getArguments().add(var); + insn.setArguments(var); var = program.createVariable(); insn.setReceiver(var); diff --git a/platform/src/main/java/org/teavm/platform/plugin/ResourceProgramTransformer.java b/platform/src/main/java/org/teavm/platform/plugin/ResourceProgramTransformer.java index 4b0addd7d..a0080483c 100644 --- a/platform/src/main/java/org/teavm/platform/plugin/ResourceProgramTransformer.java +++ b/platform/src/main/java/org/teavm/platform/plugin/ResourceProgramTransformer.java @@ -80,8 +80,12 @@ class ResourceProgramTransformer { System.arraycopy(method.getDescriptor().getSignature(), 0, types, 1, method.getDescriptor().parameterCount() + 1); accessInsn.setMethod(new MethodReference(ResourceAccessor.class.getName(), method.getName(), types)); - accessInsn.getArguments().add(insn.getInstance()); - accessInsn.getArguments().addAll(insn.getArguments()); + Variable[] accessArgs = new Variable[insn.getArguments().size() + 1]; + accessArgs[0] = insn.getInstance(); + for (int i = 0; i < insn.getArguments().size(); ++i) { + accessArgs[i + 1] = insn.getArguments().get(i); + } + accessInsn.setArguments(accessArgs); accessInsn.setReceiver(insn.getReceiver()); return Arrays.asList(accessInsn); } @@ -111,13 +115,13 @@ class ResourceProgramTransformer { InvokeInstruction keysInsn = new InvokeInstruction(); keysInsn.setType(InvocationType.SPECIAL); keysInsn.setMethod(KEYS); - keysInsn.getArguments().add(insn.getInstance()); + keysInsn.setArguments(insn.getInstance()); keysInsn.setReceiver(tmp); InvokeInstruction transformInsn = new InvokeInstruction(); transformInsn.setType(InvocationType.SPECIAL); transformInsn.setMethod(KEYS_TO_STRINGS); - transformInsn.getArguments().add(tmp); + transformInsn.setArguments(tmp); transformInsn.setReceiver(insn.getReceiver()); return Arrays.asList(keysInsn, transformInsn); @@ -161,7 +165,7 @@ class ResourceProgramTransformer { InvokeInstruction castInvoke = new InvokeInstruction(); castInvoke.setType(InvocationType.SPECIAL); castInvoke.setMethod(CAST_TO_STRING); - castInvoke.getArguments().add(resultVar); + castInvoke.setArguments(resultVar); castInvoke.setReceiver(insn.getReceiver()); instructions.add(castInvoke); return instructions; @@ -191,8 +195,7 @@ class ResourceProgramTransformer { InvokeInstruction accessorInvoke = new InvokeInstruction(); accessorInvoke.setType(InvocationType.SPECIAL); accessorInvoke.setMethod(GET_PROPERTY); - accessorInvoke.getArguments().add(insn.getInstance()); - accessorInvoke.getArguments().add(nameVar); + accessorInvoke.setArguments(insn.getInstance(), nameVar); accessorInvoke.setReceiver(resultVar); instructions.add(accessorInvoke); } @@ -208,7 +211,7 @@ class ResourceProgramTransformer { + primitiveCapitalized.substring(1); castInvoke.setMethod(new MethodReference(ResourceAccessor.class, "castTo" + primitiveCapitalized, Object.class, primitive)); - castInvoke.getArguments().add(resultVar); + castInvoke.setArguments(resultVar); castInvoke.setReceiver(insn.getReceiver()); instructions.add(castInvoke); } @@ -247,7 +250,7 @@ class ResourceProgramTransformer { InvokeInstruction castInvoke = new InvokeInstruction(); castInvoke.setType(InvocationType.SPECIAL); castInvoke.setMethod(CAST_FROM_STRING); - castInvoke.getArguments().add(insn.getArguments().get(0)); + castInvoke.setArguments(insn.getArguments().get(0)); castInvoke.setReceiver(castVar); instructions.add(castInvoke); setProperty(insn, property, instructions, castVar); @@ -272,9 +275,7 @@ class ResourceProgramTransformer { InvokeInstruction accessorInvoke = new InvokeInstruction(); accessorInvoke.setType(InvocationType.SPECIAL); accessorInvoke.setMethod(PUT); - accessorInvoke.getArguments().add(insn.getInstance()); - accessorInvoke.getArguments().add(nameVar); - accessorInvoke.getArguments().add(valueVar); + accessorInvoke.setArguments(insn.getInstance(), nameVar, valueVar); instructions.add(accessorInvoke); } @@ -288,7 +289,7 @@ class ResourceProgramTransformer { + primitiveCapitalized.substring(1); castInvoke.setMethod(new MethodReference(ResourceAccessor.class, "castFrom" + primitiveCapitalized, primitive, Object.class)); - castInvoke.getArguments().add(insn.getArguments().get(0)); + castInvoke.setArguments(insn.getArguments().get(0)); castInvoke.setReceiver(castVar); instructions.add(castInvoke); setProperty(insn, property, instructions, castVar); diff --git a/platform/src/main/java/org/teavm/platform/plugin/StringAmplifierTransformer.java b/platform/src/main/java/org/teavm/platform/plugin/StringAmplifierTransformer.java index 67385a341..09db7726a 100644 --- a/platform/src/main/java/org/teavm/platform/plugin/StringAmplifierTransformer.java +++ b/platform/src/main/java/org/teavm/platform/plugin/StringAmplifierTransformer.java @@ -60,7 +60,7 @@ public class StringAmplifierTransformer implements ClassHolderTransformer { amplifyInstruction.setMethod(new MethodReference(StringAmplifier.class, "amplify", String.class, String.class)); amplifyInstruction.setType(InvocationType.SPECIAL); - amplifyInstruction.getArguments().add(var); + amplifyInstruction.setArguments(var); amplifyInstruction.setReceiver(invoke.getReceiver()); amplifyInstruction.setLocation(invoke.getLocation());