From f3c64ee29f9094bdc87a4fe3615c21f9c65fab51 Mon Sep 17 00:00:00 2001 From: Greg Brail Date: Mon, 12 Aug 2024 15:24:37 -0700 Subject: [PATCH] Remove obsolete "ObjArray" class Depending on context, replace this venerable class with either ArrayList or ArrayDeque. --- .../javascript/tools/debugger/Dim.java | 14 +- .../mozilla/classfile/ClassFileWriter.java | 16 +- .../org/mozilla/javascript/CodeGenerator.java | 3 +- .../java/org/mozilla/javascript/Context.java | 3 +- .../mozilla/javascript/ImporterTopLevel.java | 11 +- .../org/mozilla/javascript/Interpreter.java | 3 +- .../org/mozilla/javascript/JavaMembers.java | 11 +- .../mozilla/javascript/NodeTransformer.java | 31 +- .../java/org/mozilla/javascript/ObjArray.java | 408 ------------------ .../mozilla/javascript/optimizer/Block.java | 4 +- .../mozilla/javascript/optimizer/Codegen.java | 10 +- .../javascript/optimizer/OptTransformer.java | 8 +- .../javascript/optimizer/Optimizer.java | 7 +- 13 files changed, 68 insertions(+), 461 deletions(-) delete mode 100644 rhino/src/main/java/org/mozilla/javascript/ObjArray.java diff --git a/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Dim.java b/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Dim.java index a1ec46c3b3..7749dd13aa 100644 --- a/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Dim.java +++ b/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Dim.java @@ -12,8 +12,10 @@ import java.io.InputStreamReader; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.mozilla.javascript.Callable; import org.mozilla.javascript.Context; @@ -22,7 +24,6 @@ import org.mozilla.javascript.ImporterTopLevel; import org.mozilla.javascript.Kit; import org.mozilla.javascript.NativeCall; -import org.mozilla.javascript.ObjArray; import org.mozilla.javascript.ScriptRuntime; import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.ScriptableObject; @@ -388,7 +389,7 @@ private String getNormalizedUrl(DebuggableScript fnOrScript) { /** Returns an array of all functions in the given script. */ private static DebuggableScript[] getAllFunctions(DebuggableScript function) { - ObjArray functions = new ObjArray(); + ArrayList functions = new ArrayList<>(); collectFunctions_r(function, functions); DebuggableScript[] result = new DebuggableScript[functions.size()]; functions.toArray(result); @@ -396,7 +397,8 @@ private static DebuggableScript[] getAllFunctions(DebuggableScript function) { } /** Helper function for {@link #getAllFunctions(DebuggableScript)}. */ - private static void collectFunctions_r(DebuggableScript function, ObjArray array) { + private static void collectFunctions_r( + DebuggableScript function, List array) { array.add(function); for (int i = 0; i != function.getFunctionCount(); ++i) { collectFunctions_r(function.getFunction(i), array); @@ -912,7 +914,7 @@ public void handleCompilationDone(Context cx, DebuggableScript fnOrScript, Strin public static class ContextData { /** The stack frames. */ - private ObjArray frameStack = new ObjArray(); + private ArrayList frameStack = new ArrayList<>(); /** Whether the debugger should break at the next line in this context. */ private boolean breakNextLine; @@ -947,12 +949,12 @@ public StackFrame getFrame(int frameNumber) { /** Pushes a stack frame on to the stack. */ private void pushFrame(StackFrame frame) { - frameStack.push(frame); + frameStack.add(frame); } /** Pops a stack frame from the stack. */ private void popFrame() { - frameStack.pop(); + frameStack.remove(frameStack.size() - 1); } } diff --git a/rhino/src/main/java/org/mozilla/classfile/ClassFileWriter.java b/rhino/src/main/java/org/mozilla/classfile/ClassFileWriter.java index de78d70194..c0dfa16326 100644 --- a/rhino/src/main/java/org/mozilla/classfile/ClassFileWriter.java +++ b/rhino/src/main/java/org/mozilla/classfile/ClassFileWriter.java @@ -9,9 +9,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; import java.util.Arrays; import org.mozilla.javascript.Kit; -import org.mozilla.javascript.ObjArray; import org.mozilla.javascript.UintMap; /** @@ -211,7 +211,7 @@ public void addVariableDescriptor(String name, String type, int startPC, int reg int descriptorIndex = itsConstantPool.addUtf8(type); int[] chunk = {nameIndex, descriptorIndex, startPC, register}; if (itsVarDescriptors == null) { - itsVarDescriptors = new ObjArray(); + itsVarDescriptors = new ArrayList<>(); } itsVarDescriptors.add(chunk); } @@ -852,7 +852,7 @@ public void addInvokeDynamic( BootstrapEntry bsmEntry = new BootstrapEntry(bsm, bsmArgs); if (itsBootstrapMethods == null) { - itsBootstrapMethods = new ObjArray(); + itsBootstrapMethods = new ArrayList<>(); } int bootstrapIndex = itsBootstrapMethods.indexOf(bsmEntry); if (bootstrapIndex == -1) { @@ -4487,9 +4487,9 @@ public String toString() { private int itsMaxStack; private int itsMaxLocals; - private ObjArray itsMethods = new ObjArray(); - private ObjArray itsFields = new ObjArray(); - private ObjArray itsInterfaces = new ObjArray(); + private ArrayList itsMethods = new ArrayList<>(); + private ArrayList itsFields = new ArrayList<>(); + private ArrayList itsInterfaces = new ArrayList<>(); private int itsFlags; private int itsThisClassIndex; @@ -4504,8 +4504,8 @@ public String toString() { private static final int MIN_FIXUP_TABLE_SIZE = 40; private long[] itsFixupTable; private int itsFixupTableTop; - private ObjArray itsVarDescriptors; - private ObjArray itsBootstrapMethods; + private ArrayList itsVarDescriptors; + private ArrayList itsBootstrapMethods; private int itsBootstrapMethodsLength = 0; private char[] tmpCharBuffer = new char[64]; diff --git a/rhino/src/main/java/org/mozilla/javascript/CodeGenerator.java b/rhino/src/main/java/org/mozilla/javascript/CodeGenerator.java index d78bad8300..e2dbb99e25 100644 --- a/rhino/src/main/java/org/mozilla/javascript/CodeGenerator.java +++ b/rhino/src/main/java/org/mozilla/javascript/CodeGenerator.java @@ -7,6 +7,7 @@ package org.mozilla.javascript; import java.math.BigInteger; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.mozilla.javascript.ast.AstNode; @@ -47,7 +48,7 @@ class CodeGenerator extends Icode { // fixupTable[i] = (label_index << 32) | fixup_site private long[] fixupTable; private int fixupTableTop; - private ObjArray literalIds = new ObjArray(); + private ArrayList literalIds = new ArrayList<>(); private int exceptionTableTop; diff --git a/rhino/src/main/java/org/mozilla/javascript/Context.java b/rhino/src/main/java/org/mozilla/javascript/Context.java index 09a70e25dd..09bab5ef8f 100644 --- a/rhino/src/main/java/org/mozilla/javascript/Context.java +++ b/rhino/src/main/java/org/mozilla/javascript/Context.java @@ -19,6 +19,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayDeque; +import java.util.Deque; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; @@ -2712,7 +2713,7 @@ public static boolean isCurrentContextStrict() { // For the interpreter to store information about previous invocations // interpreter invocations - ObjArray previousInterpreterInvocations; + Deque previousInterpreterInvocations; // For instruction counting (interpreter only) int instructionCount; diff --git a/rhino/src/main/java/org/mozilla/javascript/ImporterTopLevel.java b/rhino/src/main/java/org/mozilla/javascript/ImporterTopLevel.java index fffd2e15a3..458f41a1df 100644 --- a/rhino/src/main/java/org/mozilla/javascript/ImporterTopLevel.java +++ b/rhino/src/main/java/org/mozilla/javascript/ImporterTopLevel.java @@ -8,6 +8,8 @@ package org.mozilla.javascript; +import java.util.ArrayList; + /** * Class ImporterTopLevel * @@ -129,7 +131,9 @@ private static Object[] getNativeJavaPackages(Scriptable scope) { synchronized (scope) { if (scope instanceof ScriptableObject) { ScriptableObject so = (ScriptableObject) scope; - ObjArray importedPackages = (ObjArray) so.getAssociatedValue(AKEY); + @SuppressWarnings("unchecked") + ArrayList importedPackages = + (ArrayList) so.getAssociatedValue(AKEY); if (importedPackages != null) { return importedPackages.toArray(); } @@ -194,9 +198,10 @@ private static void importPackage(ScriptableObject scope, NativeJavaPackage pkg) return; } synchronized (scope) { - ObjArray importedPackages = (ObjArray) scope.getAssociatedValue(AKEY); + @SuppressWarnings("unchecked") + ArrayList importedPackages = (ArrayList) scope.getAssociatedValue(AKEY); if (importedPackages == null) { - importedPackages = new ObjArray(); + importedPackages = new ArrayList<>(); scope.associateValue(AKEY, importedPackages); } for (int j = 0; j != importedPackages.size(); j++) { diff --git a/rhino/src/main/java/org/mozilla/javascript/Interpreter.java b/rhino/src/main/java/org/mozilla/javascript/Interpreter.java index b2b9d8d93f..9b0d0dc6d8 100644 --- a/rhino/src/main/java/org/mozilla/javascript/Interpreter.java +++ b/rhino/src/main/java/org/mozilla/javascript/Interpreter.java @@ -11,6 +11,7 @@ import java.io.PrintStream; import java.io.Serializable; import java.math.BigInteger; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -1179,7 +1180,7 @@ private static Object interpretLoop(Context cx, CallFrame frame, Object throwabl // save the top frame from the previous interpretLoop // invocation on the stack if (cx.previousInterpreterInvocations == null) { - cx.previousInterpreterInvocations = new ObjArray(); + cx.previousInterpreterInvocations = new ArrayDeque<>(); } cx.previousInterpreterInvocations.push(cx.lastInterpreterFrame); } diff --git a/rhino/src/main/java/org/mozilla/javascript/JavaMembers.java b/rhino/src/main/java/org/mozilla/javascript/JavaMembers.java index e315a049b4..cefb97100f 100644 --- a/rhino/src/main/java/org/mozilla/javascript/JavaMembers.java +++ b/rhino/src/main/java/org/mozilla/javascript/JavaMembers.java @@ -420,6 +420,7 @@ public int hashCode() { } } + @SuppressWarnings("unchecked") private void reflect( Context cx, Scriptable scope, boolean includeProtected, boolean includePrivate) { // We reflect methods first, because we want overloaded field/method @@ -436,14 +437,14 @@ private void reflect( if (value == null) { ht.put(name, method); } else { - ObjArray overloadedMethods; - if (value instanceof ObjArray) { - overloadedMethods = (ObjArray) value; + ArrayList overloadedMethods; + if (value instanceof ArrayList) { + overloadedMethods = (ArrayList) value; } else { if (!(value instanceof Method)) Kit.codeBug(); // value should be instance of Method as at this stage // staticMembers and members can only contain methods - overloadedMethods = new ObjArray(); + overloadedMethods = new ArrayList<>(); overloadedMethods.add(value); ht.put(name, overloadedMethods); } @@ -463,7 +464,7 @@ private void reflect( methodBoxes = new MemberBox[1]; methodBoxes[0] = new MemberBox((Method) value); } else { - ObjArray overloadedMethods = (ObjArray) value; + ArrayList overloadedMethods = (ArrayList) value; int N = overloadedMethods.size(); if (N < 2) Kit.codeBug(); methodBoxes = new MemberBox[N]; diff --git a/rhino/src/main/java/org/mozilla/javascript/NodeTransformer.java b/rhino/src/main/java/org/mozilla/javascript/NodeTransformer.java index afdeb1f89a..46c717cb99 100644 --- a/rhino/src/main/java/org/mozilla/javascript/NodeTransformer.java +++ b/rhino/src/main/java/org/mozilla/javascript/NodeTransformer.java @@ -6,7 +6,9 @@ package org.mozilla.javascript; +import java.util.ArrayDeque; import java.util.ArrayList; +import java.util.Deque; import java.util.List; import org.mozilla.javascript.ast.FunctionNode; import org.mozilla.javascript.ast.Jump; @@ -43,8 +45,8 @@ public final void transform(ScriptNode tree, boolean inStrictMode, CompilerEnvir } private void transformCompilationUnit(ScriptNode tree, boolean inStrictMode) { - loops = new ObjArray(); - loopEnds = new ObjArray(); + loops = new ArrayDeque<>(); + loopEnds = new ArrayDeque<>(); // to save against upchecks if no finally blocks are used. hasFinally = false; @@ -162,8 +164,8 @@ private void transformCompilationUnit_r( */ if (!hasFinally) break; // skip the whole mess. Node unwindBlock = null; - for (int i = loops.size() - 1; i >= 0; i--) { - Node n = (Node) loops.get(i); + // Iterate from the top of the stack (most recently inserted) and down + for (Node n : loops) { int elemtype = n.getType(); if (elemtype == Token.TRY || elemtype == Token.WITH) { Node unwind; @@ -208,15 +210,14 @@ private void transformCompilationUnit_r( Jump jumpStatement = jump.getJumpStatement(); if (jumpStatement == null) Kit.codeBug(); - for (int i = loops.size(); ; ) { - if (i == 0) { - // Parser/IRFactory ensure that break/continue - // always has a jump statement associated with it - // which should be found - throw Kit.codeBug(); - } - --i; - Node n = (Node) loops.get(i); + if (loops.isEmpty()) { + // Parser/IRFactory ensure that break/continue + // always has a jump statement associated with it + // which should be found + throw Kit.codeBug(); + } + // Iterate from the top of the stack (most recently inserted) and down + for (Node n : loops) { if (n == jumpStatement) { break; } @@ -549,7 +550,7 @@ private static Node replaceCurrent(Node parent, Node previous, Node current, Nod return replacement; } - private ObjArray loops; - private ObjArray loopEnds; + private Deque loops; + private Deque loopEnds; private boolean hasFinally; } diff --git a/rhino/src/main/java/org/mozilla/javascript/ObjArray.java b/rhino/src/main/java/org/mozilla/javascript/ObjArray.java deleted file mode 100644 index 0f7d5901c4..0000000000 --- a/rhino/src/main/java/org/mozilla/javascript/ObjArray.java +++ /dev/null @@ -1,408 +0,0 @@ -/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package org.mozilla.javascript; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -/** - * Implementation of resizable array with focus on minimizing memory usage by storing few initial - * array elements in object fields. Can also be used as a stack. - */ -public class ObjArray implements Serializable { - private static final long serialVersionUID = 4174889037736658296L; - - public ObjArray() {} - - public final boolean isSealed() { - return sealed; - } - - public final void seal() { - sealed = true; - } - - public final boolean isEmpty() { - return size == 0; - } - - public final int size() { - return size; - } - - public final void setSize(int newSize) { - if (newSize < 0) throw new IllegalArgumentException(); - if (sealed) throw onSeledMutation(); - int N = size; - if (newSize < N) { - for (int i = newSize; i != N; ++i) { - setImpl(i, null); - } - } else if (newSize > N) { - if (newSize > FIELDS_STORE_SIZE) { - ensureCapacity(newSize); - } - } - size = newSize; - } - - public final Object get(int index) { - if (!(0 <= index && index < size)) throw onInvalidIndex(index, size); - return getImpl(index); - } - - public final void set(int index, Object value) { - if (!(0 <= index && index < size)) throw onInvalidIndex(index, size); - if (sealed) throw onSeledMutation(); - setImpl(index, value); - } - - private Object getImpl(int index) { - switch (index) { - case 0: - return f0; - case 1: - return f1; - case 2: - return f2; - case 3: - return f3; - case 4: - return f4; - } - return data[index - FIELDS_STORE_SIZE]; - } - - private void setImpl(int index, Object value) { - switch (index) { - case 0: - f0 = value; - break; - case 1: - f1 = value; - break; - case 2: - f2 = value; - break; - case 3: - f3 = value; - break; - case 4: - f4 = value; - break; - default: - data[index - FIELDS_STORE_SIZE] = value; - } - } - - public int indexOf(Object obj) { - int N = size; - for (int i = 0; i != N; ++i) { - Object current = getImpl(i); - if (current == obj || (current != null && current.equals(obj))) { - return i; - } - } - return -1; - } - - public int lastIndexOf(Object obj) { - for (int i = size; i != 0; ) { - --i; - Object current = getImpl(i); - if (current == obj || (current != null && current.equals(obj))) { - return i; - } - } - return -1; - } - - public final Object peek() { - int N = size; - if (N == 0) throw onEmptyStackTopRead(); - return getImpl(N - 1); - } - - public final Object pop() { - if (sealed) throw onSeledMutation(); - int N = size; - --N; - Object top; - switch (N) { - case -1: - throw onEmptyStackTopRead(); - case 0: - top = f0; - f0 = null; - break; - case 1: - top = f1; - f1 = null; - break; - case 2: - top = f2; - f2 = null; - break; - case 3: - top = f3; - f3 = null; - break; - case 4: - top = f4; - f4 = null; - break; - default: - top = data[N - FIELDS_STORE_SIZE]; - data[N - FIELDS_STORE_SIZE] = null; - } - size = N; - return top; - } - - public final void push(Object value) { - add(value); - } - - public final void add(Object value) { - if (sealed) throw onSeledMutation(); - int N = size; - if (N >= FIELDS_STORE_SIZE) { - ensureCapacity(N + 1); - } - size = N + 1; - setImpl(N, value); - } - - public final void add(int index, Object value) { - int N = size; - if (!(0 <= index && index <= N)) throw onInvalidIndex(index, N + 1); - if (sealed) throw onSeledMutation(); - Object tmp; - switch (index) { - case 0: - if (N == 0) { - f0 = value; - break; - } - tmp = f0; - f0 = value; - value = tmp; - /* fall through */ case 1: - if (N == 1) { - f1 = value; - break; - } - tmp = f1; - f1 = value; - value = tmp; - /* fall through */ case 2: - if (N == 2) { - f2 = value; - break; - } - tmp = f2; - f2 = value; - value = tmp; - /* fall through */ case 3: - if (N == 3) { - f3 = value; - break; - } - tmp = f3; - f3 = value; - value = tmp; - /* fall through */ case 4: - if (N == 4) { - f4 = value; - break; - } - tmp = f4; - f4 = value; - value = tmp; - - index = FIELDS_STORE_SIZE; - /* fall through */ default: - ensureCapacity(N + 1); - if (index != N) { - System.arraycopy( - data, - index - FIELDS_STORE_SIZE, - data, - index - FIELDS_STORE_SIZE + 1, - N - index); - } - data[index - FIELDS_STORE_SIZE] = value; - } - size = N + 1; - } - - public final void remove(int index) { - int N = size; - if (!(0 <= index && index < N)) throw onInvalidIndex(index, N); - if (sealed) throw onSeledMutation(); - --N; - switch (index) { - case 0: - if (N == 0) { - f0 = null; - break; - } - f0 = f1; - /* fall through */ case 1: - if (N == 1) { - f1 = null; - break; - } - f1 = f2; - /* fall through */ case 2: - if (N == 2) { - f2 = null; - break; - } - f2 = f3; - /* fall through */ case 3: - if (N == 3) { - f3 = null; - break; - } - f3 = f4; - /* fall through */ case 4: - if (N == 4) { - f4 = null; - break; - } - f4 = data[0]; - - index = FIELDS_STORE_SIZE; - /* fall through */ default: - if (index != N) { - System.arraycopy( - data, - index - FIELDS_STORE_SIZE + 1, - data, - index - FIELDS_STORE_SIZE, - N - index); - } - data[N - FIELDS_STORE_SIZE] = null; - } - size = N; - } - - public final void clear() { - if (sealed) throw onSeledMutation(); - int N = size; - for (int i = 0; i != N; ++i) { - setImpl(i, null); - } - size = 0; - } - - public final Object[] toArray() { - Object[] array = new Object[size]; - toArray(array, 0); - return array; - } - - public final void toArray(Object[] array) { - toArray(array, 0); - } - - public final void toArray(Object[] array, int offset) { - int N = size; - switch (N) { - default: - System.arraycopy(data, 0, array, offset + FIELDS_STORE_SIZE, N - FIELDS_STORE_SIZE); - /* fall through */ case 5: - array[offset + 4] = f4; - /* fall through */ case 4: - array[offset + 3] = f3; - /* fall through */ case 3: - array[offset + 2] = f2; - /* fall through */ case 2: - array[offset + 1] = f1; - /* fall through */ case 1: - array[offset + 0] = f0; - /* fall through */ case 0: - break; - } - } - - private void ensureCapacity(int minimalCapacity) { - int required = minimalCapacity - FIELDS_STORE_SIZE; - if (required <= 0) throw new IllegalArgumentException(); - if (data == null) { - int alloc = FIELDS_STORE_SIZE * 2; - if (alloc < required) { - alloc = required; - } - data = new Object[alloc]; - } else { - int alloc = data.length; - if (alloc < required) { - if (alloc <= FIELDS_STORE_SIZE) { - alloc = FIELDS_STORE_SIZE * 2; - } else { - alloc *= 2; - } - if (alloc < required) { - alloc = required; - } - Object[] tmp = new Object[alloc]; - if (size > FIELDS_STORE_SIZE) { - System.arraycopy(data, 0, tmp, 0, size - FIELDS_STORE_SIZE); - } - data = tmp; - } - } - } - - private static RuntimeException onInvalidIndex(int index, int upperBound) { - // \u2209 is "NOT ELEMENT OF" - String msg = index + " \u2209 [0, " + upperBound + ')'; - throw new IndexOutOfBoundsException(msg); - } - - private static RuntimeException onEmptyStackTopRead() { - throw new RuntimeException("Empty stack"); - } - - private static RuntimeException onSeledMutation() { - throw new IllegalStateException("Attempt to modify sealed array"); - } - - private void writeObject(ObjectOutputStream os) throws IOException { - os.defaultWriteObject(); - int N = size; - for (int i = 0; i != N; ++i) { - Object obj = getImpl(i); - os.writeObject(obj); - } - } - - private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException { - is.defaultReadObject(); // It reads size - int N = size; - if (N > FIELDS_STORE_SIZE) { - data = new Object[N - FIELDS_STORE_SIZE]; - } - for (int i = 0; i != N; ++i) { - Object obj = is.readObject(); - setImpl(i, obj); - } - } - - // Number of data elements - private int size; - - private boolean sealed; - - private static final int FIELDS_STORE_SIZE = 5; - private transient Object f0, f1, f2, f3, f4; - private transient Object[] data; -} diff --git a/rhino/src/main/java/org/mozilla/javascript/optimizer/Block.java b/rhino/src/main/java/org/mozilla/javascript/optimizer/Block.java index e5f5e710d8..9c60b9c83d 100644 --- a/rhino/src/main/java/org/mozilla/javascript/optimizer/Block.java +++ b/rhino/src/main/java/org/mozilla/javascript/optimizer/Block.java @@ -6,11 +6,11 @@ import java.io.PrintWriter; import java.io.StringWriter; +import java.util.ArrayList; import java.util.BitSet; import java.util.HashMap; import java.util.Map; import org.mozilla.javascript.Node; -import org.mozilla.javascript.ObjArray; import org.mozilla.javascript.ObjToIntMap; import org.mozilla.javascript.Token; import org.mozilla.javascript.ast.Jump; @@ -114,7 +114,7 @@ static void runFlowAnalyzes(OptFunctionNode fn, Node[] statementNodes) { private static Block[] buildBlocks(Node[] statementNodes) { // a mapping from each target node to the block it begins Map theTargetBlocks = new HashMap<>(); - ObjArray theBlocks = new ObjArray(); + ArrayList theBlocks = new ArrayList<>(); // there's a block that starts at index 0 int beginNodeIndex = 0; diff --git a/rhino/src/main/java/org/mozilla/javascript/optimizer/Codegen.java b/rhino/src/main/java/org/mozilla/javascript/optimizer/Codegen.java index 02b51031e8..8bc5b85dcb 100644 --- a/rhino/src/main/java/org/mozilla/javascript/optimizer/Codegen.java +++ b/rhino/src/main/java/org/mozilla/javascript/optimizer/Codegen.java @@ -14,6 +14,7 @@ import static org.mozilla.classfile.ClassFileWriter.ACC_VOLATILE; import java.lang.reflect.Constructor; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -26,7 +27,6 @@ import org.mozilla.javascript.GeneratedClassLoader; import org.mozilla.javascript.Kit; import org.mozilla.javascript.NativeFunction; -import org.mozilla.javascript.ObjArray; import org.mozilla.javascript.ObjToIntMap; import org.mozilla.javascript.RhinoException; import org.mozilla.javascript.Script; @@ -205,7 +205,7 @@ private void transform(ScriptNode tree) { } if (possibleDirectCalls != null) { - directCallTargets = new ObjArray(); + directCallTargets = new ArrayList<>(); } OptTransformer ot = new OptTransformer(possibleDirectCalls, directCallTargets); @@ -225,7 +225,7 @@ private static void initOptFunctions_r(ScriptNode scriptOrFn) { } private void initScriptNodesData(ScriptNode scriptOrFn) { - ObjArray x = new ObjArray(); + ArrayList x = new ArrayList<>(); collectScriptNodes_r(scriptOrFn, x); int count = x.size(); @@ -238,7 +238,7 @@ private void initScriptNodesData(ScriptNode scriptOrFn) { } } - private static void collectScriptNodes_r(ScriptNode n, ObjArray x) { + private static void collectScriptNodes_r(ScriptNode n, List x) { x.add(n); int nestedCount = n.getFunctionCount(); for (int i = 0; i != nestedCount; ++i) { @@ -1322,7 +1322,7 @@ public void setMainMethodClass(String className) { private CompilerEnvirons compilerEnv; - private ObjArray directCallTargets; + private List directCallTargets; ScriptNode[] scriptOrFnNodes; private ObjToIntMap scriptOrFnIndexes; diff --git a/rhino/src/main/java/org/mozilla/javascript/optimizer/OptTransformer.java b/rhino/src/main/java/org/mozilla/javascript/optimizer/OptTransformer.java index d0c397abd6..81bae9c37c 100644 --- a/rhino/src/main/java/org/mozilla/javascript/optimizer/OptTransformer.java +++ b/rhino/src/main/java/org/mozilla/javascript/optimizer/OptTransformer.java @@ -4,11 +4,11 @@ package org.mozilla.javascript.optimizer; +import java.util.List; import java.util.Map; import org.mozilla.javascript.Kit; import org.mozilla.javascript.Node; import org.mozilla.javascript.NodeTransformer; -import org.mozilla.javascript.ObjArray; import org.mozilla.javascript.Token; import org.mozilla.javascript.ast.ScriptNode; @@ -20,7 +20,9 @@ */ class OptTransformer extends NodeTransformer { - OptTransformer(Map possibleDirectCalls, ObjArray directCallTargets) { + OptTransformer( + Map possibleDirectCalls, + List directCallTargets) { this.possibleDirectCalls = possibleDirectCalls; this.directCallTargets = directCallTargets; } @@ -100,5 +102,5 @@ private void detectDirectCall(Node node, ScriptNode tree) { } private Map possibleDirectCalls; - private ObjArray directCallTargets; + private List directCallTargets; } diff --git a/rhino/src/main/java/org/mozilla/javascript/optimizer/Optimizer.java b/rhino/src/main/java/org/mozilla/javascript/optimizer/Optimizer.java index 3ae6b147dc..9646f422dd 100644 --- a/rhino/src/main/java/org/mozilla/javascript/optimizer/Optimizer.java +++ b/rhino/src/main/java/org/mozilla/javascript/optimizer/Optimizer.java @@ -4,8 +4,9 @@ package org.mozilla.javascript.optimizer; +import java.util.ArrayList; +import java.util.List; import org.mozilla.javascript.Node; -import org.mozilla.javascript.ObjArray; import org.mozilla.javascript.Token; import org.mozilla.javascript.ast.ScriptNode; @@ -32,7 +33,7 @@ private void optimizeFunction(OptFunctionNode theFunction) { inDirectCallFunction = theFunction.isTargetOfDirectCall(); this.theFunction = theFunction; - ObjArray statementsArray = new ObjArray(); + ArrayList statementsArray = new ArrayList<>(); buildStatementList_r(theFunction.fnode, statementsArray); Node[] theStatementNodes = new Node[statementsArray.size()]; statementsArray.toArray(theStatementNodes); @@ -419,7 +420,7 @@ private void rewriteAsObjectChildren(Node n, Node child) { } } - private static void buildStatementList_r(Node node, ObjArray statements) { + private static void buildStatementList_r(Node node, List statements) { int type = node.getType(); if (type == Token.BLOCK || type == Token.LOCAL_BLOCK