Add benchmark for Exception and Stacktrace creation.

Change-Id: Id5b3096f9b08561e603f8abfc9de550642e676b3
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/BigExceptionBenchmark.gwt.xml b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/BigExceptionBenchmark.gwt.xml
new file mode 100644
index 0000000..6f4a48a
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/BigExceptionBenchmark.gwt.xml
@@ -0,0 +1,19 @@
+<!--                                                                        -->
+<!-- Copyright 2014 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.BigExceptionBenchmark.EntryPoint"/>
+  <source path="shared" includes="BigExceptionBenchmark.java, ExceptionUtil.java" />
+</module>
\ No newline at end of file
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/BigExceptionWithStackTraceAccessedBenchmark.gwt.xml b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/BigExceptionWithStackTraceAccessedBenchmark.gwt.xml
new file mode 100644
index 0000000..45fc9ad
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/BigExceptionWithStackTraceAccessedBenchmark.gwt.xml
@@ -0,0 +1,19 @@
+<!--                                                                        -->
+<!-- Copyright 2014 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.BigExceptionWithStackTraceAccessedBenchmark.EntryPoint"/>
+  <source path="shared" includes="BigExceptionWithStackTraceAccessedBenchmark.java, ExceptionUtil.java" />
+</module>
\ No newline at end of file
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/SmallExceptionBenchmark.gwt.xml b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/SmallExceptionBenchmark.gwt.xml
new file mode 100644
index 0000000..e3443b2
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/SmallExceptionBenchmark.gwt.xml
@@ -0,0 +1,19 @@
+<!--                                                                        -->
+<!-- Copyright 2014 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.SmallExceptionBenchmark.EntryPoint"/>
+  <source path="shared" includes="SmallExceptionBenchmark.java, ExceptionUtil.java" />
+</module>
\ No newline at end of file
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/SmallExceptionWithStackTraceAccessedBenchmark.gwt.xml b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/SmallExceptionWithStackTraceAccessedBenchmark.gwt.xml
new file mode 100644
index 0000000..53fdb08
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/SmallExceptionWithStackTraceAccessedBenchmark.gwt.xml
@@ -0,0 +1,19 @@
+<!--                                                                        -->
+<!-- Copyright 2014 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.SmallExceptionWithStackTraceAccessedBenchmark.EntryPoint"/>
+  <source path="shared" includes="SmallExceptionWithStackTraceAccessedBenchmark.java, ExceptionUtil.java" />
+</module>
\ No newline at end of file
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/BigExceptionBenchmark.java b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/BigExceptionBenchmark.java
new file mode 100644
index 0000000..9ac53e5
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/BigExceptionBenchmark.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2014 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;
+
+/**
+ * Benchmarks the performance of throwing and catching an exception without accessing the
+ * stacktrace.
+ */
+public class BigExceptionBenchmark extends AbstractBenchmark {
+
+  public static class EntryPoint extends AbstractBenchmarkEntryPoint {
+    @Override
+    protected AbstractBenchmark getBenchmark() {
+      return new BigExceptionBenchmark();
+    }
+  }
+
+  public BigExceptionBenchmark() {
+    super("BigExceptionBenchmark");
+  }
+
+  @Override
+  public Object run() {
+    try {
+      ExceptionUtil.throwRecursive(20);
+    } catch(Exception e) {
+      if(!e.getMessage().equals("message")) {
+        throw new RuntimeException("benchmark failed verification: '" + e.getMessage()  + "'");
+      }
+    }
+    return null;
+  }
+}
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/BigExceptionWithStackTraceAccessedBenchmark.java b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/BigExceptionWithStackTraceAccessedBenchmark.java
new file mode 100644
index 0000000..ed70c8a
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/BigExceptionWithStackTraceAccessedBenchmark.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2014 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;
+
+/**
+ * Benchmarks the performance of throwing and catching an exception with accessing the
+ * stacktrace.
+ */
+public class BigExceptionWithStackTraceAccessedBenchmark extends AbstractBenchmark {
+
+  public static class EntryPoint extends AbstractBenchmarkEntryPoint {
+    @Override
+    protected AbstractBenchmark getBenchmark() {
+      return new BigExceptionWithStackTraceAccessedBenchmark();
+    }
+  }
+
+  public BigExceptionWithStackTraceAccessedBenchmark() {
+    super("BigExceptionWithStackTraceAccessedBenchmark");
+  }
+
+  @Override
+  public Object run() {
+    try {
+      ExceptionUtil.throwRecursive(20);
+    } catch(Exception e) {
+      if(!e.getMessage().equals("message")) {
+        throw new RuntimeException("benchmark failed verification: '" + e.getMessage()  + "'");
+      }
+      return e.getStackTrace();
+    }
+    return null;
+  }
+}
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ExceptionUtil.java b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ExceptionUtil.java
new file mode 100644
index 0000000..dd4b9c5
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/ExceptionUtil.java
@@ -0,0 +1,14 @@
+package com.google.gwt.benchmark.benchmarks.java.lang.shared;
+
+/**
+ * Helper class for exception benchmarks.
+ */
+class ExceptionUtil {
+  public static void throwRecursive(int count) throws Exception {
+    if (count > 1) {
+      throwRecursive(count - 1);
+    } else {
+      throw new Exception("message");
+    }
+  }
+}
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/SmallExceptionBenchmark.java b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/SmallExceptionBenchmark.java
new file mode 100644
index 0000000..b3740dc
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/SmallExceptionBenchmark.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2014 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;
+
+/**
+ * Benchmarks the performance of throwing and catching an exception without accessing the
+ * stacktrace.
+ */
+public class SmallExceptionBenchmark extends AbstractBenchmark {
+
+  public static class EntryPoint extends AbstractBenchmarkEntryPoint {
+    @Override
+    protected AbstractBenchmark getBenchmark() {
+      return new SmallExceptionBenchmark();
+    }
+  }
+
+  public SmallExceptionBenchmark() {
+    super("SmallExceptionBenchmark");
+  }
+
+  @Override
+  public Object run() {
+    try {
+      ExceptionUtil.throwRecursive(0);
+    } catch(Exception e) {
+      if(!e.getMessage().equals("message")) {
+        throw new RuntimeException("benchmark failed verification: '" + e.getMessage()  + "'");
+      }
+    }
+    return null;
+  }
+}
diff --git a/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/SmallExceptionWithStackTraceAccessedBenchmark.java b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/SmallExceptionWithStackTraceAccessedBenchmark.java
new file mode 100644
index 0000000..95f0013
--- /dev/null
+++ b/benchmarks/src/main/java/com/google/gwt/benchmark/benchmarks/java/lang/shared/SmallExceptionWithStackTraceAccessedBenchmark.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2014 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;
+
+/**
+ * Benchmarks the performance of throwing and catching an exception with accessing the
+ * stacktrace.
+ */
+public class SmallExceptionWithStackTraceAccessedBenchmark extends AbstractBenchmark {
+
+  public static class EntryPoint extends AbstractBenchmarkEntryPoint {
+    @Override
+    protected AbstractBenchmark getBenchmark() {
+      return new SmallExceptionWithStackTraceAccessedBenchmark();
+    }
+  }
+
+  public SmallExceptionWithStackTraceAccessedBenchmark() {
+    super("SmallExceptionWithStackTraceAccessedBenchmark");
+  }
+
+  @Override
+  public Object run() {
+    try {
+      ExceptionUtil.throwRecursive(0);
+    } catch (Exception e) {
+      if (!e.getMessage().equals("message")) {
+        throw new RuntimeException("benchmark failed verification: '" + e.getMessage() + "'");
+      }
+      return e.getStackTrace();
+    }
+    return null;
+  }
+}