changeset 225:5c98cc846f92

8013208: Octane performance regression Reviewed-by: hannesw, sundar Contributed-by: james.laskey@oracle.com
author jlaskey
date Fri, 26 Apr 2013 09:48:41 -0300
parents 7917ef020898
children b532eeab085f
files src/jdk/nashorn/internal/runtime/ScriptObject.java src/jdk/nashorn/internal/runtime/arrays/ArrayIndex.java
diffstat 2 files changed, 210 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/runtime/ScriptObject.java	Fri Apr 26 09:20:37 2013 +0200
+++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java	Fri Apr 26 09:48:41 2013 -0300
@@ -2265,17 +2265,29 @@
     }
 
     private int getInt(final int index, final String key) {
-        for (ScriptObject object = this; object != null; object = object.getProto()) {
-            final ArrayData array = object.getArray();
-
-            if (array.has(index)) {
-                return array.getInt(index);
-            }
-
-            final FindProperty find = object.findProperty(key, false);
+        if (isValidArrayIndex(index)) {
+             for (ScriptObject object = this; ; ) {
+                final FindProperty find = object.findProperty(key, false, false, this);
+
+                if (find != null) {
+                    return getIntValue(find);
+                }
+
+                if ((object = object.getProto()) == null) {
+                    break;
+                }
+
+                final ArrayData array = object.getArray();
+
+                if (array.has(index)) {
+                    return array.getInt(index);
+                }
+           }
+        } else {
+            final FindProperty find = findProperty(key, true);
 
             if (find != null) {
-                return getIntValue(new FindProperty(this, find.getOwner(), find.getProperty()));
+                return getIntValue(find);
             }
         }
 
@@ -2284,36 +2296,75 @@
 
     @Override
     public int getInt(final Object key) {
-        return getInt(getArrayIndexNoThrow(key), convertKey(key));
+        final int index = getArrayIndexNoThrow(key);
+        final ArrayData array = getArray();
+
+        if (array.has(index)) {
+            return array.getInt(index);
+        }
+
+        return getInt(index, convertKey(key));
     }
 
     @Override
     public int getInt(final double key) {
-        return getInt(getArrayIndexNoThrow(key), convertKey(key));
+        final int index = getArrayIndexNoThrow(key);
+        final ArrayData array = getArray();
+
+        if (array.has(index)) {
+            return array.getInt(index);
+        }
+
+        return getInt(index, convertKey(key));
     }
 
     @Override
     public int getInt(final long key) {
-        return getInt(getArrayIndexNoThrow(key), convertKey(key));
+        final int index = getArrayIndexNoThrow(key);
+        final ArrayData array = getArray();
+
+        if (array.has(index)) {
+            return array.getInt(index);
+        }
+
+        return getInt(index, convertKey(key));
     }
 
     @Override
     public int getInt(final int key) {
-        return getInt(getArrayIndexNoThrow(key), convertKey(key));
+        final ArrayData array = getArray();
+
+        if (array.has(key)) {
+            return array.getInt(key);
+        }
+
+        return getInt(key, convertKey(key));
     }
 
     private long getLong(final int index, final String key) {
-        for (ScriptObject object = this; object != null; object = object.getProto()) {
-            final ArrayData array = object.getArray();
-
-            if (array.has(index)) {
-                return array.getLong(index);
-            }
-
-            final FindProperty find = object.findProperty(key, false);
+        if (isValidArrayIndex(index)) {
+            for (ScriptObject object = this; ; ) {
+                final FindProperty find = object.findProperty(key, false, false, this);
+
+                if (find != null) {
+                    return getLongValue(find);
+                }
+
+                if ((object = object.getProto()) == null) {
+                    break;
+                }
+
+                final ArrayData array = object.getArray();
+
+                if (array.has(index)) {
+                    return array.getLong(index);
+                }
+           }
+        } else {
+            final FindProperty find = findProperty(key, true);
 
             if (find != null) {
-                return getLongValue(new FindProperty(this, find.getOwner(), find.getProperty()));
+                return getLongValue(find);
             }
         }
 
@@ -2322,36 +2373,75 @@
 
     @Override
     public long getLong(final Object key) {
-        return getLong(getArrayIndexNoThrow(key), convertKey(key));
+        final int index = getArrayIndexNoThrow(key);
+        final ArrayData array = getArray();
+
+        if (array.has(index)) {
+            return array.getLong(index);
+        }
+
+        return getLong(index, convertKey(key));
     }
 
     @Override
     public long getLong(final double key) {
-        return getLong(getArrayIndexNoThrow(key), convertKey(key));
+        final int index = getArrayIndexNoThrow(key);
+        final ArrayData array = getArray();
+
+        if (array.has(index)) {
+            return array.getLong(index);
+        }
+
+        return getLong(index, convertKey(key));
     }
 
     @Override
     public long getLong(final long key) {
-        return getLong(getArrayIndexNoThrow(key), convertKey(key));
+        final int index = getArrayIndexNoThrow(key);
+        final ArrayData array = getArray();
+
+        if (array.has(index)) {
+            return array.getLong(index);
+        }
+
+        return getLong(index, convertKey(key));
     }
 
     @Override
     public long getLong(final int key) {
-        return getLong(getArrayIndexNoThrow(key), convertKey(key));
+        final ArrayData array = getArray();
+
+        if (array.has(key)) {
+            return array.getLong(key);
+        }
+
+        return getLong(key, convertKey(key));
     }
 
     private double getDouble(final int index, final String key) {
-        for (ScriptObject object = this; object != null; object = object.getProto()) {
-            final ArrayData array = object.getArray();
-
-            if (array.has(index)) {
-                return array.getDouble(index);
-            }
-
-            final FindProperty find = object.findProperty(key, false);
+        if (isValidArrayIndex(index)) {
+            for (ScriptObject object = this; ; ) {
+                final FindProperty find = object.findProperty(key, false, false, this);
+
+                if (find != null) {
+                    return getDoubleValue(find);
+                }
+
+                if ((object = object.getProto()) == null) {
+                    break;
+                }
+
+                final ArrayData array = object.getArray();
+
+                if (array.has(index)) {
+                    return array.getDouble(index);
+                }
+           }
+        } else {
+            final FindProperty find = findProperty(key, true);
 
             if (find != null) {
-                return getDoubleValue(new FindProperty(this, find.getOwner(), find.getProperty()));
+                return getDoubleValue(find);
             }
         }
 
@@ -2360,36 +2450,75 @@
 
     @Override
     public double getDouble(final Object key) {
-        return getDouble(getArrayIndexNoThrow(key), convertKey(key));
+        final int index = getArrayIndexNoThrow(key);
+        final ArrayData array = getArray();
+
+        if (array.has(index)) {
+            return array.getDouble(index);
+        }
+
+        return getDouble(index, convertKey(key));
     }
 
     @Override
     public double getDouble(final double key) {
-        return getDouble(getArrayIndexNoThrow(key), convertKey(key));
+        final int index = getArrayIndexNoThrow(key);
+        final ArrayData array = getArray();
+
+        if (array.has(index)) {
+            return array.getDouble(index);
+        }
+
+        return getDouble(index, convertKey(key));
     }
 
     @Override
     public double getDouble(final long key) {
-        return getDouble(getArrayIndexNoThrow(key), convertKey(key));
+        final int index = getArrayIndexNoThrow(key);
+        final ArrayData array = getArray();
+
+        if (array.has(index)) {
+            return array.getDouble(index);
+        }
+
+        return getDouble(index, convertKey(key));
     }
 
     @Override
     public double getDouble(final int key) {
-        return getDouble(getArrayIndexNoThrow(key), convertKey(key));
+        final ArrayData array = getArray();
+
+        if (array.has(key)) {
+            return array.getDouble(key);
+        }
+
+        return getDouble(key, convertKey(key));
     }
 
     private Object get(final int index, final String key) {
-        for (ScriptObject object = this; object != null; object = object.getProto()) {
-            final ArrayData array = object.getArray();
-
-            if (array.has(index)) {
-                return array.getObject(index);
+        if (isValidArrayIndex(index)) {
+            for (ScriptObject object = this; ; ) {
+                final FindProperty find = object.findProperty(key, false, false, this);
+
+                if (find != null) {
+                    return getObjectValue(find);
+                }
+
+                if ((object = object.getProto()) == null) {
+                    break;
+                }
+
+                final ArrayData array = object.getArray();
+
+                if (array.has(index)) {
+                    return array.getObject(index);
+                }
             }
-
-            final FindProperty find = object.findProperty(key, false);
+        } else {
+            final FindProperty find = findProperty(key, true);
 
             if (find != null) {
-                return getObjectValue(new FindProperty(this, find.getOwner(), find.getProperty()));
+                return getObjectValue(find);
             }
         }
 
@@ -2398,22 +2527,49 @@
 
     @Override
     public Object get(final Object key) {
-        return get(getArrayIndexNoThrow(key), convertKey(key));
+        final int index = getArrayIndexNoThrow(key);
+        final ArrayData array = getArray();
+
+        if (array.has(index)) {
+            return array.getObject(index);
+        }
+
+        return get(index, convertKey(key));
     }
 
     @Override
     public Object get(final double key) {
-        return get(getArrayIndexNoThrow(key), convertKey(key));
+        final int index = getArrayIndexNoThrow(key);
+        final ArrayData array = getArray();
+
+        if (array.has(index)) {
+            return array.getObject(index);
+        }
+
+        return get(index, convertKey(key));
     }
 
     @Override
     public Object get(final long key) {
-        return get(getArrayIndexNoThrow(key), convertKey(key));
+        final int index = getArrayIndexNoThrow(key);
+        final ArrayData array = getArray();
+
+        if (array.has(index)) {
+            return array.getObject(index);
+        }
+
+        return get(index, convertKey(key));
     }
 
     @Override
     public Object get(final int key) {
-        return get(getArrayIndexNoThrow(key), convertKey(key));
+        final ArrayData array = getArray();
+
+        if (array.has(key)) {
+            return array.getObject(key);
+        }
+
+        return get(key, convertKey(key));
     }
 
     /**
--- a/src/jdk/nashorn/internal/runtime/arrays/ArrayIndex.java	Fri Apr 26 09:20:37 2013 +0200
+++ b/src/jdk/nashorn/internal/runtime/arrays/ArrayIndex.java	Fri Apr 26 09:48:41 2013 -0300
@@ -84,7 +84,9 @@
      * @return valid array index, or negative value if not valid
      */
     public static int getArrayIndexNoThrow(final Object key) {
-        if (key instanceof Number) {
+        if (key instanceof Integer) {
+            return getArrayIndexNoThrow(((Integer)key).intValue());
+        } else if (key instanceof Number) {
             return getArrayIndexNoThrow(((Number)key).doubleValue());
         } else if (key instanceof String) {
             return (int)fromString((String)key);