changeset 10014:16dfdc920e77

unittest/aot: add testcase for string objects
author Bernhard Urban <bernhard.urban@jku.at>
date Wed, 12 Jun 2013 16:04:43 +0200
parents 767ef799b323
children deb5bd841422
files graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/AheadOfTimeCompilationTest.java
diffstat 1 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/AheadOfTimeCompilationTest.java	Wed Jun 12 16:04:43 2013 +0200
+++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/AheadOfTimeCompilationTest.java	Wed Jun 12 16:04:43 2013 +0200
@@ -54,6 +54,7 @@
 public class AheadOfTimeCompilationTest extends GraalCompilerTest {
 
     public static final Object STATICFINALOBJECT = new Object();
+    public static final String STATICFINALSTRING = "test string";
 
     public static Object getStaticFinalObject() {
         return AheadOfTimeCompilationTest.STATICFINALOBJECT;
@@ -136,6 +137,34 @@
         assertEquals(0, result.getNodes(ReadNode.class).count());
     }
 
+    public static String getStringObject() {
+        return AheadOfTimeCompilationTest.STATICFINALSTRING;
+    }
+
+    @Test
+    public void testStringObjectAOT() {
+        // embedded strings are fine
+        testStringObjectCommon(true);
+    }
+
+    @Test
+    public void testStringObject() {
+        testStringObjectCommon(false);
+    }
+
+    private void testStringObjectCommon(boolean compileAOT) {
+        StructuredGraph result = compile("getStringObject", compileAOT);
+
+        NodeIterable<ConstantNode> filter = result.getNodes().filter(ConstantNode.class);
+        assertEquals(1, filter.count());
+        Object mirror = filter.first().asConstant().asObject();
+        assertEquals(String.class, mirror.getClass());
+        assertEquals("test string", mirror);
+
+        assertEquals(0, result.getNodes(FloatingReadNode.class).count());
+        assertEquals(0, result.getNodes(ReadNode.class).count());
+    }
+
     private StructuredGraph compile(String test, boolean compileAOT) {
         StructuredGraph graph = parse(test);
         ResolvedJavaMethod method = graph.method();