I replaced Vector by ObjArray when it was used from the single thread and similarly replaced Hashatble by ObjToIntMap when it was used from the single thread to mark keys presence ignoring values. It avoids unnecessary synchronization and save memory. To simplify the replacement I added to ObjArray and ObjToIntMap few utility methods.

This commit is contained in:
igor%mir2.org 2002-04-24 21:37:36 +00:00
Родитель 787bb0a978
Коммит 0877a53dd0
24 изменённых файлов: 166 добавлений и 168 удалений

Просмотреть файл

@ -40,7 +40,6 @@
package org.mozilla.javascript;
import java.util.Vector;
import java.lang.reflect.Constructor;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
@ -252,7 +251,7 @@ public class FunctionObject extends NativeFunction implements Serializable {
static Method[] findMethods(Method[] methods, String name) {
// Usually we're just looking for a single method, so optimize
// for that case.
Vector v = null;
ObjArray v = null;
Method first = null;
for (int i=0; i < methods.length; i++) {
if (methods[i] == null)
@ -262,10 +261,10 @@ public class FunctionObject extends NativeFunction implements Serializable {
first = methods[i];
} else {
if (v == null) {
v = new Vector(5);
v.addElement(first);
v = new ObjArray(5);
v.add(first);
}
v.addElement(methods[i]);
v.add(methods[i]);
}
}
}
@ -276,7 +275,7 @@ public class FunctionObject extends NativeFunction implements Serializable {
return single;
}
Method[] result = new Method[v.size()];
v.copyInto(result);
v.toArray(result);
return result;
}

Просмотреть файл

