Merge "Improves the benchmarking for Arrays."
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/ArrayObjectIterationBenchmark.gwt.xml b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/ArrayObjectIterationBenchmark.gwt.xml
new file mode 100644
index 0000000..02d72e6
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/ArrayObjectIterationBenchmark.gwt.xml
@@ -0,0 +1,19 @@
+<!--                                                                        -->
+<!-- Copyright 2015 Google Inc.                                             -->
+<!-- Licensed under the Apache License, Version 2.0 (the "License"); you    -->
+<!-- may not use this file except in compliance with the License. You may   -->
+<!-- may obtain a copy of the License at                                    -->
+<!--                                                                        -->
+<!-- http://www.apache.org/licenses/LICENSE-2.0                             -->
+<!--                                                                        -->
+<!-- Unless required by applicable law or agreed to in writing, software    -->
+<!-- distributed under the License is distributed on an "AS IS" BASIS,      -->
+<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        -->
+<!-- implied. License for the specific language governing permissions and   -->
+<!-- limitations under the License.                                         -->
+
+<module>
+  <inherits name="com.google.gwt.benchmark.benchmarks.java.lang.Lang"/>
+  <entry-point class="com.google.gwt.benchmark.benchmarks.java.lang.shared.ArrayObjectIterationBenchmark.EntryPoint"/>
+  <source path="shared" includes="ArrayObjectIterationBenchmark.java" />
+</module>
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/ArrayObjectSetBenchmark.gwt.xml b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/ArrayObjectSetBenchmark.gwt.xml
new file mode 100644
index 0000000..b812e9d
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/ArrayObjectSetBenchmark.gwt.xml
@@ -0,0 +1,19 @@
+<!--                                                                        -->
+<!-- Copyright 2015 Google Inc.                                             -->
+<!-- Licensed under the Apache License, Version 2.0 (the "License"); you    -->
+<!-- may not use this file except in compliance with the License. You may   -->
+<!-- may obtain a copy of the License at                                    -->
+<!--                                                                        -->
+<!-- http://www.apache.org/licenses/LICENSE-2.0                             -->
+<!--                                                                        -->
+<!-- Unless required by applicable law or agreed to in writing, software    -->
+<!-- distributed under the License is distributed on an "AS IS" BASIS,      -->
+<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        -->
+<!-- implied. License for the specific language governing permissions and   -->
+<!-- limitations under the License.                                         -->
+
+<module>
+  <inherits name="com.google.gwt.benchmark.benchmarks.java.lang.Lang"/>
+  <entry-point class="com.google.gwt.benchmark.benchmarks.java.lang.shared.ArrayTestObjectSetBenchmark.EntryPoint"/>
+  <source path="shared" includes="ArrayTestObjectSetBenchmark.java" />
+</module>
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/ArrayTestObjectCreateBenchmark.gwt.xml b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/ArrayTestObjectCreateBenchmark.gwt.xml
new file mode 100644
index 0000000..84cbc17
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/ArrayTestObjectCreateBenchmark.gwt.xml
@@ -0,0 +1,19 @@
+<!--                                                                        -->
+<!-- Copyright 2015 Google Inc.                                             -->
+<!-- Licensed under the Apache License, Version 2.0 (the "License"); you    -->
+<!-- may not use this file except in compliance with the License. You may   -->
+<!-- may obtain a copy of the License at                                    -->
+<!--                                                                        -->
+<!-- http://www.apache.org/licenses/LICENSE-2.0                             -->
+<!--                                                                        -->
+<!-- Unless required by applicable law or agreed to in writing, software    -->
+<!-- distributed under the License is distributed on an "AS IS" BASIS,      -->
+<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        -->
+<!-- implied. License for the specific language governing permissions and   -->
+<!-- limitations under the License.                                         -->
+
+<module>
+  <inherits name="com.google.gwt.benchmark.benchmarks.java.lang.Lang"/>
+  <entry-point class="com.google.gwt.benchmark.benchmarks.java.lang.shared.ArrayTestObjectCreateBenchmark.EntryPoint"/>
+  <source path="shared" includes="ArrayTestObjectCreateBenchmark.java" />
+</module>
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/ArrayTestObjectSetBenchmark.gwt.xml b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/ArrayTestObjectSetBenchmark.gwt.xml
new file mode 100644
index 0000000..5d66b34
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/ArrayTestObjectSetBenchmark.gwt.xml
@@ -0,0 +1,19 @@
+<!--                                                                        -->
+<!-- Copyright 2015 Google Inc.                                             -->
+<!-- Licensed under the Apache License, Version 2.0 (the "License"); you    -->
+<!-- may not use this file except in compliance with the License. You may   -->
+<!-- may obtain a copy of the License at                                    -->
+<!--                                                                        -->
+<!-- http://www.apache.org/licenses/LICENSE-2.0                             -->
+<!--                                                                        -->
+<!-- Unless required by applicable law or agreed to in writing, software    -->
+<!-- distributed under the License is distributed on an "AS IS" BASIS,      -->
+<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        -->
+<!-- implied. License for the specific language governing permissions and   -->
+<!-- limitations under the License.                                         -->
+
+<module>
+  <inherits name="com.google.gwt.benchmark.benchmarks.java.lang.Lang"/>
+  <entry-point class="com.google.gwt.benchmark.benchmarks.java.lang.shared.ArrayObjectSetBenchmark.EntryPoint"/>
+  <source path="shared" includes="ArrayObjectSetBenchmark.java" />
+</module>
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayIntCreateBenchmark.java b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayIntCreateBenchmark.java
index d3d1d64..dc9f73e 100644
--- a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayIntCreateBenchmark.java
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayIntCreateBenchmark.java
@@ -30,25 +30,12 @@
     }
   }
 