@ -38,8 +38,6 @@
package org.mozilla.javascript;
import java.util.Vector;
/**
* Class ImporterTopLevel
*

Просмотреть файл

@ -39,7 +39,6 @@
package org.mozilla.javascript;
import java.io.*;
import java.util.Vector;
import java.util.Enumeration;
import org.mozilla.javascript.debug.*;
@ -131,12 +130,12 @@ public class Interpreter extends LabelTable {
private Object[] generateRegExpLiterals(Context cx,
Scriptable scope,
Vector regexps)
ObjArray regexps)
{
Object[] result = new Object[regexps.size()];
RegExpProxy rep = cx.getRegExpProxy();
for (int i = 0; i < regexps.size(); i++) {
Node regexp = (Node) regexps.elementAt(i);
Node regexp = (Node) regexps.get(i);
Node left = regexp.getFirstChild();
Node right = regexp.getLastChild();
result[i] = rep.newRegExp(cx, scope, left.getString(),
@ -153,12 +152,12 @@ public class Interpreter extends LabelTable {
{
itsSourceFile = (String) tree.getProp(Node.SOURCENAME_PROP);
itsData.itsSourceFile = itsSourceFile;
itsFunctionList = (Vector) tree.getProp(Node.FUNCTION_PROP);
itsFunctionList = (ObjArray) tree.getProp(Node.FUNCTION_PROP);
debugSource = (String) tree.getProp(Node.DEBUGSOURCE_PROP);
if (itsFunctionList != null)
generateNestedFunctions(scope, cx, securityDomain);
Object[] regExpLiterals = null;
Vector regexps = (Vector)tree.getProp(Node.REGEXP_PROP);
ObjArray regexps = (ObjArray)tree.getProp(Node.REGEXP_PROP);
if (regexps != null)
regExpLiterals = generateRegExpLiterals(cx, scope, regexps);
@ -185,7 +184,7 @@ public class Interpreter extends LabelTable {
{
itsNestedFunctions = new InterpretedFunction[itsFunctionList.size()];
for (short i = 0; i < itsFunctionList.size(); i++) {
FunctionNode def = (FunctionNode)itsFunctionList.elementAt(i);
FunctionNode def = (FunctionNode)itsFunctionList.get(i);
Interpreter jsi = new Interpreter();
jsi.itsSourceFile = itsSourceFile;
jsi.itsData = new InterpreterData(securityDomain,
@ -204,11 +203,11 @@ public class Interpreter extends LabelTable {
generateFunctionICode(Context cx, Scriptable scope,
FunctionNode theFunction, Object securityDomain)
{
itsFunctionList = (Vector) theFunction.getProp(Node.FUNCTION_PROP);
itsFunctionList = (ObjArray) theFunction.getProp(Node.FUNCTION_PROP);
if (itsFunctionList != null)
generateNestedFunctions(scope, cx, securityDomain);
Object[] regExpLiterals = null;
Vector regexps = (Vector)theFunction.getProp(Node.REGEXP_PROP);
ObjArray regexps = (ObjArray)theFunction.getProp(Node.REGEXP_PROP);
if (regexps != null)
regExpLiterals = generateRegExpLiterals(cx, scope, regexps);
@ -236,7 +235,7 @@ public class Interpreter extends LabelTable {
}
boolean itsInFunctionFlag;
Vector itsFunctionList;
ObjArray itsFunctionList;
InterpreterData itsData;
VariableTable itsVariableTable;
@ -353,9 +352,9 @@ public class Interpreter extends LabelTable {
to pass to the addGoto routine. (Parallels codegen here).
Seems unnecessary.
*/
Vector cases = (Vector) node.getProp(Node.CASES_PROP);
ObjArray cases = (ObjArray) node.getProp(Node.CASES_PROP);
for (int i = 0; i < cases.size(); i++) {
Node thisCase = (Node)cases.elementAt(i);
Node thisCase = (Node)cases.get(i);
Node first = thisCase.getFirstChild();
// the case expression is the firstmost child
// the rest will be generated when the case

Просмотреть файл

@ -210,8 +210,8 @@ public class JavaAdapter extends ScriptableObject {
if (scriptClassName != null)
generateEmptyCtor(cfw, adapterName, superName, scriptClassName);
Hashtable generatedOverrides = new Hashtable();
Hashtable generatedMethods = new Hashtable();
ObjToIntMap generatedOverrides = new ObjToIntMap();
ObjToIntMap generatedMethods = new ObjToIntMap();
// generate methods to satisfy all specified interfaces.
for (int i = 0; i < interfacesCount; i++) {
@ -240,12 +240,12 @@ public class JavaAdapter extends ScriptableObject {
// method/signature.
String methodName = method.getName();
String methodKey = methodName + getMethodSignature(method);
if (! generatedOverrides.containsKey(methodKey)) {
if (! generatedOverrides.has(methodKey)) {
generateMethod(cfw, adapterName, methodName,
method.getParameterTypes(),
method.getReturnType());
generatedOverrides.put(methodKey, Boolean.TRUE);
generatedMethods.put(methodName, Boolean.TRUE);
generatedOverrides.put(methodKey, 0);
generatedMethods.put(methodName, 0);
}
}
}
@ -272,12 +272,12 @@ public class JavaAdapter extends ScriptableObject {
String methodName = method.getName();
String methodSignature = getMethodSignature(method);
String methodKey = methodName + methodSignature;
if (! generatedOverrides.containsKey(methodKey)) {
if (! generatedOverrides.has(methodKey)) {
generateMethod(cfw, adapterName, methodName,
method.getParameterTypes(),
method.getReturnType());
generatedOverrides.put(methodKey, Boolean.TRUE);
generatedMethods.put(methodName, Boolean.TRUE);
generatedOverrides.put(methodKey, 0);
generatedMethods.put(methodName, 0);
}
// if a method was overridden, generate a "super$method"
// which lets the delegate call the superclass' version.
@ -298,7 +298,7 @@ public class JavaAdapter extends ScriptableObject {
if (!(ids[j] instanceof String))
continue;
String id = (String) ids[j];
if (generatedMethods.containsKey(id))
if (generatedMethods.has(id))
continue;
Object f = o.get(id, o);
int length;

Просмотреть файл

@ -36,7 +36,6 @@
*/
package org.mozilla.javascript;
import java.util.Hashtable;
/**
* This class implements the Array native object.

Просмотреть файл

@ -38,8 +38,6 @@
package org.mozilla.javascript;
import java.util.Hashtable;
/**
* This class implements the Function native object.
* See ECMA 15.3.

Просмотреть файл

@ -355,7 +355,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
Member bestFit = null;
Class[] bestFitTypes = null;
java.util.Vector ambiguousMethods = null;
ObjArray ambiguousMethods = null;
for (int i = 0; i < methodsOrCtors.length; i++) {
Member member = methodsOrCtors[i];
@ -389,8 +389,8 @@ public class NativeJavaMethod extends NativeFunction implements Function {
if (debug) printDebug("Deferring ", member, args);
// add to "ambiguity list"
if (ambiguousMethods == null)
ambiguousMethods = new java.util.Vector();
ambiguousMethods.addElement(member);
ambiguousMethods = new ObjArray();
ambiguousMethods.add(member);
}
else if (preference == PREFERENCE_FIRST_ARG) {
if (debug) printDebug("Substituting ", member, args);
@ -424,7 +424,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
// Compare ambiguous methods with best fit, in case
// the current best fit removes the ambiguities.
for (int i = ambiguousMethods.size() - 1; i >= 0 ; i--) {
Member member = (Member)ambiguousMethods.elementAt(i);
Member member = (Member)ambiguousMethods.get(i);
Class paramTypes[] = hasMethods
? ((Method) member).getParameterTypes()
: ((Constructor) member).getParameterTypes();
@ -437,11 +437,11 @@ public class NativeJavaMethod extends NativeFunction implements Function {
if (debug) printDebug("Substituting ", member, args);
bestFit = member;
bestFitTypes = paramTypes;
ambiguousMethods.removeElementAt(i);
ambiguousMethods.remove(i);
}
else if (preference == PREFERENCE_SECOND_ARG) {
if (debug) printDebug("Rejecting ", member, args);
ambiguousMethods.removeElementAt(i);
ambiguousMethods.remove(i);
}
else {
if (debug) printDebug("UNRESOLVED: ", member, args);
@ -453,13 +453,13 @@ public class NativeJavaMethod extends NativeFunction implements Function {
StringBuffer buf = new StringBuffer();
boolean isCtor = (bestFit instanceof Constructor);
ambiguousMethods.addElement(bestFit);
ambiguousMethods.add(bestFit);
for (int i = 0; i < ambiguousMethods.size(); i++) {
if (i != 0) {
buf.append(", ");
}
Member member = (Member)ambiguousMethods.elementAt(i);
Member member = (Member)ambiguousMethods.get(i);
if (!isCtor) {
Class rtnType = ((Method)member).getReturnType();
buf.append(rtnType);

Просмотреть файл

@ -36,8 +36,6 @@
package org.mozilla.javascript;
import java.util.Hashtable;
/**
* This class implements the Object native object.
* See ECMA 15.2.

Просмотреть файл

@ -38,7 +38,6 @@
package org.mozilla.javascript;
import java.lang.reflect.Method;
import java.util.Vector;
/**
* This class implements the String native object.

Просмотреть файл

@ -37,9 +37,6 @@
package org.mozilla.javascript;
import java.util.Stack;
import java.util.Vector;
/**
* This class transforms a tree to a lower-level representation for codegen.
*
@ -64,8 +61,8 @@ public class NodeTransformer {
public Node transform(Node tree, Node enclosing, TokenStream ts,
Scriptable scope)
{
loops = new Stack();
loopEnds = new Stack();
loops = new ObjArray();
loopEnds = new ObjArray();
inFunction = tree.getType() == TokenStream.FUNCTION;
if (!inFunction) {
addVariables(tree, getVariableTable(tree));
@ -117,12 +114,12 @@ public class NodeTransformer {
fnNode = (FunctionNode)
inner.transform(fnNode, tree, ts, scope);
node.putProp(Node.FUNCTION_PROP, fnNode);
Vector fns = (Vector) tree.getProp(Node.FUNCTION_PROP);
ObjArray fns = (ObjArray) tree.getProp(Node.FUNCTION_PROP);
if (fns == null) {
fns = new Vector(7);
fns = new ObjArray();
tree.putProp(Node.FUNCTION_PROP, fns);
}
fns.addElement(fnNode);
fns.add(fnNode);
}
break;
@ -134,7 +131,7 @@ public class NodeTransformer {
// check against duplicate labels...
for (int i=loops.size()-1; i >= 0; i--) {
Node n = (Node) loops.elementAt(i);
Node n = (Node) loops.get(i);
if (n.getType() == TokenStream.LABEL) {
String otherId = (String)n.getProp(Node.LABEL_PROP);
if (id.equals(otherId)) {
@ -196,7 +193,7 @@ public class NodeTransformer {
node.putProp(Node.BREAK_PROP, breakTarget);
loops.push(node);
loopEnds.push(breakTarget);
node.putProp(Node.CASES_PROP, new Vector(13));
node.putProp(Node.CASES_PROP, new ObjArray());
break;
}
@ -205,8 +202,8 @@ public class NodeTransformer {
{
Node sw = (Node) loops.peek();
if (type == TokenStream.CASE) {
Vector cases = (Vector) sw.getProp(Node.CASES_PROP);
cases.addElement(node);
ObjArray cases = (ObjArray) sw.getProp(Node.CASES_PROP);
cases.add(node);
} else {
sw.putProp(Node.DEFAULT_PROP, node);
}
@ -254,7 +251,7 @@ public class NodeTransformer {
case TokenStream.TARGET:
case TokenStream.LEAVEWITH:
if (!loopEnds.empty() && loopEnds.peek() == node) {
if (!loopEnds.isEmpty() && loopEnds.peek() == node) {
loopEnds.pop();
loops.pop();
}
@ -274,7 +271,7 @@ public class NodeTransformer {
Node parent = iterator.getCurrentParent();
for (int i=loops.size()-1; i >= 0; i--) {
Node n = (Node) loops.elementAt(i);
Node n = (Node) loops.get(i);
int elemtype = n.getType();
if (elemtype == TokenStream.TRY) {
Node jsrnode = new Node(TokenStream.JSR);
@ -305,7 +302,7 @@ public class NodeTransformer {
int i;
Node parent = iterator.getCurrentParent();
for (i=loops.size()-1; i >= 0; i--) {
Node n = (Node) loops.elementAt(i);
Node n = (Node) loops.get(i);
int elemtype = n.getType();
if (elemtype == TokenStream.WITH) {
parent.addChildBefore(new Node(TokenStream.LEAVEWITH),
@ -392,12 +389,12 @@ public class NodeTransformer {
case TokenStream.OBJECT:
{
Vector regexps = (Vector) tree.getProp(Node.REGEXP_PROP);
ObjArray regexps = (ObjArray) tree.getProp(Node.REGEXP_PROP);
if (regexps == null) {
regexps = new Vector(3);
regexps = new ObjArray();
tree.putProp(Node.REGEXP_PROP, regexps);
}
regexps.addElement(node);
regexps.add(node);
Node n = new Node(TokenStream.OBJECT);
iterator.replaceCurrent(n);
n.putProp(Node.REGEXP_PROP, node);
@ -649,7 +646,7 @@ public class NodeTransformer {
protected boolean inWithStatement() {
for (int i=loops.size()-1; i >= 0; i--) {
Node n = (Node) loops.elementAt(i);
Node n = (Node) loops.get(i);
if (n.getType() == TokenStream.WITH)
return true;
}
@ -720,8 +717,8 @@ public class NodeTransformer {
cx.reportWarning(msg, (String) prop, lineno, null, 0);
}
protected Stack loops;
protected Stack loopEnds;
protected ObjArray loops;
protected ObjArray loopEnds;
protected boolean inFunction;
protected IRFactory irFactory;
}

Просмотреть файл

@ -50,10 +50,11 @@ public class ObjArray implements Serializable {
minimalAllocation = 8;
}
public ObjArray(int initialCapacity) {
if (initialCapacity < 0) throw new IllegalArgumentException();
if (initialCapacity - FIELDS_STORE_SIZE > 0) {
minimalAllocation = initialCapacity - FIELDS_STORE_SIZE;
public ObjArray(int capacityHint) {
this();
if (capacityHint < 0) throw new IllegalArgumentException();
if (minimalAllocation < capacityHint - FIELDS_STORE_SIZE) {
minimalAllocation = capacityHint - FIELDS_STORE_SIZE;
}
}
@ -65,6 +66,21 @@ public class ObjArray implements Serializable {
return size;
}
public final void setSize(int newSize) {
if (newSize < 0) throw new IllegalArgumentException();
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 invalidIndex(index, size);
return getImpl(index);
@ -220,18 +236,28 @@ public class ObjArray implements Serializable {
size = 0;
}
public final void toArray(Object[] copy) {
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, copy, FIELDS_STORE_SIZE,
System.arraycopy(data, 0, array, offset + FIELDS_STORE_SIZE,
N - FIELDS_STORE_SIZE);
case 6: copy[5] = f5;
case 5: copy[4] = f4;
case 4: copy[3] = f3;
case 3: copy[2] = f2;
case 2: copy[1] = f1;
case 1: copy[0] = f0;
case 6: array[offset + 5] = f5;
case 5: array[offset + 4] = f4;
case 4: array[offset + 3] = f3;
case 3: array[offset + 2] = f2;
case 2: array[offset + 1] = f1;
case 1: array[offset + 0] = f0;
case 0: break;
}
}

Просмотреть файл

@ -202,15 +202,20 @@ public class ObjToIntMap implements Serializable {
/** Return array of present keys */
public Object[] getKeys() {
Object[] array = new Object[keyCount];
getKeys(array, 0);
return array;
}
public void getKeys(Object[] array, int offset) {
int count = keyCount;
Object[] result = new Object[count];
for (int i = 0; count != 0; ++i) {
Object key = keys[i];
if (key != null && key != DELETED) {
result[--count] = key;
--count;
array[offset++] = key;
}
}
return result;
}
private static int tableLookupStep(int fraction, int mask, int power) {

Просмотреть файл

@ -40,7 +40,7 @@
package org.mozilla.javascript;
import java.util.*;
import java.util.Enumeration;
import java.lang.reflect.*;
import org.mozilla.classfile.DefiningClassLoader;
@ -2070,7 +2070,7 @@ public class ScriptRuntime {
*
* See ECMA 12.6.3.
*
* IdEnumeration maintains a Hashtable to make sure a given
* IdEnumeration maintains a ObjToIntMap to make sure a given
* id is enumerated only once across multiple objects in a
* prototype chain.
*
@ -2082,7 +2082,7 @@ public class ScriptRuntime {
*/
class IdEnumeration implements Enumeration {
IdEnumeration(Scriptable m) {
used = new Hashtable(27);
used = new ObjToIntMap(27);
changeObject(m);
next = getNext();
}
@ -2094,8 +2094,8 @@ class IdEnumeration implements Enumeration {
public Object nextElement() {
Object result = next;
// only key used; 'next' as value for convenience
used.put(next, next);
// only key used; 0 as value for convenience
used.put(next, 0);
next = getNext();
return result;
@ -2129,7 +2129,7 @@ class IdEnumeration implements Enumeration {
if (!obj.has(((Number) result).intValue(), obj))
continue; // must have been deleted
}
if (!used.containsKey(result)) {
if (!used.has(result)) {
break;
}
}
@ -2140,5 +2140,5 @@ class IdEnumeration implements Enumeration {
private Scriptable obj;
private int index;
private Object[] array;
private Hashtable used;
private ObjToIntMap used;
}

Просмотреть файл

@ -1537,21 +1537,15 @@ public abstract class ScriptableObject implements Scriptable, Serializable,
* @since 1.5R2
*/
public static Object[] getPropertyIds(Scriptable obj) {
Hashtable h = new Hashtable(); // JDK1.2: use HashSet
ObjToIntMap map = new ObjToIntMap();
while (obj != null) {
Object[] ids = obj.getIds();
for (int i=0; i < ids.length; i++) {
h.put(ids[i], ids[i]);
map.put(ids[i], 0);
}
obj = (Scriptable)obj.getPrototype();
}
Object[] result = new Object[h.size()];
java.util.Enumeration e = h.elements();
int n = 0;
while (e.hasMoreElements()) {
result[n++] = e.nextElement();
}
return result;
return map.getKeys();
}
/**

Просмотреть файл

@ -37,7 +37,6 @@
package org.mozilla.javascript;
import java.io.*;
import java.util.*;
public class VariableTable {
@ -55,7 +54,7 @@ public class VariableTable {
}
public LocalVariable getVariable(int index) {
return (LocalVariable)(itsVariables.elementAt(index));
return (LocalVariable)(itsVariables.get(index));
}
public boolean hasVariable(String name) {
@ -65,7 +64,7 @@ public class VariableTable {
public LocalVariable getVariable(String name) {
int vIndex = itsVariableNames.get(name, -1);
if (vIndex != -1)
return (LocalVariable)(itsVariables.elementAt(vIndex));
return (LocalVariable)(itsVariables.get(vIndex));
else
return null;
}
@ -92,7 +91,7 @@ public class VariableTable {
public void establishIndices() {
for (int i = 0; i < itsVariables.size(); i++) {
LocalVariable lVar = (LocalVariable)(itsVariables.elementAt(i));
LocalVariable lVar = (LocalVariable)(itsVariables.get(i));
lVar.setIndex(i);
}
}
@ -107,7 +106,7 @@ public class VariableTable {
}
int index = varStart++;
LocalVariable lVar = createLocalVariable(pName, true);
itsVariables.addElement(lVar);
itsVariables.add(lVar);
itsVariableNames.put(pName, index);
}
@ -119,7 +118,7 @@ public class VariableTable {
}
int index = itsVariables.size();
LocalVariable lVar = createLocalVariable(vName, false);
itsVariables.addElement(lVar);
itsVariables.add(lVar);
itsVariableNames.put(vName, index);
}
@ -127,7 +126,7 @@ public class VariableTable {
public void removeLocal(String name) {
int i = itsVariableNames.get(name, -1);
if (i != -1) {
itsVariables.removeElementAt(i);
itsVariables.remove(i);
itsVariableNames.remove(name);
ObjToIntMap.Iterator iter = itsVariableNames.newIterator();
for (iter.start(); !iter.done(); iter.next()) {
@ -140,7 +139,7 @@ public class VariableTable {
}
// a list of the formal parameters and local variables
private Vector itsVariables = new Vector();
private ObjArray itsVariables = new ObjArray();
// mapping from name to index in list
private ObjToIntMap itsVariableNames = new ObjToIntMap(11);

Просмотреть файл

@ -38,7 +38,6 @@ package org.mozilla.javascript.optimizer;
import org.mozilla.javascript.*;
import org.mozilla.classfile.*;
import java.util.Vector;
import java.util.Hashtable;
import java.util.Enumeration;
@ -66,7 +65,7 @@ public class Block {
{
// a mapping from each target node to the block it begins
Hashtable theTargetBlocks = new Hashtable();
Vector theBlocks = new Vector();
ObjArray theBlocks = new ObjArray();
// there's a block that starts at index 0
int beginNodeIndex = 0;
@ -81,7 +80,7 @@ public class Block {
if (statementNodes[beginNodeIndex].getType()
== TokenStream.TARGET)
theTargetBlocks.put(statementNodes[beginNodeIndex], fb);
theBlocks.addElement(fb);
theBlocks.add(fb);
// start the next block at this node
beginNodeIndex = i;
}
@ -96,7 +95,7 @@ public class Block {
if (statementNodes[beginNodeIndex].getType()
== TokenStream.TARGET)
theTargetBlocks.put(statementNodes[beginNodeIndex], fb);
theBlocks.addElement(fb);
theBlocks.add(fb);
// start the next block at the next node
beginNodeIndex = i + 1;
}
@ -110,20 +109,20 @@ public class Block {
statementNodes);
if (statementNodes[beginNodeIndex].getType() == TokenStream.TARGET)
theTargetBlocks.put(statementNodes[beginNodeIndex], fb);
theBlocks.addElement(fb);
theBlocks.add(fb);
}
// build successor and predecessor links
for (int i = 0; i < theBlocks.size(); i++) {
FatBlock fb = (FatBlock)(theBlocks.elementAt(i));
FatBlock fb = (FatBlock)(theBlocks.get(i));
Node blockEndNode = fb.getEndNode();
int blockEndNodeType = blockEndNode.getType();
if ((blockEndNodeType != TokenStream.GOTO)
&& (i < (theBlocks.size() - 1))) {
FatBlock fallThruTarget = (FatBlock)(theBlocks.elementAt(i + 1));
FatBlock fallThruTarget = (FatBlock)(theBlocks.get(i + 1));
fb.addSuccessor(fallThruTarget);
fallThruTarget.addPredecessor(fb);
}
@ -145,7 +144,7 @@ public class Block {
Block[] result = new Block[theBlocks.size()];
for (int i = 0; i < theBlocks.size(); i++) {
FatBlock fb = (FatBlock)(theBlocks.elementAt(i));
FatBlock fb = (FatBlock)(theBlocks.get(i));
result[i] = fb.diet();
result[i].setBlockID(i);
}

Просмотреть файл

@ -72,8 +72,8 @@ public class Codegen extends Interpreter {
SecuritySupport securitySupport,
ClassNameHelper nameHelper)
{
Vector classFiles = new Vector();
Vector names = new Vector();
ObjArray classFiles = new ObjArray();
ObjArray names = new ObjArray();
String generatedName = null;
Exception e = null;
@ -90,8 +90,8 @@ public class Codegen extends Interpreter {
ClassRepository repository = nameHelper.getClassRepository();
for (int i=0; i < names.size(); i++) {
String name = (String) names.elementAt(i);
byte[] classFile = (byte[]) classFiles.elementAt(i);
String name = (String) names.get(i);
byte[] classFile = (byte[]) classFiles.get(i);
boolean isTopLevel = name.equals(generatedName);
try {
@ -361,7 +361,7 @@ public class Codegen extends Interpreter {
}
public String generateCode(Node tree, Vector names, Vector classFiles,
public String generateCode(Node tree, ObjArray names, ObjArray classFiles,
ClassNameHelper nameHelper)
{
this.itsNameHelper = (OptClassNameHelper) nameHelper;
@ -504,8 +504,8 @@ public class Codegen extends Interpreter {
byte[] bytes = classFile.toByteArray();
namesVector.addElement(name);
classFilesVector.addElement(bytes);
namesVector.add(name);
classFilesVector.add(bytes);
classFile = null;
namesVector = null;
@ -1174,13 +1174,13 @@ public class Codegen extends Interpreter {
}
// precompile all regexp literals
Vector regexps = (Vector) tree.getProp(Node.REGEXP_PROP);
ObjArray regexps = (ObjArray) tree.getProp(Node.REGEXP_PROP);
if (regexps != null) {
setNonTrivialInit(methodName);
generateRegExpLiterals(regexps, inCtor);
}
Vector fns = (Vector) tree.getProp(Node.FUNCTION_PROP);
ObjArray fns = (ObjArray) tree.getProp(Node.FUNCTION_PROP);
if (fns != null) {
setNonTrivialInit(methodName);
generateFunctionInits(fns);
@ -1189,7 +1189,7 @@ public class Codegen extends Interpreter {
if (tree instanceof OptFunctionNode) {
OptFunctionNode fnNode = (OptFunctionNode)tree;
Vector directCallTargets
ObjArray directCallTargets
= ((OptFunctionNode)tree).getDirectCallTargets();
if (directCallTargets != null) {
setNonTrivialInit(methodName);
@ -1227,9 +1227,9 @@ public class Codegen extends Interpreter {
}
}
private void generateRegExpLiterals(Vector regexps, boolean inCtor) {
private void generateRegExpLiterals(ObjArray regexps, boolean inCtor) {
for (int i=0; i < regexps.size(); i++) {
Node regexp = (Node) regexps.elementAt(i);
Node regexp = (Node) regexps.get(i);
StringBuffer sb = new StringBuffer("_re");
sb.append(i);
String fieldName = sb.toString();
@ -1270,7 +1270,7 @@ public class Codegen extends Interpreter {
}
}
private void generateFunctionInits(Vector fns) {
private void generateFunctionInits(ObjArray fns) {
// make an array to put them in, so they're available
// for decompilation.
push(fns.size());
@ -1287,7 +1287,7 @@ public class Codegen extends Interpreter {
addByteCode(ByteCode.DUP); // make another reference to the array
push(i); // to set up for aastore at end of loop
Node def = (Node) fns.elementAt(i);
Node def = (Node) fns.get(i);
Codegen codegen = new Codegen();
String fnClassName = codegen.generateCode(def, namesVector,
classFilesVector,
@ -1524,10 +1524,10 @@ public class Codegen extends Interpreter {
}
astore(variableObjectLocal);
Vector fns = (Vector) tree.getProp(Node.FUNCTION_PROP);
ObjArray fns = (ObjArray) tree.getProp(Node.FUNCTION_PROP);
if (inFunction && fns != null) {
for (int i=0; i < fns.size(); i++) {
FunctionNode fn = (FunctionNode) fns.elementAt(i);
FunctionNode fn = (FunctionNode) fns.get(i);
if (fn.getFunctionType() == FunctionNode.FUNCTION_STATEMENT) {
visitFunction(fn, true);
addByteCode(ByteCode.POP);
@ -2305,9 +2305,9 @@ public class Codegen extends Interpreter {
short selector = getNewWordLocal();
astore(selector);
Vector cases = (Vector) node.getProp(Node.CASES_PROP);
ObjArray cases = (ObjArray) node.getProp(Node.CASES_PROP);
for (int i=0; i < cases.size(); i++) {
Node thisCase = (Node) cases.elementAt(i);
Node thisCase = (Node) cases.get(i);
Node first = thisCase.getFirstChild();
generateCodeFromNode(first, thisCase, -1, -1);
aload(selector);
@ -3767,8 +3767,8 @@ public class Codegen extends Interpreter {
boolean inFunction;
boolean inDirectCallFunction;
private ClassFileWriter classFile;
private Vector namesVector;
private Vector classFilesVector;
private ObjArray namesVector;
private ObjArray classFilesVector;
private short scriptRuntimeIndex;
private int version;
private OptClassNameHelper itsNameHelper;

Просмотреть файл

@ -38,10 +38,6 @@ package org.mozilla.javascript.optimizer;
import org.mozilla.javascript.*;
import java.util.Vector;
import java.util.Hashtable;
import java.util.Enumeration;
public class FatBlock {
public FatBlock(int startNodeIndex, int endNodeIndex, Node[] statementNodes)
@ -55,15 +51,15 @@ public class FatBlock {
public Block getSlimmerSelf()
{ return itsShadowOfFormerSelf; }
private Block[] reduceToArray(Hashtable h)
private Block[] reduceToArray(ObjToIntMap map)
{
Block[] result = null;
if (!h.isEmpty()) {
result = new Block[h.size()];
Enumeration enum = h.elements();
if (!map.isEmpty()) {
result = new Block[map.size()];
int i = 0;
while (enum.hasMoreElements()) {
FatBlock fb = (FatBlock)(enum.nextElement());
ObjToIntMap.Iterator iter = map.newIterator();
for (iter.start(); !iter.done(); iter.next()) {
FatBlock fb = (FatBlock)(iter.getKey());
result[i++] = fb.itsShadowOfFormerSelf;
}
}
@ -77,13 +73,13 @@ public class FatBlock {
return itsShadowOfFormerSelf;
}
public void addSuccessor(FatBlock b) { itsSuccessors.put(b, b); }
public void addPredecessor(FatBlock b) { itsPredecessors.put(b, b); }
public void addSuccessor(FatBlock b) { itsSuccessors.put(b, 0); }
public void addPredecessor(FatBlock b) { itsPredecessors.put(b, 0); }
// all the Blocks that come immediately after this
private Hashtable itsSuccessors = new Hashtable(4);
private ObjToIntMap itsSuccessors = new ObjToIntMap();
// all the Blocks that come immediately before this
private Hashtable itsPredecessors = new Hashtable(4);
private ObjToIntMap itsPredecessors = new ObjToIntMap();
private Block itsShadowOfFormerSelf;

Просмотреть файл

@ -73,14 +73,14 @@ public class OptFunctionNode extends FunctionNode {
public void addDirectCallTarget(FunctionNode target) {
if (itsDirectCallTargets == null)
itsDirectCallTargets = new Vector();
itsDirectCallTargets = new ObjArray();
for (int i = 0; i < itsDirectCallTargets.size(); i++) // OPT !!
if (((FunctionNode)itsDirectCallTargets.elementAt(i)) == target)
if (((FunctionNode)itsDirectCallTargets.get(i)) == target)
return;
itsDirectCallTargets.addElement(target);
itsDirectCallTargets.add(target);
}
public Vector getDirectCallTargets() {
public ObjArray getDirectCallTargets() {
return itsDirectCallTargets;
}
@ -119,5 +119,5 @@ public class OptFunctionNode extends FunctionNode {
private boolean itsContainsCalls;
private boolean[] itsContainsCallsCount = new boolean[4];
private boolean itsParameterNumberContext;
private Vector itsDirectCallTargets;
private ObjArray itsDirectCallTargets;
}

Просмотреть файл

@ -38,8 +38,6 @@ package org.mozilla.javascript.optimizer;
import org.mozilla.javascript.*;
import java.util.Hashtable;
import java.util.Stack;
import java.util.Vector;
/**
* This class performs node transforms to prepare for optimization.

Просмотреть файл

@ -45,7 +45,6 @@ import java.io.FileOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Vector;
import java.util.Hashtable;
public class Optimizer {
@ -1028,18 +1027,16 @@ public class Optimizer {
private Node[] buildStatementList(FunctionNode theFunction)
{
Vector nodeList = new Vector();
ObjArray nodeList = new ObjArray();
StmtNodeIterator iterator = new StmtNodeIterator(theFunction);
Node node = iterator.nextNode();
while (node != null) {
nodeList.addElement(node);
nodeList.add(node);
node = iterator.nextNode();
}
Node[] result = new Node[nodeList.size()];
for (int i = 0; i < nodeList.size(); i++) {
result[i] = (Node)(nodeList.elementAt(i));
}
nodeList.toArray(result);
return result;
}

Просмотреть файл

@ -40,8 +40,6 @@ package org.mozilla.javascript.optimizer;
import org.mozilla.javascript.*;
import java.util.Stack;
public class StmtNodeIterator {
public StmtNodeIterator(Node start)
@ -87,7 +85,7 @@ public class StmtNodeIterator {
return itsCurrentNode = findFirstInterestingNode(itsCurrentNode);
}
private Stack itsStack = new Stack();
private ObjArray itsStack = new ObjArray();
private Node itsStart;
private Node itsCurrentNode;

Просмотреть файл

@ -1961,7 +1961,7 @@ public class NativeRegExp extends IdScriptable implements Function {
if (state.parenCount > re.parenCount)
throw new RuntimeException();
if (state.parenCount == 0) {
res.parens.setSize(0);
res.parens.clear();
res.lastParen = SubString.emptySubString;
} else {
SubString parsub = null;
@ -1969,7 +1969,7 @@ public class NativeRegExp extends IdScriptable implements Function {
res.parens.setSize(state.parenCount);
for (num = 0; num < state.parenCount; num++) {
parsub = state.parens[num];
res.parens.setElementAt(parsub, num);
res.parens.set(num, parsub);
if (matchType == TEST) continue;
String parstr = parsub == null ? "": parsub.toString();
obj.put(num+1, obj, parstr);

Просмотреть файл

@ -35,7 +35,6 @@
package org.mozilla.javascript.regexp;
import org.mozilla.javascript.*;
import java.util.Vector;
/**
*
@ -43,7 +42,7 @@ import java.util.Vector;
public class RegExpImpl implements RegExpProxy {
public RegExpImpl() {
parens = new Vector(9);
parens = new ObjArray();
}
public boolean isRegExp(Object obj) {
@ -281,12 +280,12 @@ public class RegExpImpl implements RegExpProxy {
SubString getParenSubString(int i) {
if (i >= parens.size())
return SubString.emptySubString;
return (SubString) parens.elementAt(i);
return (SubString) parens.get(i);
}
String input; /* input string to match (perl $_, GC root) */
boolean multiline; /* whether input contains newlines (perl $*) */
Vector parens; /* Vector of SubString; last set of parens
ObjArray parens; /* Vector of SubString; last set of parens
matched (perl $1, $2) */
SubString lastMatch; /* last string matched (perl $&) */
SubString lastParen; /* last paren matched (perl $+) */
@ -472,12 +471,12 @@ class ReplaceData extends GlobData {
if (lambda != null) {
// invoke lambda function with args lastMatch, $1, $2, ... $n,
// leftContext.length, whole string.
Vector parens = reImpl.parens;
ObjArray parens = reImpl.parens;
int parenCount = parens.size();
Object[] args = new Object[parenCount + 3];
args[0] = reImpl.lastMatch.toString();
for (int i=0; i < parenCount; i++) {
SubString sub = (SubString) parens.elementAt(i);
SubString sub = (SubString) parens.get(i);
args[i+1] = sub.toString();
}
args[parenCount+1] = new Integer(reImpl.leftContext.length);