-  private Object[] array;
-
   public ArrayIntCreateBenchmark() {
     super("ArrayIntCreateBenchmark");
   }
 
   @Override
   public Object run() {
-    // Note: we are reusing the same array every time, since every run allocates
-    // about 8MB of memory. Not reusing would mean running out of memory very fast
-    // on faster JavaScript VMs
-    for (int i = 0; i < array.length; i++) {
-      array[i] = new int[1000];
-    }
-    return array;
-  }
-
-  @Override
-  public void setupOneTime() {
-    array = new Object[1000];
+    return new int[1000][1000];
   }
 }
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayObjectCreateBenchmark.java b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayObjectCreateBenchmark.java
index 1223c2c..35483c6 100644
--- a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayObjectCreateBenchmark.java
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayObjectCreateBenchmark.java
@@ -30,25 +30,12 @@
     }
   }
 
-  private Object[] array;
-
   public ArrayObjectCreateBenchmark() {
     super("ArrayObjectCreateBenchmark");
   }
 
   @Override
   public Object run() {
-    // Note: we are reusing the same array every time, since every run allocates
-    // about 8MB of memory. Not reusing would mean running out of memory very fast
-    // on faster JavaScript VMs
-    for (int i = 0; i < array.length; i++) {
-      array[i] = new Object[1000];
-    }
-    return array;
-  }
-
-  @Override
-  public void setupOneTime() {
-    array = new Object[1000];
+    return new Object[1000][1000];
   }
 }
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayObjectIterationBenchmark.java b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayObjectIterationBenchmark.java
new file mode 100644
index 0000000..bb27ef5
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayObjectIterationBenchmark.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.benchmark.benchmarks.java.lang.shared;
+
+import com.google.gwt.benchmark.framework.client.AbstractBenchmarkEntryPoint;
+import com.google.gwt.benchmark.framework.shared.AbstractBenchmark;
+
+/**
+ * Benchmark array iteration performance.
+ */
+public class ArrayObjectIterationBenchmark extends AbstractBenchmark {
+
+  public static class EntryPoint extends AbstractBenchmarkEntryPoint {
+    @Override
+    protected AbstractBenchmark getBenchmark() {
+      return new ArrayObjectIterationBenchmark();
+    }
+  }
+
+  private Object[] array;
+
+  public ArrayObjectIterationBenchmark() {
+    super("ArrayObjectIterationBenchmark");
+  }
+
+  @Override
+  public Object run() {
+
+    int sum = 0;
+
+    for (Object object : array) {
+      if (object != null) {
+        sum++;
+      }
+    }
+
+    // compare value - disables opts and finds JIT bugs
+    if (sum != 10000) {
+      throw new RuntimeException();
+    }
+
+    return Integer.valueOf(sum);
+  }
+
+  @Override
+  public void setupOneTime() {
+    array = new Object[10000];
+    for (int i = 0; i < array.length; i++) {
+      array[i] = ":" + i;
+    }
+  }
+}
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayObjectSetBenchmark.java b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayObjectSetBenchmark.java
new file mode 100644
index 0000000..4489432
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayObjectSetBenchmark.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.benchmark.benchmarks.java.lang.shared;
+
+import com.google.gwt.benchmark.framework.client.AbstractBenchmarkEntryPoint;
+import com.google.gwt.benchmark.framework.shared.AbstractBenchmark;
+
+/**
+ * Benchmark array set performance.
+ */
+public class ArrayObjectSetBenchmark extends AbstractBenchmark {
+
+  public static class EntryPoint extends AbstractBenchmarkEntryPoint {
+    @Override
+    protected AbstractBenchmark getBenchmark() {
+      return new ArrayObjectSetBenchmark();
+    }
+  }
+
+  private Object[] array;
+
+  public ArrayObjectSetBenchmark() {
+    super("ArrayObjectSetBenchmark");
+  }
+
+  @Override
+  public Object run() {
+    for (int i = 0; i < array.length; i++) {
+      array[i] = "String";
+    }
+
+    return array;
+  }
+
+  @Override
+  public void setupOneTime() {
+    array = new Object[10000];
+  }
+}
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayTestObjectCreateBenchmark.java b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayTestObjectCreateBenchmark.java
new file mode 100644
index 0000000..85a9f3f
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayTestObjectCreateBenchmark.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.benchmark.benchmarks.java.lang.shared;
+
+import com.google.gwt.benchmark.framework.client.AbstractBenchmarkEntryPoint;
+import com.google.gwt.benchmark.framework.shared.AbstractBenchmark;
+
+/**
+ * Benchmark for object array creation performance.
+ */
+public class ArrayTestObjectCreateBenchmark extends AbstractBenchmark {
+
+  public static class EntryPoint extends AbstractBenchmarkEntryPoint {
+    @Override
+    protected AbstractBenchmark getBenchmark() {
+      return new ArrayTestObjectCreateBenchmark();
+    }
+  }
+
+  private static class TestObject {}
+
+  public ArrayTestObjectCreateBenchmark() {
+    super("ArrayTestObjectCreateBenchmark");
+  }
+
+  @Override
+  public Object run() {
+    return new TestObject[1000][1000];
+  }
+}
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayTestObjectSetBenchmark.java b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayTestObjectSetBenchmark.java
new file mode 100644
index 0000000..d5f1ddf
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ArrayTestObjectSetBenchmark.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.benchmark.benchmarks.java.lang.shared;
+
+import com.google.gwt.benchmark.framework.client.AbstractBenchmarkEntryPoint;
+import com.google.gwt.benchmark.framework.shared.AbstractBenchmark;
+
+/**
+ * Benchmark array set performance.
+ */
+public class ArrayTestObjectSetBenchmark extends AbstractBenchmark {
+
+  public static class EntryPoint extends AbstractBenchmarkEntryPoint {
+    @Override
+    protected AbstractBenchmark getBenchmark() {
+      return new ArrayTestObjectSetBenchmark();
+    }
+  }
+
+  private static class TestObject { }
+
+  private Object[] array;
+  private Object testObjectInstance = new Object();
+
+  public ArrayTestObjectSetBenchmark() {
+    super("ArrayTestObjectSetBenchmark");
+  }
+
+  @Override
+  public Object run() {
+    for (int i = 0; i < array.length; i++) {
+      array[i] = testObjectInstance;
+    }
+
+    return array;
+  }
+
+  @Override
+  public void setupOneTime() {
+    array = new TestObject[10000];
+    testObjectInstance = new TestObject();
+  }
+}